IIR Filter Design

7.2.1 IIR Filter Design

The methods of designing IIR filters introduced here are basically the discretizations of analog filters dealt with in Sect. 7.1. We will use the same MATLAB functions that are used for analog filter design.

Example 7.2 IIR Filter Design Let us find the system functions of digital filters (with sampling frequency F s =

50 [kHz]) meeting the specifications given below. (a)We are going to determine the system function of a digital Butterworth lowpass

filter with the passband/stopband edge frequencies, passband ripple, and stop- band attenuation as

ω p = 2 π ×6000 [rad/s], ω s = 2π ×15000 [rad/s], R p = 2 [dB], and A s = 25 [dB] (E7.2.1)

322 7 Analog and Digital Filters First, we prewarp the edge frequencies, design an analog Butterworth LPF satis-

fying the given specifications on the passband ripple and stopband attenuation at the prewarped passband and stopband edge frequencies, and then discretize the LPF through bilinear transformation:

>>Fs=5e4; T=1/Fs; format short e %Sampling frequency and sampling period >>wp=2*pi*6000; ws=2*pi*15000; Rp=2; As=25;

>>wp p=prewarp(wp,T); ws p=prewarp(ws,T); % Prewarp the edge frequencies >>[Nb,wcb]=buttord(wp p,ws p,Rp,As,’s’);%Order, cutoff freq of analog BW LPF >>[Bb,Ab]= butter(Nb,wcb,’s’); % num/den of analog BW LPF system ftn >>[Bb d0,Ab d0]= bilinear(Bb,Ab,Fs) % Bilinear transformation

We can also use the MATLAB function butter() to design a digital Butter- worth filter directly:

>>fp=wp*T/pi; fs=ws*T/pi; %Normalize edge freq into [0,1](1:pi[rad/sample]) >>[Nb,fcb]= buttord(fp,fs,Rp,As) % Order, Cutoff freq of digital BW LPF

Nb = 3, fcb = 3.0907e-001 >>[Bb d,Ab d]= butter(Nb,fcb) % num/den of digital BW LPF system ftn

Bb d = 5.3234e-002

5.3234e-002 Ab d =

1.5970e-001

1.5970e-001

1.0000e+000 -1.1084e+000 6.6286e-001 -1.2856e-001 >>[SOS,Kc]= tf2sos(Bb d,Ab d) % Cascade form realization SOS =

1 1 0 1.0000e+00

-3.0925e-01

-7.9918e-01 4.1571e-01 Kc =

1 2 1 1.0000e+00

5.3234e-002 >>[BBp,AAp,Kp]= tf2par z(Bb d,Ab d) % Parallel form realization BBp =

-9.9489e-001

5.6162e-001 0 1.4622e+000

AAp = 1.0000e+000

Kp = -4.1408e-001

%sig07e02a.m for digital Butterworth LPF design clear, clf, format short e Fs=5e4; T=1/Fs; % Sampling frequency and sampling period wp=2*pi*6000; ws=2*pi*15000; Rp=2; As=25; % analog filter design and discretization through bilinear transformation wp p=prewarp(wp,T); ws p=prewarp(ws,T); % Prewarp the edge frequencies [Nb,wcb]=buttord(wp p,ws p,Rp,As,’s’); % Order, cutoff freq of analog BW LPF [Bb,Ab]= butter(Nb,wcb,’s’); % num/den of analog BW LPF system ftn [Bb d0,Ab d0]= bilinear(Bb,Ab,Fs) % Bilinear transformation % direct digital filter design fp=wp*T/pi; fs=ws*T/pi; % Normalize edge freq into [0,1] (1: pi[rad/sample]) [Nb,fcb]= buttord(fp,fs,Rp,As) % Order of digital BW LPF [Bb d,Ab d]= butter(Nb,fcb) % num/den of digital BW LPF system ftn % Plot the frequency response magnitude fn=[0:512]/512; W=pi*fn; % Normalized and digital frequency range subplot(221), plot(fn,20*log10(abs(freqz(Bb d,Ab d,W))+eps)) % To check if the filter specifications are satisfied hold on, plot(fp,-Rp,’o’, fcb,-3, ’+’, fs,-As,’x’) axis([0 1 -80 10]), title(’Butterworth LPF’) [SOS,Kc]= tf2sos(Bb d,Ab d) % Cascade form realization [BBp,AAp,Kp]= tf2par z(Bb d,Ab d) % Cascade form realization

7.2 Digital Filter Design 323

f s 0 0.2 0.4 Normalized frequency 1.0 –250 0 0.2 Normalized frequency(× π rad/sample) 1.0 (a) From MATLAB

(b) From the FDAtool Fig. 7.7 The magnitude curves of the frequency response of the digital Butterworth LPF

Fig. 7.8 Design of a digital Butterworth LPF with order 3 and cutoff frequency 0.309 using FDAtool

This result means that the system function of the designed Butterworth LPF of order N = 3 is

G + 0.1597z [z] = + 0.1597z + 0.05323

0.05323z 3 2

: Direct form (E7.2.2a) − 1.1084z + 0.6629z − 0.1286

0.05323(z 2 + 2z + 1)(z + 1)

= (z 2 : Cascade form (E7.2.2b) − 0.7992z + 0.4157)(z − 0.3092) −0.9949z 2 + 0.5616z

1.4622z

− 0.4141 : Parallel form − 0.7992z + 0.4157

z − 0.3092

(E7.2.2c)

324 7 Analog and Digital Filters

The magnitude curve of the frequency response of the designed filter is shown in Fig. 7.7. If the order and cutoff frequency are determined, then we can use the FDATool to design a digital filter as depicted in Fig. 7.8 where the same cascade realization is obtained as with butter(). Note that the cutoff frequency fcb determined by buttord() and used by butter() and FDATool is normal- ized to the range of [0,1] with 1 corresponding to Fs/2[Hz] (half the sampling frequency).

(b)We are going to determine the system function of a Chebyshev I BPF with ω s 1 = 2π × 6000, ω p 1 = 2π × 10000, ω p 2 = 2π × 12000,

ω s 2 = 2π × 15000 [rad/s], R p = 2 [dB], and A s = 25 [dB]

(E7.2.3)

First, we prewarp the edge frequencies, design an analog chebyshev I BPF satis- fying the given specifications on the passband ripple and stopband attenuation at the prewarped passband and stopband edge frequencies, and then discretize the BPF through bilinear transformation:

>>Fs=5e4; T=1/Fs; % Sampling frequency and sampling period >>ws1=2*pi*6e3; wp1=2*pi*1e4; wp2=2*pi*12e3; ws2=2*pi*15e3; Rp=2; As=25; >>wp p=prewarp([wp1 wp2],T); ws p=prewarp([ws1 ws2],T); % Prewarp >>[N,wpc]=cheb1ord(wp p,ws p,Rp,As,’s’) %Order & cutoff freq of A-C1 BPF

N = 2, wpc = 7.2654e+004 9.3906e+004 >>[Bc1,Ac1]=cheby1(N,Rp,wpc,’s’) % num/den of analog C1 BPF system ftn >>[Bc1 d0,Ac1 d0]= bilinear(Bc1,Ac1,Fs) % Bilinear transformation

The MATLAB function cheby1() can also be used to design a digital Chebyshev I filter directly as follows:

>>fp=[wp1 wp2]*T/pi; fs=[ws1 ws2]*T/pi; %Normalize edge freq into [0,1] >>[Nc1,fcc1]=cheb1ord(fp,fs,Rp,As) % Order & Cutoff freq of D-C1 BPF

Nc1 = 2,

fcc1 = 0.4 0.48

>>[Bc1 d,Ac1 d]= cheby1(Nc1,Rp,fcc1) % num/den of D-C1 BPF system ftn

0 9.3603e-03 Ac1 d = 1.0000e+00 -7.1207e-01 1.8987e+00 -6.4335e-01 8.1780e-01 >>[SOS,Kc]= tf2sos(Bc1 d,Ac1 d) % Cascade form realization SOS = 1 2 1 1.0000e+000 -1.6430e-001 9.0250e-001 1 -2

Bc1 d = 9.3603e-03

0 -1.8721e-02

1 1.0000e+000 -5.4780e-001 9.0610e-001 Kc = 9.3603e-003 >>[BBp,AAp,Kp]= tf2par z(Bc1 d,Ac1 d) % Parallel form realization BBp = -1.9910e-003 -8.9464e-002 -9.4316e-005 9.7236e-002 AAp =

1.0000e+000 -5.4785e-001 9.0612e-001 1.0000e+000 -1.6432e-001 9.0253e-001

Kp = 1.1446e-002

This means that the system function of the designed Chebyshev I BPF of order 2Nc1 = 4 is

7.2 Digital Filter Design 325

G 9.3603 × 10 −3 z 4 − 1.8721 × 10 −2 z + 9.3603 × 10 [z] = −3

: Direct form

− 0.7121z + 1.8987z − 0.6434z + 0.8178

(E7.2.4a) −3 (z 2 9.3603 × 10 2 + 2z + 1)(z − 2z + 1)

= (z 2 2 : Cascade form − 0.1643z + 0.9025)(z − 0.5478z + 0.9061)

(E7.2.4b1)

2 0.10855 × 0.10855 × 0.7943(z 2 − 1)(z − 1) = (z 2 2 : Cascade form

− 0.1643z + 0.9025)(z − 0.5478z + 0.9061) (E7.2.4b2)

−9.4316 × 10 2 −5 z + 9.7236 × 10 −2 z = 0.011446 +

z 2 − 0.1643z + 0.9025 −1.991 × 10 −3 z 2 − 8.9464 × 10 −2 z

: Parallel form (E7.2.4c) − 0.5478z + 0.9061

–Rp [dB]

f s1 f p1 f p2 f s2 –80 0 0.2 0.4 Normalized frequency 1.0 –80 0 0.2 Normalized frequency (× π rad/sample) 1.0

(a) From MATLAB (b) From the FDAtool Fig. 7.9 The magnitude curves of the frequency response of the digital Chebyshev I BPF

326 7 Analog and Digital Filters

The magnitude curve of the frequency response of the designed filter is shown in Fig. 7.9. If the order and passband edge frequencies are determined, then we use the FDATool to design a digital filter as depicted in Fig. 7.10 where the same cascade realization is obtained as with cheby1(). Note that the critical passband edge frequencies fcc1(1) and fcc1(2) determined by cheb1ord() and used by cheby1() and FDATool are normalized to the range of [0,1] with 1 corresponding to Fs/2[Hz] (half the sampling frequency, i.e., the Nyquist frequency).

(c)We are going to determine the system function of a Chebyshev II BSF with ω p 1 = 2π × 6000, ω s 1 = 2π × 10000, ω s 2 = 2π × 12000,

ω p 2 = 2π × 15000 [rad/s], R p = 2 [dB], and A s = 25 [dB]

(E7.2.5)

Let us use the MATLAB function cheby2() to design a digital Chebyshev II filter directly as follows:

>>Fs=5e4; T=1/Fs; % Sampling frequency and sampling period >>wp1=2*pi*6e3; ws1=2*pi*1e4; ws2=2*pi*12e3; wp2=2*pi*15e3; Rp=2; As=25; >>fp=[wp1 wp2]*T/pi; fs=[ws1 ws2]*T/pi; %Normalize edge freq into [0,1] >>[Nc2,fcc2]=cheb2ord(fp,fs,Rp,As) % Order & Cutoff freq of D-C2 BSF

Nc2 = 2,

fcc2 = 0.4 0.48

>>[Bc2 d,Ac2 d]=cheby2(Nc2,As,fcc2,’stop’) %D-C2 BSF system ftn Bc2 d = 6.0743e-01 -4.5527e-01 1.2816e+00 -4.5527e-01 6.0743e-01 Ac2 d = 1.0000e+00 -5.7307e-01 1.1202e+00 -3.3746e-01 3.7625e-01

>>[SOS,Kc]= tf2sos(Bc2 d,Ac2 d) % Cascade form realization

1.4835e-001 5.9730e-001 1 -0.5495 1 1.0000e+000 -7.2143e-001 6.2992e-001 Kc = 6.0743e-001 >>[BBp,AAp,Kp]= tf2par z(Bc2 d,Ac2 d) % Parallel form realization BBp = -4.7229e-001 2.3377e-001 -5.3469e-001 -7.9541e-002 AAp =

SOS = 1 -0.2000 1 1.0000e+000

1.0000e+000 -7.2143e-001 6.2992e-001 1.0000e+000 1.4835e-001 5.9730e-001

Kp = 1.6144e+000

This means that the system function of the designed Chebyshev II BSF of order 2Nc2 = 4 is

G − 0.4553z + 1.2816z [z] = − 0.4553z + 0.6074 : Direct form

0.6074z 4 3 2

z 4 3 − 0.5731z 2 + 1.1202z − 0.3375z + 0.3763

(E7.2.6a)

0.6074(z 2 − 0.2z + 1)(z 2 − 0.5495z + 1)

= (z 2 2 : Cascade form − 0.1484z + 0.5973)(z − 0.7214z + 0.6299)

(E7.2.6b)

2 −0.4723z 2 + 0.2338z −0.5347z − 0.07954z

− 0.7214z + 0.6299 z 2 + 0.1484z + 0.5973 + 1.6144

7.2 Digital Filter Design 327 The magnitude curve of the frequency response of the designed filter is shown

in Fig. 7.11. If the order and stopband edge frequencies are determined, then we can use the FDATool to design a digital filter as depicted in Fig. 7.12 where the same cascade realization is obtained as with cheby2(). Note that the critical stopband edge frequencies fcc2(1) and fcc2(2) determined by cheb2ord() and used by cheby2() and FDATool are normalized to the range of [0,1] with 1 corresponding to Fs/2[Hz]. Note also that as can be seen from the magnitude curves in Fig. 7.11, the Chebyshev II type filter closely meets the specification on the stopband attenuation ( A s ≥ 25[dB]), while it satisfies that on the passband ripple (R p ≤ 2[dB]) with some margin.

[dB] –Rp –Rp

0 0.2 0.4 Normalized frequency 1.0 0 0.2 Normalized frequency (× π rad/sample) 1.0 (a) From MATLAB

(b) From the FDAtool Fig. 7.11 The magnitude curves of the frequency response of the digital Chebyshev II BSF

Fig. 7.12 Design of a digital Chebyshev II BSF with order 4 and stopband edge frequencies 0.4 & 0.48 using FDAtool (version 7.2-R2006a)

328 7 Analog and Digital Filters (d)We are going to determine the system function of an elliptic HPF with

ω s = 2π × 6000 [rad/s], ω p = 2π × 15000 [rad/s], R p = 2 [dB], and A s = 25 [dB]

(E7.2.7)

Let us use the MATLAB function ellip() to design a digital elliptic filter directly as follows:

>>Fs=5e4; T=1/Fs; % Sampling frequency and sampling period >>ws=2*pi*6e3; wp=2*pi*15e3; Rp=2; As=25; >>fp=wp*T/pi; fs=ws*T/pi; %Normalize edge freq into [0,1]

>>[Ne,fce]=ellipord(fp,fs,Rp,As) % Order & Cutoff freq of D-elliptic HPF Ne = 2, fce = 0.6 >>[Be d,Ae d]=ellip(Ne,Rp,As,fce,’high’) %D-elliptic HPF system ftn Be d = 2.0635e-001 -3.0101e-001 2.0635e-001 Ae d = 1.0000e+000 5.4365e-001 4.4217e-001

>>[SOS,Kc]= tf2sos(Be d,Ae d) % Cascade form realization

5.4365e-001 4.4217e-001 Kc = 2.0635e-001 >>[BBp,AAp,Kp]= tf2par z(Be d,Ae d) % Parallel form realization BBp = -2.6034e-001 -5.5472e-001 AAp =

SOS = 1 -1.4587e+000 1 1.0000e+000

1.0000e+000 5.4365e-001 4.4217e-001 Kp =

4.6669e-001

This means that the system function of the designed elliptic HPF of order Ne = 2 is

G 0.2064z 2 − 0.3010z + 0.2064 0.2064(z − 1.4587z + 1) [z] =

z 2 + 0.5437z + 0.4422 = z 2 + 0.5437z + 0.4422 : Cascade form (E7.2.8a) −0.2603z 2 − 0.5547z

(E7.2.8b) + 0.5437z + 0.4422

= z 2 + 0.4667 : Parallel form

%sig07e02.m for digital filter design and frequency response plot clear, clf, format short e Fs=5e4; T=1/Fs; % Sampling frequency and sampling period disp(’(a) Digital Butterworth LPF’) wp=2*pi*6000; ws=2*pi*15000; Rp=2; As=25; fp=wp*T/pi; fs=ws*T/pi; [Nb,fcb]= buttord(fp,fs,Rp,As) % Order of analog BW LPF [Bb d,Ab d]= butter(Nb,fcb) % num/den of digital BW LPF system ftn fn=[0:512]/512; W=pi*fn; % Plot the frequency response magnitude curve subplot(221), plot(fn,20*log10(abs(freqz(Bb d,Ab d,W))+eps)) hold on, plot(fp,-Rp,’o’, fcb,-3,’+’, fs,-As,’x’) [SOS,Kc]= tf2sos(Bb d,Ab d) % Cascade form realization [BBp,AAp,Kp]= tf2par z(Bb d,Ab d) % Parallel form realization disp(’(b) Digital Chebyshev I BPF’) ws1=2*pi*6e3; wp1=2*pi*1e4; wp2=2*pi*12e3; ws2=2*pi*15e3; Rp=2; As=25;

7.2 Digital Filter Design 329

fp=[wp1 wp2]*T/pi; fs=[ws1 ws2]*T/pi; %Normalize edge freq into [0,1] [Nc1,fcc1]=cheb1ord(fp,fs,Rp,As) % Order & critical passband edge freq [Bc1 d,Ac1 d]= cheby1(Nc1,Rp,fcc1) % num/den of D-C1 BPF system ftn subplot(222), plot(fn,20*log10(abs(freqz(Bc1 d,Ac1 d,W))+eps)) [SOS,Kc]= tf2sos(Bc1 d,Ac1 d) % Cascade form realization [BBp,AAp,Kp]= tf2par z(Bc1 d,Ac1 d) % Parallel form realization disp(’(c) Digital Chebyshev II BSF’) wp1=2*pi*6e3; ws1=2*pi*1e4; ws2=2*pi*12e3; wp2=2*pi*15e3; Rp=2; As=25; fp=[wp1 wp2]*T/pi; fs=[ws1 ws2]*T/pi; %Normalize edge freq into [0,1] [Nc2,fcc2]=cheb2ord(fp,fs,Rp,As) % Order & critical edge frequencies [Bc2 d,Ac2 d]=cheby2(Nc2,As,fcc2,’stop’) %num/den of D-C2 BSF system ftn subplot(223), plot(fn,20*log10(abs(freqz(Bc2 d,Ac2 d,W))+eps)) [SOS,Kc]= tf2sos(Bc2 d,Ac2 d) % Cascade form realization [BBp,AAp,Kp]= tf2par z(Bc2 d,Ac2 d) % Parallel form realization disp(’(d) Digital elliptic HPF’) ws=2*pi*6000; wp=2*pi*15000; Rp=2; As=25; fp=wp*T/pi; fs=ws*T/pi; %Normalize edge freq into [0,1] [Ne,fce]=ellipord(fp,fs,Rp,As) % Order & Cutoff freq of D-elliptic HPF [Be d,Ae d]=ellip(Ne,Rp,As,fce,’high’) % D-elliptic HPF system ftn subplot(224), plot(fn,20*log10(abs(freqz(Be d,Ae d,W))+eps)) [SOS,Kc]= tf2sos(Be d,Ae d) % Cascade form realization [BBp,AAp,Kp]= tf2par z(Be d,Ae d) % Parallel form realization:

The magnitude curve of the frequency response of the designed filter is shown in Fig. 7.13. If the order and cutoff frequency are determined, then we use the FDATool to design a digital filter as depicted in Fig. 7.14, yielding the cascade realization close to that obtained with ellip(). Note that the cutoff frequency fce determined by ellipord() and used by ellip() and FDATool is nor- malized to the range of [0,1] with 1 corresponding to Fs/2[Hz] (half the sampling frequency).

(e)All the above filter design works are put into the M-file named “sig07e02.m”, which plots the frequency responses of the designed filters so that one can check if the design specifications are satisfied. Figs. 7.7(a), 7.9(a), 7.11(a), and 7.13(a), obtained by running the program “sig07e02.m”, show the following points:

- Figure 7.7(a) shows the monotone frequency response magnitude of a Butter- worth filter. - Figure 7.9(a) shows that the critical passband edge frequencies f p 1 and f p 2 given as an input argument fcc1 = [fp1 fp2] of ‘cheby1()’ are the frequencies at which the passband ripple condition is closely met. Note that the frequency response magnitude of a Chebyshev I filter satisfying the passband ripple con- dition closely has a ripple in the passband, which is traded off for a narrower transition band than the Butterworth filter (with the same filter order).

- Figure 7.11(a) shows that the critical stopband edge frequencies f s 1 and f s 2 given as an input argument fcc2 = [fs1 fs2] of ‘cheby2()’ are the frequencies

at which the stopband attenuation condition is closely met. Note that the fre- quency response magnitude of a Chebyshev II filter satisfying the stopband attenuation condition closely has a ripple in the stopband.

330 7 Analog and Digital Filters

[dB] 0 –Rp

–80 0 0.2 0.4 Normalized frequency 1.0 0 0.2 Normalized frequency (xπ rad/sample) 1.0

(a) From MATLAB (b) From the FDAtool

Fig. 7.13 The magnitude curves of the frequency response of the digital elliptic HPF

Fig. 7.14 Design of a digital elliptic HPF with order 2 and stopband/passband edge frequencies 0.24/0.6 using FDAtool (version 7.2-R2006a)

7.2 Digital Filter Design 331

Fig. 7.15 The state diagram of a filter drawn by the ‘Realize Model’ function of FDAtool

- Figure 7.13(a) shows that the critical passband edge frequency f p given as an input argument fce of ‘ellip()’ is the frequency at which the passband ripple condition is closely met. Note that the frequency response magnitude of an elliptic filter has ripples in both the passband and the stopband, yielding a relatively narrow transition band with the smallest filter order N = 2 among the four filters.

Note that we can click the Realize Model button or the Pole/Zero Editor button on the left-hand side of the FDATool window to create a Simulink model file having the designed filter block as depicted in Fig. 7.15 or to see the pole/zero plot of the designed filter as illustrated in Fig. 7.14.