Lab 5
Lab 5
Laboratory Exercises 5
Filters
Filters appear as basic building blocks in a signal processing environment and there is a wealth
of knowledge that deals with the design and implementation of digital filters. This exercise will
make use of the MATLAB built-in function fir1, to realize a low-pass, a high-pass, a band-pass,
and a band-stop filter. (MATLAB description of fir1 is appended here for your reference.)
Note:
The MATLAB built in function conv could be used to obtain the output of the filter in the time
domain. Alternatively, MATLAB filter function can be used for same (but with caution).
Submission
Your report should include the following:
(a) Your MATLAB code with appropriate comments that describe your approach and steps.
(b) The graphs and other results you have obtained.
(c) Your observations and comments with regard to the investigation you have completed.
PD/10
fir1 - Window-based finite impulse response filter design
Syntax
b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
b = fir1(...,'normalization')
Description
fir1 implements the classical method of windowed linear-phase FIR digital filter design [1]. It designs filters
in standard lowpass, highpass, bandpass, and bandstop configurations. By default the filter is normalized so
that the magnitude response of the filter at the center frequency of the passband is 0 dB.
Note Use fir2 for windowed filters with arbitrary frequency response.
b = fir1(n,Wn) returns row vector b containing the n+1 coefficients of an order n lowpass FIR filter. This
is a Hamming-window based, linear-phase filter with normalized cutoff frequency Wn. The output filter
coefficients, b, are ordered in descending powers of z.
If Wn is a multi-element vector, Wn = [w1 w2 w3 w4 w5 ... wn], fir1 returns an order n multiband filter
with bands 0 < ω< w1, w1 < ω< w2, ..., wn < ω< 1.
By default, the filter is scaled so that the center of the first passband has a magnitude of exactly 1 after
windowing.
b = fir1(n,Wn,'ftype') specifies a filter type, where 'ftype' is:
'stop' for a bandstop filter, if Wn = [w1 w2]. The stopband frequency range is specified by this
interval.
b = fir1(n,Wn,window) uses the window specified in column vector window for the design. The vector
window must be n+1 elements long. If no window is specified, fir1 uses a Hamming window (see hamming)
of length n+1.
'scale' (default): Normalize the filter so that the magnitude response of the filter at the center
frequency of the passband is 0 dB.
Examples
Example 1
Example 2
The chirp.mat file contains a signal, y, that has most of its power above fs/4, or half the Nyquist
frequency. Design a 34th-order FIR highpass filter to attenuate the components of the signal below fs/4.
Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple:
load chirp % Load y and fs.
b = fir1(34,0.48,'high',chebwin(35,30));
freqz(b,1,512)
References
[1] Programs for Digital Signal Processing, IEEE Press, New York, 1979. Algorithm 5.2.