[b, a] cheby2(N, Rs, Wn);
[b, a] ellip(N, Rp, Rs, Wn);
The input parameters N and Wn are determined in the order estimation stage. These
functions return the filter coefficients in length N1 row vectors b and a with coeffi-
cients in descending powers of z
À1
. The form of the transfer function obtained is given
by
Hz
b1 b2z
À1
Á Á Á bN 1z
ÀN
1 a2z
À1
Á Á Á aN 1z
ÀN
:
6:5:1
As introduced in Chapter 4, the frequency response of digital filters can be computed
using the function freqz, which returns the frequency response H! of a given
numerator and denominator coefficients in vectors b and a, respectively.
Example 6.12: Design a lowpass Butterworth filter with less than 1.0 dB of ripple
from 0 to 800 Hz, and at least 20 dB of stopband attenuation from 1600 Hz to the
Nyquist frequency 4000 Hz.
The MATLAB script (exam6_12.m in the software package) for designing the
specified filter is listed as follows:
Wp 800/4000; Ws = 1600/4000;
Rp 1.0; Rs 20.0;
[N, Wn] buttord(Wp, Ws, Rp, Rs);
[b, a] butter(N, Wn);
freqz(b, a, 512, 8000);
The Butterworth filter coefficients are returned via vectors b and a by MATLAB
function butter(N,Wn). The magnitude and phase responses of the designed
fourth-order IIR filter are shown in Figure 6.18. This filter will be used for the IIR
filter experiments in Sections 6.7.
Example 6.13: Design a bandpass filter with passband of 100 Hz to 200 Hz and the
sampling rate is 1 kHz. The passband ripple is less than 3 dB and the stopband
attenuation is at least 30 dB by 50 Hz out on both sides of the passband.
The MATLAB script (exam6_13.m in the software package) for designing the
specified bandpass filter is listed as follows:
Wp [100 200]/500; Ws [50 250]/500;
Rp 3; Rs 30;
[N, Wn] buttord(Wp, Ws, Rp, Rs);
[b, a] butter(N, Wn);
freqz(b, a, 128, 1000);
The magnitude and phase responses of the designed bandpass filter are shown in
Figure 6.19.
272
DESIGN AND IMPLEMENTATION OF IIR FILTERS