Professional Documents
Culture Documents
Filter is one of the most common in signals and systems and transformation. Therefore, you need to
know, what is filter, and what is application of using different filters, and principally why we use filter?
To calculate the output, we need to evaluate the convolution integral, as following structures:
Similarly, to calculate the output of a DT system that has a DT input signal, we use the convolution sum.
As the general form of the convolution sum is: ∞
[ ] = ∫ ℎ[ ] [ − ]
−∞
For an FIR system, the filter coefficients are the individual terms that make up the impulse response of
the system. These FIR filter coefficients are commonly called the b
coefficients. In MATLAB, when all of the b coefficients are
formed into a vector, it is called the B vector. Making this
substitution (b for h) and remembering that an FIR filter of order
N has N +1 coefficients, the convolution sum takes on the
general form of the FIR difference equation, namely,
[ ] = ∑ b[ ] [ − ]
=0
This equation tells us that, in order to calculate a value for the current output, (0), we must perform the dot product of . , where
B = {b[0], b[1], . . . , b[N]} and X represents the current and past values of the input, X = {x[0], x[−1], . . . ,x[−N]}. That is,
[0] = ∑ [ ] [− ] =0
= [0] [0] + [1] [−1] + · · · + [ ] [− ]
The block diagram associated with implementing the FIR difference equation is shown in Figure 1.
MATLAB Implementation
MATLAB has a number of ways of performing the filtering operation. In this lab, we will only discuss two
of them. The first is the built-in filter function, and the second is to build your own routine to perform the
FIR filtering operation. The built-in function allows us to filter signals almost immediately.
Built-In Approach
As mentioned previously, MATLAB has a built-in function called filter.m. This function can be used to
implement both an FIR filter (using only the numerator (B) coefficients) and an IIR filter (using both the
denominator (A) and the numerator (B) coefficients). Use MATLAB Help to understand more about the
filter function.
Notice that in the difference equation discussion of the MATLAB filter command, the A and B coefficient
vector indices start at 1 instead of at 0. MATLAB does not allow for an index value equal to zero. While this
may seem like only a minor inconvenience, improper vector indices account for a significant number
1
FIR Filter Design
of the errors that occur during MATLAB algorithm development. In our lab, we typically can create
another vector, say n, which is composed of integers with the first element equal to zero (i.e., n=0:15
creates n = {0, 1, 2, 3, . . . , 15}), and use this n vector to “fool” MATLAB into counting from zero
for things such as plot axes. See the code given below for an example of this technique.
The MATLAB code shown above will filter the input vector x using the FIR filter coefficients in vector
B. Notice that the input vector x is zero padded (line 5) to flush the filter. This technique differs slightly
from the direct implementation of the MATLAB filter command in which for M input values there will
be M output values. This technique assumes that the input vector is both preceded and followed by a large
number of zeros. This implies that the filter is initially at rest (no initial conditions) and will relax or flush
any remaining values at the end of the filtering operation.
Lab exercise-1: Run this code and see the Stem plot from the example above.
2
FIR Filter Design
inversely related to the filter order. Illustrate filtered and unfiltered closing values of the NASDAQ
composite index for calendar year 2001.
Lab exercise-2: Demonstrate two plots where using the MATLAB function “filter” and “filtfilt”
functions. Compare your results with the raw data where the results of filtering the raw data
with both a 4-term (3rd-order) and a 32-term (31st-order) of moving average filter.
For additional information on the MATLAB function filtfilt, type “help filtfilt” from the
MATLAB command prompt.
Notice that “fir1” give you -6 dB (i.e., not –3dB) cut-off frequency. You can check it by typing “help fir1” on the
command window.