Vous êtes sur la page 1sur 6

StudyofMovingAverageFilters

Study of Moving Average Filters


Submitted by: UTSAV BANERJEE 09EC1053 E&ECE Department IIT Kharagpur The MATLAB software was used to study the gain vs. frequency response of various moving average filters. A sinusoidal input with 5000 samples was provided to the 3-point (3rd order) moving average (MA) filter in the program, and the output obtained was as follows:

Next, a square pulse was provided as input and some random noise added to it and the output was observed for various orders of the Moving Average filters, namely, M=3, M=9, M=51, M=101and M=101:

StudyofMovingAverageFilters

The freqz function in MATLAB was used to plot the frequency responses for some typical moving average filters with M-values 3, 5, 7, 11, 101 and 1001 respectively. The freqz function was used in the syntax freqz(B,A), which returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter

given the numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to 512. For the M-point (Mth order) moving average filter, y[n] = (x[n] + x[n 1] + x[n 2] + . . . + x[n M + 1]) / M h[n] = y[n] / x[n] Using the properties of Discrete time Fourier Transform, we have Y(ejw) = (1/M) (1 + e-jw + e-j2w + . . . + e-j(M-1)w) X(ejw) So, H(ejw) = Y(ejw) / X(ejw) = (1/M) (1 + e-jw + e-j2w + . . . + e-j(M-1)w) The function H(ejw) is known as the transfer function of the moving average filter system of Mth order. The magnitude of H(ejw) gives the value of the gain obtained. Thus, B= [1/M, 1/M, 1/M, repeated M times] and A=[1, 0, 0, ].

StudyofMovingAverageFilters
Using the MATLAB code, we get a comparative plot of the frequency responses of various ordered moving average filters as follows, namely, for M=3, M=5, M=7, M=11, M=101 and M=1001:

Clearly, the roll-off is very slow and the stopband attenuation is poor. The moving average filter cannot separate one band of frequencies from another. We know that 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). With increase in the order M of the filter, the filtering action becomes better. Next, we try to program a more general filter of the form: y[n] = a0x[n] + a1x[n 1] + a2x[n 2] + . . . + aM-1x[n M + 1] where a0, a1, a2, , aM-1 are real constants, whose values are to be varied to check the influence on the frequency response of the filter. For the sake of simplicity, we restrict ourselves to 3rd order filter only. The MATLAB code asks the user for the values of the three constants and displays the corresponding frequency response. Filter 1:y[n] = (1)x[n] + (-1)x[n 1] + (3)x[n 2]

StudyofMovingAverageFilters

This filter acts roughly as a band stop filter, although the stop band is not completely removed. Filter 2:y[n] = (2)x[n] + (-0.75)x[n 1] + (-0.25)x[n 2]

This filter acts as a good high pass filter. 4

StudyofMovingAverageFilters
Filter 3:y[n] = (-2)x[n] + (1)x[n 1] + (3)x[n 2]

This filter acts as a band pass filter, with some low-pass allowance. Filter 4:y[n] = (1)x[n] + (3)x[n 1] + (5)x[n 2]

This is a low pass filter, although the higher frequencies are not entirely eliminated. 5

StudyofMovingAverageFilters
Filter 5:y[n] = (100)x[n] + (-100)x[n 1] + (100)x[n 2]

This is also a band stop filter (of V-shape). Thus, on varying the coefficients, we can obtain various types of filters of different efficiencies.

-----------------------------------------------------------------------------------------------------MATLAB Files Attached: movavgfilter.m (Shows filtered output for various ordered MA filters) mafilterFreqResponse.m (Shows Frequency Response of various ordered MA filters) GeneralFilter.m (Shows Frequency Response of the general filter described above)

Submitted by: UTSAV BANERJEE 09EC1053 E&ECE Department IIT Kharagpur

Vous aimerez peut-être aussi