Your task this week is to examine a simple moving average filter.
Consider first a three point moving average filter, implemented non-recursively:

This filter can be represented in the standard form for our difference equations as:

where b0=b1=b2=1/3, a0=1 (a0 multiplies y(n) and is not normally shown because it is assumed to be equal to one).
There are several ways to implement this in Matlab. Try them all to show they yield identical results.
Start by defining filter coefficients and b and a matrices.
>> b=[1/3 1/3 1/3];
>> a=[1 0 0];
>> x=[0 0 0 0 1 1 1 1 1 0 0 0 0];
Filter Method 1
>> y=conv(b,x);
>> stem(y);
Filter Method 2
>> y=filter(b,a,x);
>> stem(y);
Filter Method 3
>> H=tf(b,a,1) %Leave off ";" to display "H"
>> y=lsim(H,x);
>> stem(y);
Filter Method 4
>> H=tf(b,a,1,'variable','z^-1') %Leave off ";" to display "H"
>> y=lsim(H,x);
>> stem(y);
Explain the four filter methods. Which could not be used for an IIR (or recursive) filter?
Consider the signal:

use a sampling frequency of 8000 Hz (cell phone quality),
use a 100 point moving average filter,
for the frequencies 0, 40, 80, 120, 160, 200, 240, and 280 Hz make a single plot for each frequency that:
plots the first four hundred points of the sampled input, and
plots the first four hundred points of the sampled output on the same graph.
Plot the magnitude of the last cycle of the output vs. frequency (i.e., the height of the steady-state oscillations at each frequency). Comment on the result.
Determine how many additions and multiplications are necessary to calculate one value of the output.
Implement a recursive version of the moving average algorithm and give evidence that it works (i.e., compare it to one or more of your results from above, or calculate and compare the impulse response of the two filters (the Matlab command "dimpulse" is useful for the latter)).
Determine how many additions and multiplications are necessary to calculate one value of the output.