Question

I'm using MATLAB's filter function to create a moving average of a line graph. My question is, what kind of filter is? Low pass? High pass? etc...

I'm a sophomore electrical engineer so this kind of question is of particular interest to me.

I'm graphing the average temperature in January.

temperature = filter(ones(1,3)/3,1,janTemp);
plot(days,temperature);

where janTemp is the 1 column vector with the temperatures and days is the list of days in a vector.

Was it helpful?

Solution

filter doesn't create a filter; it applies a filter to a signal:

FILTER One-dimensional digital filter.
Y = FILTER(B,A,X) filters the data in vector X with the filter described by vectors A and B to create the filtered data Y.

The filter will be low-pass, high-pass etc depending on the coefficient vectors A, B. These vectors contain the coefficients of the difference equation defining the filter:

a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)

Equivalently, A and B define the numerator and denominator polynomials of the filter's transfer function, H(z).

In your case, with B = [1 1 1] and A = 1, it will be a low-pass FIR filter, i.e. a moving average, as you indicate in your question.

See filter's documentation or type help filter for details.

OTHER TIPS

An easy way to visualize the frequency response of a filter is with freqz.

freqz([1 1 1]/3,1)

enter image description here

This filter attenuates high frequencies, but by no means very well.

Consider a 5-tap Butterworth FIR filter:

freqz(butter(5,0.5,'low'),1)

enter image description here

See also fvtool, the Filter Visualization Tool (FVTool).

Moving average is usually an example of low pass filter. See more information at http://en.wikipedia.org/wiki/Moving_average

In general you can learn more about filters in matlab at http://www.mathworks.com/tagteam/55876_digfilt.pdf.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top