# Moving Average Filter ( MA filter )

(11 votes, average: 4.18 out of 5)

The moving average filter is a simple Low Pass FIR (Finite Impulse Response) filter commonly used for smoothing an array of sampled data/signal. It takes M samples of input at a time and take the average of those M-samples and produces a single output point. It is a very simple LPF (Low Pass Filter) structure that comes handy for scientists and engineers to filter unwanted noisy component from the intended data.

As the filter length increases ( the parameter M ) the smoothness of the output increases, whereas the sharp transitions in the data are made increasingly blunt. This implies that this filter has excellent time domain response but a poor frequency response.

The MA filter perform three important functions:

1) It takes M input points, computes the average of those M-points and produces a single output point
2) Due to the computation/calculations involved , the filter introduces a definite amount of delay
3) The filter acts as a Low Pass Filter (with poor frequency domain response and a good time domain response).

### Matlab Code:

Following matlab code simulates the time domain response of a M-point Moving Average filter and also plots the frequency response for various filter lengths.

Check this book for full Matlab code.
Simulation of Digital Communication Systems Using Matlab – by Mathuranathan Viswanathan

### Time Domain Response:

 Input to MA filter 3-point MA filter output Input to Moving average filter Response of 3 point Moving average filter 51-point MA filter output 101-point MA filter output Response of 51-point Moving average filter Response of 101-point Moving average filter 501-point MA filter output Response of 501 point Moving average filter

On the first plot, we have the input that is going into the moving average filter. The input is noisy and our objective is to reduce the noise. The next figure is the output response of a 3-point Moving Average filter. It can be deduced from the figure that the 3-point Moving Average filter has not done much in filtering out the noise. We increase the filter taps to 51-points and we can see that the noise in the output has reduced a lot, which is depicted in next figure.

We increase the taps further to 101 and 501 and we can observe that even-though the noise is almost zero, the transitions are blunted out drastically (observe the slope on the either side of the signal and compare them with the ideal brick wall transition in our input).

### Frequency Response:

From the frequency response it can be asserted that the roll-off is very slow and the stop band attenuation is not good. Given this stop band attenuation,clearly, the moving average filter cannot separate one band of frequencies from another. As we know that a good performance in the time domain results in poor performance in the frequency domain, and vice versa. In short, the moving average is an exceptionally good smoothing filter (the action in the time domain), but an exceptionally bad low-pass filter (the action in the frequency domain)