Professional Documents
Culture Documents
2. Digital filtering
This exercise will introduce FIR and IIR digital filters (lowpass, highpass, passband, stopband),
their frequency and impulse response. Filter use for signal filtering is also demonstrated.
Assignment:
A. FIR Filters
1. Display and draw in your workbook the FIR lowpass filter frequency response for program
setting (order=100, sampling frequency Fs=1000Hz, cutoff frequency f1=60Hz, rectangular
window). Determine the approximate transition width and the ripple.
2. Change type of the window to Hann (hanning). Compare the transition width and the ripple with
the previous case
3. Change type of the window to another one from the windows offer. Compare the transition
width and the ripple with the previous cases
4. Using above described filters try to filter the harmonic signal with amplitude 1V, offset 2V,
Fsignal=100Hz, number of samples N=256. Put the graphs of the input and output signals into
your notebook and find the approximate time delay of the output voltage as compared to the
input voltage.
B. IIR Filters
5. Display and draw in your workbook the IIR Butherworth lowpass filter frequency response for
program default setting (filter order M=3, sampling frequency Fs=1000Hz, cutoff frequency
f1=60Hz). Determine the width of the transition band (for passband ripple 0.1 and stopband
ripple 0.01).
6. Set order of the filter on 10. Compare the transition width to the previous case, draw the
frequency response.
7. Use the Chebychev 1, Chebychev 2 and Elliptic filters of the order M=. Compare the transition
widths, draw the frequency responses
8. Filter input harmonic signal with amplitude 1 V, offset 2 V and frequency 100 Hz using
Butterworth filters (M=3, fs=1000 Hz, f1 = 50 Hz, f2 =150 Hz) of the type: low pass, high pass,
band stop and band pass. Sketch the original and filtered waveforms for each filter into your
notebook. Explain the cause of noise reduction and variation of filtered signal amplitude.
9. Make yourself acquainted with source code of IIR.M
10. In the time left experiment with different filters design (see instructions below).
Guide:
For demonstration of FIR filter design run FIR_AN in Matlab Command Window, script for IIR
filters is called IIR_AN.
Page 2 of 4
Page 3 of 4
[b,a] = cheby2(9,20,300/500);
The frequency response of the filter:
freqz(b,a,512,1000)
4. zp2sos converts a zero-pole-gain representation of a given system to an equivalent secondorder section representation.
Example :
Find a second-order section form of a Butterworth lowpass filter:
[z,p,k] = butter(5,0.2);
sos = zp2sos(z,p,k);
Direct IIR Filter Design
Unlike the analog prototyping method, direct design methods are not constrained to the standard
lowpass, highpass, bandpass, or bandstop configurations. Rather, these functions design filters
with an arbitrary, perhaps multiband, frequency response. yulewalk designs recursive IIR digital
filters by fitting a specified frequency response. yulewalks name reflects its method for finding the
filters denominator coefficients: it finds the inverse FFT of the ideal desired power spectrum and
solves the modified Yule-Walker equations using the resulting autocorrelation function samples.
FIR Filters
Windowing Method
a) Standard Band FIR Filter Design:
b = fir1(n,Wn,options)
fir1 implements the classical method of windowed linear phase FIR digital filter design. It
resembles the IIR filter design functions in that it is formulated to design filters in standard band
configurations: lowpass, bandpass, highpass, and bandstop.
The statements:
n = 50;
Wn = 0.4;
b = fir1(n,Wn);
create row vector b containing the coefficients of the order n Hamming-windowed filter. This is a
lowpass, linear phase FIR filter with cutoff frequency Wn. Wn is a number between 0 and 1, where
1 corresponds to the Nyquist frequency, half the sampling frequency. (Unlike other methods, here
Wn corresponds to the 6 dB point.) As a window you can use in option:
bartlett, blackman, boxcar, chebwin, hamming, hanning, kaiser, triang
Syntax:
b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
where ftype is high for a highpass filter with cutoff frequency Wn, stop for a bandstop filter, if Wn =
[w1 w2], the stopband is w1 < < w2.
Examples
Design a 48th-order FIR bandpass filter with passband 0.35 < w < 0.65:
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
b) Multiband FIR Filter Design:
b = fir2(n,f,m,options)
The function fir2 also designs windowed linear-phase FIR filters, but with an arbitrarily shaped
piecewise linear frequency response. This is in contrast to fir1, which only designs filters in
standard lowpass, highpass, bandpass, and bandstop configurations.
Multiband FIR Filter Design with Transition Bands
Page 4 of 4