Design of IIR filters Giuseppe Scarpa ENS 2013 Contents 1 Introduction 2 2 CT lowpass 2.1 The Butterworth approximation . . . . . . . . . . . . 2.2 The Chebyshev approximation . . . . . . . . . . . . . 2.3 The inverse Chebyshev or Chebyshev II approximation 2.4 The elliptic or Cauer approximation . . . . . . . . . . . . . . 3 4 6 9 10 3 CT to DT 3.1 Impulse-invariance transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Bilinear transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 11 15 4 Lowpass examples 19 5 Frequency transformations 5.1 Continuous-time frequency transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Discrete-time frequency transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 21 22 6 M ATLAB examples 24 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Introduction to the IIR filter design problem Key observation: A practically realizable IIR (in particular a causal one) cannot have a linear phase response ⇓ The approximation concerns magnitude AND phase response ⇓ The direct optimization according to any given criterion becomes a very complex task ⇓ The canonical design paradigm for IIR moves the problem to the continuous-time domain. General design paradigm for IIR The reference general paradigm for IIR filter design lies on the following steps: CT specifications: the conversion of the (given) IIR specifications in continuous-time (CT) specifications CT filter design: continuous-time filter design CT/DT transformation: transformation of the CT filter in a DT filter In addition, for selective filters like BP, HP, SB it is custom to design a lowpass in the CT domain and the apply a frequency band transformation. The frequency band transformation can be carried both in the CT and the DT domains, resulting in two possible approaches: CT specifications: specification in the CT domain for the equivalent lowpass Lowpass CT filter design: design of the equivalent LP filter CT band shift: frequency band transformation in the CT domain CT/DT transformation: CT to DT filter transformation DT band shift: frequency band transformation in the DT domain where only one band shift step has to be chosen. FIR vs IIR Advantages of FIR: • possibility to have exact linear phase • always stable with finite-duration transients • design methods generally linear in filter parameters • flexibility in the choice of the frequency response Advantages of IIR: • much smaller filter order for fixed specifications • typically much smaller delay introduced • noniterative design methods ⇒ no need for computer-aided techniques 2 2 Design of continuous-time lowpass filter Magnitude-squared response Let us start analysing some properties of the magnitude-squared response of a real-coefficients CT system. We can write: |Hc (jΩ)|2 = Hc (jΩ)Hc∗ (jΩ) = Hc (jΩ)Hc (−jΩ) = Hc (s)Hc (−s)|s=jΩ Therefore: (s − sk ) is a factor of Hc (s) ⇒ (−s − sk ) is a factor of Hc (−s) ⇓ (s − sk )(−s − sk ) = (s2k − s2 )s=jΩ = (s2k + Ω2 ) is a factor of |Hc (jΩ)|2 Hence we can always write |Hc (jΩ)|2 = G2 2 (Ω2 + ζ12 )(Ω2 + ζ22 ) · · · (Ω2 + ζM ) 2 2 2 2 2 2 (Ω + s1 )(Ω + s2 ) · · · (Ω + sN ) For real system zeros and poles are either real o pairs of complex conjugate ones: real (Ω2 + s2k ) ∈ R+ complex conjugate s1 = rejθ , s2 = re−jθ : (Ω2 + s21 )(Ω2 + s22 ) = (Ω2 − r2 )2 ∈ R+ In conclusion |Hc (jΩ)|2 is: • real and non negative • rational function in Ω2 • differentiable For these reasons it is typically preferred to |Hc (jΩ)| for the design of continuous-time filters. Observe, also, that due to the causality and stability requirements the phase response cannot be assigned independently. In continuous-time lowpass filter design, the magnitude-squared function is usually put in the following form: ( V 2 (Ω) << 1, Ω < Ωc 1 2 , |Hc (jΩ)| = 2 1 + V (Ω) V 2 (Ω) >> 1, Ω > Ωc Different choices of V (Ω) lead to different design techniques. Observe: • once determined |Hc (jΩ)|2 , a proper spectral factorization is needed to get a causal and stable solution. • zeros and poles of Hc (s)H(−s) are symmetrically located wrt both the real and the imaginary axes (quadrantal symmetry) • hence, causal and stable systems are obtained by picking poles from the left-half plane • if zeros are taken from the left-half plane as well, than minimum phase is also achieved 3 Analog specification |H(jΩ)|2 Specifications Relative Transition band Analog 0 Passband 1 Ideal Response Ap 1 1+2 Passband ripple As Stopband ripple Stopband 1 A2 Ω Ωp Ωc Ωs Passband edge Cutoff-freq. 2.1 Stopband edge The Butterworth approximation The Butterworth family of lowpass filter is defined by the following formula |HB (jΩ)|2 , 1 , 1 + (Ω/Ωc )2N N = 1, 2, . . . Properties: • |HB (j0)|2 = 1 • |HB (j∞)|2 = 0 • |HB (jΩc )|2 = 1/2 (Ωc is the 3dB cutoff frequency for all N ) • Maximally flat • Asymptotic rolloff ρ∞ ≈ 6N dB/oct. Ideal LP (N = ∞) |HB (jΩ)|2 1 1/2 N ↑ Ω Ωc Pole locations The solution of the equation 1 + (s/jΩc )2N = 0 yields the 2N poles: ( σk = Ωc cos θk sk = σk + jΩk , where Ωk = Ωc sin θk with θk , π 2k − 1 + π, 2 2N k = 1, 2, . . . , 2N 4 π/N I{s} s1 I{s} s12 s1 N =6 s2 s11 s2 s3 s10 s4 s9 Ωc s5 N =5 s9 s3 s8 R{s} R{s} s4 s8 s6 s10 s7 s5 s7 s6 • poles never occur on the imaginary axis • poles occur on the real axis only for odd values of N • stability is obtained by selecting the N poles lying on the left-half plane (gray) HB (s) = ΩN c (s − s1 )(s − s2 ) · · · (s − sN ) Design procedure Let Ωp , Ωs , Ap and As be the specifications. We want to find the filter parameters Ωc and N . To satisfy the specification we need: ( 1 1+(Ωp /Ωc )2N 1 1+(Ωs /Ωc )2N =⇒ Ωs Solving wrt N : N ≥ ≤ ≥ 1 1+2 1 A2 ΩN c ⇔ (Ωp /Ωc )2N ≤ 2 ⇔ (Ωs /Ωc )2N ≥ A2 − 1 p A 2 − 1 ≥ Ωp N √ A2 − 1 √ ln β Ωs 1p 2 10As /10 − 1 N≥ , where α , , β, A −1= p ln α Ωp 10Ap /10 − 1 In particular we can choose the smallest N larger than ln β/ ln α: ln β N= ln α Once computed N , Ωc can be anywhere in the interval: Ωp (10Ap /10 − 1)−1/2N ≤ Ωc ≤ Ωs (10As /10 − 1)−1/2N Observe: • the left limit satisfy exactly the specifications at Ωp • the right limit satisfy exactly the specifications at Ωs • if we want smaller ripple in the bandpass, than we take the right limit 5 M ATLAB functions for analog Butterworth lowpass The SP toolbox provides the following functions: • [N,Omegac] = buttord(Omegap,Omegas,Ap,As,’s’) • [C,D] = butter(N,Omegac,’s’) where C and D are the numerator and denominator polynomials of the system function. Example: design of a Butterworth lowpass filter [buttex.m] Specifications: Fp = 40Hz, Fs = 50Hz, Ap = 1dB, As = 30dB » Op = 2*pi*40; Os = 2*pi*50; Ap = 1; As = 30; » [N,Oc] = buttord(Op,Os,Ap,As,’s’); N N = 19 » Fc = Oc/(2*pi) Fc = 41.6902 » [C, D] = butter(N,Oc,’s’); » % Plots... » % ... 2.2 The Chebyshev approximation Differently from FIR filters, in the IIR case there are closed formulas for filter design, avoiding the use of iterative algorithms for searching the optimal solution. Start with the Chebyshev I: |HC (jΩ)|2 = 1 1+ 2 TN2 (Ω/Ωc ) 2 The approximation error, for << 1, is: 2 EC (Ω/Ωc ) = 1 − 1 ≈ 2 TN2 (Ω/Ωc ), 1 + 2 TN2 (Ω/Ωc ) |Ω| ≤ Ωc • A Chebyshev polynomial TN (x) is defined for any value of x, and not just on the interval [−1, 1] • However the formula used for TN (x) in the passband TN (x) = cos(N cos−1 x), |x| ≤ 1 is not valid for |x| > 1 • It can be proved that TN (x) = cosh(N cosh−1 x), M ATLAB generation of Chebyshev polynomials: 6 |x| > 1 |x| ≤ 1: T = cos(N*acos(x)) |x| > 1: T = cosh(N*acosh(x)) |HC (jΩ)| N =4 N =6 N =7 1 √ 1 1+2 Ω Ωc Properties of the lowpass Chebyshev I filter • |ω| ≤ Ωc ⇒ |HC (jΩ)|2 equiripple between 1 and 1 1+2 • |ω| > Ωc ⇒ |HC (jΩ)|2 → 0 (monotonically) • Asymptotic roll-off 20N dB/decade = 6N dB/octave ( 1, N odd • |HC (j0)|2 = , |HC (jΩc )|2 = 1/(1 + 2 ), N even 1 1+2 Pole locations The solution of the equation 1 + 2 TN2 (s/jΩc ) = 0 yields the 2N poles: ( σk = [Ωc sinh(φ)] cos θk sk = σk + jΩk , where Ωk = [Ωc cosh(φ)]] sin θk with θk , π 2k − 1 + π, 2 2N k = 1, 2, . . . , 2N and 1 1 sinh−1 N It can be shown that the poles lie on an elliptic curve elongated in direction of the vertical axis By selecting the poles lying on the left-half plane ({sk }, k = 1, 2. . . . , N ) we get a stable and causal system with system function: ( √ N Y 1/ 1 + 2 , N even G HC (s) = QN , G= (−sk ) × 1, N odd k=1 (s − sk ) k=1 φ, with G selected to satisfy the normalization condition on HC (j0). 7 Design procedure Given Ωp , Ωs , Ap and As −→ find Ωc and N . To satisfy the specification we need: ( 1 2 (Ω /Ω ) 1+2 TN p c 1 2 (Ω /Ω ) 1+2 TN s p ≥ ≤ 1 1+2 1 A2 ⇐ Ωc = Ωp ⇔ TN (Ωs /Ωp ) ≥ 1 √ A2 − 1 Outside the passband (|Ω| > Ωp = Ωc ) we have: Solving wrt N : 1p cosh N cosh−1 (Ωs /Ωp ) ≥ A2 − 1 p 2−1 ln β + β cosh β √ = N≥ cosh−1 α ln α + α2 − 1 −1 where α and β are the same parameters involved in the Butterworth design procedure. √ Ωs 10As /10 − 1 1p 2 α, , β, A −1= p Ωp 10Ap /10 − 1 M ATLAB functions for analog Chebyshev I lowpass The SP toolbox provides the following functions: • [N,Omegac] = cheb1ord(Omegap,Omegas,Ap,As,’s’) • [C,D] = cheby1(N,Ap,Omegac,’s’) where C and D are the numerator and denominator polynomials of the system function. Example: design of a Chebyshev I lowpass filter [cheb1ex.m] Specifications: Fp = 40Hz, Fs = 50Hz, Ap = 1dB, » Op = 2*pi*40; Os = 2*pi*50; Ap = 1; As = 30; » [N,Oc] = cheb1ord(Op,Os,Ap,As,’s’); N N = 7 » Fc = Oc/(2*pi) Fc = 40 » [C, D] = cheby1(N,Ap,Oc,’s’); » % Plots... » % ... 8 As = 30dB 2.3 The inverse Chebyshev or Chebyshev II approximation To convert a Chebyshev I to a Chebyshev II we need two steps: • Ωc /Ω −→ Ω/Ωc • Complement to 1 of |HC (jΩ)|2 |HC (jΩ)|2 |HC (jΩ)|2 1 1 A2 −1 A2 A2 −1 A2 2 1+2 2 1+2 1 1 1 1+2 1 A2 Ω/Ωc 1 Therefore: |HIC (jΩ)|2 , 1 − |HIC (jΩ)|2 Ω/Ωc 1 1 + 2 TN2 (Ωc /Ω) = 1 Ω/Ωc 2 TN2 (Ωc /Ω) 1 + 2 TN2 (Ωc /Ω) Observe the maximally flat behaviour in the passband. Zeros and poles Zeros: TN (jΩc /s) = cos[N cos −1 ( ζk = jΩc / cos uk (jΩc /s)] = 0 ⇒ π uk = 2k−1 N 2 , k = 1, . . . , 2N Poles: TN (jΩc /s) = ±j/ ⇒ sk = Ω2c σk + jΩk where σk and Ωk are the same coefficients defined for the Chebyshev I , that is: σk = [Ωc sinh(φ)] cos θk Ω = [Ω cosh(φ)]] sin θ k c k θk , π2 + 2k−1 π, k = 1, 2, . . . , 2N 2N −1 1 1 φ , N sinh Observe that the poles do not lie on any geometric curve, while the zeros are located on the imaginary axis. Design by M ATLAB The design procedure is similar to that of Chebyshev I, except that the roles of passband and stopband are interchanged, that is: • Ωc is anchored to Ωs • N is determined to satisfy the specifications in the passband The M ATLAB SP Toolbox provides the necessary functions: • [N,Ws] = cheb2ord(Omegap,Omegas,Ap,As,’s’) • [C,D] = cheby2(N,As,Ws,’s’) 9 where C and D are the numerator and denominator polynomials of the system function. Ws is the exact stopband edge frequency. Example: design of a Chebyshev II lowpass filter [cheb2ex.m] Specifications: Fp = 40Hz, Fs = 50Hz, Ap = 1dB, As = 30dB » Op = 2*pi*40; Os = 2*pi*50; Ap = 1; As = 30; » [N,Ws] = cheb2ord(Op,Os,Ap,As,’s’); N N = 7 » Fs = Ws/(2*pi) Fs = 49.8720 » [C, D] = cheby2(N,As,Ws,’s’); » % Plots... » % ... 2.4 The elliptic or Cauer approximation Equiripple behaviour in passband or stopband provides a performance gain (smaller N for fixed specifications) ⇓ We can expect additional gain with equiripple in both bands, which is obtained by [no proof]: |HE (jΩ)|2 , 1 2 (Ω/Ω ) 1 + 2 RN c due to Cauer, and also referred to as elliptic filter, where the Chebyshev polynomial has been replaced by 2 2 Ω22N −1 −Ω2 Ω23 −Ω2 ν 2 Ω1 −Ω · · · 1−Ω N even 2 2, 1−Ω21 Ω2 1−Ω23 Ω2 2N −1 Ω RN (Ω) , 2 2 2 2 2 2 Ω −Ω Ω −Ω Ω −Ω ν 2 Ω2 2 2 2 4 2 2 · · · 2N2 2 , N odd 1−Ω Ω 1−Ω Ω 1−Ω Ω 2 4 2N Design by M ATLAB We skip heavy analytical aspects concerning the design of Cauer filters, focusing on the M ATLAB based design. As usual one function computes the filter parameters, the other singles out the system function: • [N,Oc] = ellipord(Omegap,Omegas,Ap,As,’s’) • [C,D] = ellip(N,Ap,As,Oc,’s’) where C and D are the numerator and denominator polynomials of the system function. Oc is the passband edge frequency Ωp . Example: design of a Cauer lowpass filter [cauerex.m] Specifications: Fp = 40Hz, Fs = 50Hz, Ap = 1dB, 10 As = 30dB » Op = 2*pi*40; Os = 2*pi*50; Ap = 1; As = 30; » [N,Oc] = ellipord(Op,Os,Ap,As,’s’); N N = 5 » [C, D] = ellip(N,Ap,As,Oc,’s’); » % Plots... » % ... Comparison • Butterworth filters are optimal in the maximally flat sense • Elliptic filters are optimal in the minimax sense (minimum ripples and steepest transition) • Chebyshev I and II are in the middle About the group delay The phase has not been taken in consideration in the design. If the (linearity of the) phase response is of critical importance than the Butterworth and the Chebyshev II filters are the most suited solutions. 3 Transformation of continuous-time filters to discrete-time IIR filters Our attention we be focused on two (among several ones) solutions: Impulse-invariance: for didactic purpose Bilinear transform: because is the state-of-the-art A mapping function s = f (z) from s-plane to z-plane should satisfy the three following conditions, in order to ensure the practical realizability: • A rational Hc (s) should be mapped to a rational H(z); • Imaginary axis to the unit circle: {s = jΩ, −∞ < Ω < ∞} −→ {z = ejω , −π < ω ≤ π} • left-half s-plane mapped into the interior of the unit circle of the z-plane 3.1 Impulse-invariance transformation Given by the sampling the continuous-time impulse response: h[n] , Td hc (nTd ) (Td , design sampling period) Said impulse-invariance because it preserves the shape of hc (t) Spectral domain: 11 The time-domain sampling corresponds to replication in the spectral domain (with possibility of aliasing!): ∞ X H(ejω ) = k=−∞ ω 2π Hc j +j k Td Td Mapping for the impulse-invariance transformation For simplicity rely on a proper (M < N ) rational system function Hc (s). We can then consider a partial fraction expansion: N N X X Ak ⇒ hc (t) = Ak esk t u(t) Hc (s) = s − sk k=1 k=1 ⇒ ⇒ sk Td H(z) = ∞ X h[n] = Td hc (nTd ) = N X Td Ak (esk Td )n u[n] k=1 h[n]z −n = n=0 ∞ X N X Td Ak (esk Td )n z −n = n=0 k=1 N X k=1 Td Ak 1 − esk Td z −1 provided |e | < 1. Therefore the following pole mapping rule applies: sk pole of Hc (s) ⇒ pk , esk Td pole of Hc (s) This rule corresponds to the following mappings s = f (z): s= ln z ⇔ z = esTd Td or, equivalently (assuming s , σ + jΩ and z , rejω ) ( r = eσTd ω = ΩTd Observe that this mapping rule does not apply for zeros. Aliasing The impulse-invariance transformation IS NOT a one-to-one mapping. In fact s1 = σ + jΩ1 and s2 = σ + jΩ2 , will be mapped into the same point z = eσTd ejΩ1 Td , if Ω1 − Ω2 = 2kπ Td . Ω I{z} z=e sTd z = ejω π Td s = ± 2kπ T d ω σ − Tπ d 1 s=± (2k+1)π Td 3π −T d H(z)|z=esTd = ∞ X k=−∞ 12 2πk Hc s + j Td R{z} M ATLAB The impulse-invariance transformation of a rational transfer function of a CT system can be done using: [B,A] = impinvar(C,D,Fd) where [C,D] and [B,A] are the numerator/denominator polynomial coefficients of the CT and its DT counterpart system function, respectively. Example: Impulse-invariance transformation L hc (t) = e−2t u(t) ←−→ Hc (s) = 1 , Re [s] > −2 s+2 » C = [1]; D = [1,2]; Td = 0.1; » [B,A] = impinvar(C, D, 1/Td) B = 0.1000 A= 1.000 -0.8187 ⇒ H(z) = 0.1 1−0.8187z −1 , |z| > 0.8187 Limitations of the impulse-invariance technique • As already observed the first important limitation is the aliasing. The reduction of the aliasing effects can be obtained by reducing Td • More in general if the system function Hc (s) is not a proper function, the technique cannot be applied at all. The replication formula would not converge at all. Design procedure (lowpass) Specification: ωp , ωs , Ap and As 1. Choose Td ( ωp → Ωp = ωp /Td 2. ωs → Ωs = ωs /Td 3. Design the equivalent analog Hc (s) (Butterworth or Chebyshev I)1 4. Poles mapping or M ATLAB conversion by means of impinvar Example (Butterworth) Specifications: ωp = 0.25π, ωs = 0.4π, Ap = 1dB, As = 30dB » op=0.25*pi; os=0.4*pi; Ap=1; As=30; 1. » Td=0.1; 2. » Op = op/Td; Os = os/Td; 3. » [N,Oc] = buttord(Op,Os,Ap,As,’s’); » [C,D] = butter(N,Oc,’s’); 1 Because of the aliasing, filters with equiripple behaviour in the stopband are unsuited 13 4. » [B,A] = impinvar(C,D,1/Td); » N N = 9 Example (Chebyshev I) Specifications: ωp = 0.25π, ωs = 0.4π, Ap = 1dB, As = 30dB » op=0.25*pi; os=0.4*pi; Ap=1; As=30; 1. » Td=0.1; 2. » Op = op/Td; Os = os/Td; 3. » [N,Oc] = cheb1ord(Op,Os,Ap,As,’s’); » [C,D] = cheby1(N,Ap,Oc,’s’); 4. » [B,A] = impinvar(C,D,1/Td); » N N = 5 Example (Chebyshev II) [impinvex.m] Specifications: ωp = 0.25π, ωs = 0.4π, Ap = 1dB, As = 30dB » op=0.25*pi; os=0.4*pi; Ap=1; As=30; 1. » Td=0.1; 2. » Op = op/Td; Os = os/Td; 3. » [N,Oc] = cheb2ord(Op,Os,Ap,As,’s’); » [C,D] = cheby2(N,As,Oc,’s’); 4. » [B,A] = impinvar(C,D,1/Td); » N N = 5 14 3.2 Bilinear transformation • The bilinear transformation avoids the limitations of the impulse invariance due to the aliasing • It is a one-to-one nonlinear transformation between s-plane and z-plane • It is defined by the following relationship: s = f (z) , 2 1 − z−1 Td 1 + z −1 • The design parameter Td is not subject to any limitation and can be chosen to simplify the analytical derivations • It satisfies all the realizability conditions and is the most popular mapping technique Realizability The bilinear transformation is formally obtained by: H(z) = Hc (s)|s= 2 1−z −1 Td 1+z −1 Therefore a generic factor (zero or pole) is transformed as follows: s − νk = = 2 1 − z −1 2 1 − z −1 − (1 + z −1 )νk Td /2 − ν = k Td 1 + z −1 Td 1 + z −1 2(1 − Td νk /2) 1 + Td νk /2 −1 ... = z 1 − Td (1 + z −1 ) 1 − Td νk /2 Eventually: νk −→ 1 + Td νk /2 1 − Td νk /2 Zero and pole mapping Therefore the bilinear transformation can be obtained by individually mapping zeros and poles... having: H(z) = G where Observe: zk = G = QM (1 + z −1 )N −M k=1 (1 − zk z −1 ) QN −1 ) k=1 (1 − pk z 1+Td ζk /2 1+Td sk /2 pk = 1−T 1−Td ζk /2 , d sk /2 Td N −M QM Td β0 2 k=1 1−ζk 2 QN Td k=1 1−sk 2 • A rational Hc (s) always gives a rational H(z) • The mapping preserves the system order N • If M < N the # of zeros increases → (1 + z −1 )N −M (adjoining N − M zeros in −1) 15 M ATLAB function for bilinear transformation The M ATLAB bilinear transformation can be done either by zeros/poles mapping or by polynomial coefficients conversion: • [zd, pd, G] = bilinear(zc,pc,beta0,Fd) – zeros ζk (zc), poles sk (pc) and gain β0 (beta0) of the analog system Hc (s); design parameter 1/Td (Fd) – zeros zk (zd), poles pk (pd) and gain G (G) of the discrete system H(z) • [B,A] = bilinear(C,D,Fd) – numerator (C) and denominator (D) coefficients of the analog system Hc (s) – numerator (B) and denominator (A) coefficients of the discrete system H(z) Example of bilinear transformation Hc (s) = 5s + 10 5(s + 2) = 2 (s + 3)(s + 4) s + 7s + 12 Therefore: » beta0=5; zc=-2; pc=[-3;-4]; Td=2; % C=[5,10]; D=[1,7,12]; Td=2; » [zd, pd, G] = bilinear(zc,pc,beta0,1/Td); % [Bd, Ad] = bilinear(C,D,1/Td); Mapping properties Let z = rejω and s = σ + jΩ, therefore z = rejω = 2/Td + s 2/Td + σ + jΩ = 2/Td − s 2/Td − σ − jΩ hence r = |z| = 2 1/2 (2/Td + σ)2 + Ω (2/Td − σ)2 + Ω2 and ω = tan−1 On the unit circle we have: Ω 2/Td + σ ω = 2 tan−1 ΩTd 2 ⇒ + tan−1 ⇔ Ω= Ω r < 1, if σ < 0 r = 1, if σ = 0 r > 1, if σ > 0 Ω 2/Td − σ ω 2 tan Td 2 I{z} s = f (z) z = ejω s = j∞ s=0 ω 0 σ 1 s = −j∞ 16 R{z} • the open left-half plane is mapped in the interior of the unit circle • jΩ axis is mapped onto the unit circle • the open right-half plane is mapped outside the unit circle • Ω = 0 ⇒ ω = 0 and Ω → ±∞ ⇒ ω → ±π • NO ALIASING • causal and stable CT filters yield causal and stable DT filters Frequency warping The nonlinear relationship between ω and Ω, ω = 2 tan −1 ΩTd 2 ⇔ Ω= ω 2 , tan Td 2 10 Ω 8 6 Flat response 8 6 4 Linear response 10 4 2 gives rise to a nonlinear frequency scaling, known as frequency warping, which may cause distortion, both in magnitude and phase response. 2 Ω Ω= 2 Td tan ω 2 ω/π 0.2 1 |Hc (jΩ)| 2 Linear response 0.4 0.6 0.8 1 2 |H(ejω )| 1 Linear response Flat response Nonlinear response ω/π 0.2 0.4 0.6 0.8 1 Observations: • since tan φ ≈ φ for small φ, then the relation between Ω and ω is approximatively linear for |ω| < 0.3π (no warping) • in general flat responses cannot be distorted by the warping • warping distorts nonflat responses for |ω| > 0.3π (Ex.: differentiators cannot be converted by bilinear transformation) • frequency bands are nonlinearly translated/scaled, thus prewarping is necessary: ω 2 k Ωk = tan Td 2 The value Td can be feely set and it is usually set to Td = 2 to simplify the derivations • phase response is affected in similar manner. As consequence phase linearity is not preserved 17 Design procedure (lowpass) Specification: ωp , ωs , Ap and As 1. Set Td = 2 ( ωp → Ωp = tan(ωp /2) 2. ωs → Ωs = tan(ωs /2) 3. Design the equivalent analog Hc (s) 4. Pole/zero/gain mapping or M ATLAB conversion by means of impinvar Example (Butterworth) Specifications: ωp = 0.25π, ωs = 0.4π, Ap = 1dB, As = 30dB » op=0.25*pi; os=0.4*pi; Ap=1; As=30; 1. » Td=2; 2. » Op = tan(op/2); Os = tan(os/2); 3. » [N,Oc] = buttord(Op,Os,Ap,As,’s’); » [C,D] = butter(N,Oc,’s’); 4. » [B,A] = bilinear(C,D,1/Td); » N N = 8 Example (Chebyshev II) [bilinearex.m] Specifications: ωp = 0.25π, ωs = 0.4π, Ap = 1dB, As = 30dB » op=0.25*pi; os=0.4*pi; Ap=1; As=30; 1. » Td=2; 2. » Op = tan(op/2); Os = tan(os/2); 3. » [N,Oc] = cheb2ord(Op,Os,Ap,As,’s’); » [C,D] = cheby2(N,As,Oc,’s’); 4. » [B,A] = bilinear(C,D,1/Td); » N N = 5 18 4 Design examples for lowpass IIR filters M ATLAB functions for bilinear transf.-based IIR design M ATLAB provides functions to directly design discrete-time IIR, which incorporate the bilinear transformation. These functions are overloads of the corresponding ones used for continuous-time filter design: buttord, butter, cheb1ord, cheby1,... where the option parameter ’s’ is omitted. ( » [N,omegac] = buttord(omegap,omegas,Ap,As); Butterworth » [B,A] = butter(N,omegac); Chebyshev I ( » [N,omegac] = cheb1ord(omegap,omegas,Ap,As); » [B,A] = cheby1(N,A,pomegac); ( » [N,omegac] = cheb2ord(omegap,omegas,Ap,As); Chebyshev II » [B,A] = cheby2(N,As,omegac); Elliptic ( » [N,omegac] = ellipord(omegap,omegas,Ap,As); » [B,A] = ellip(N,Ap,As,omegac); Warning: in this case omegap and omegas must be normalized: omegap ← ωp /π, omegas ← ωs /π In the following we will show several realistic examples [iirlpexe.m] using the above functions Example (Digital Butterworth lowpass) Specifications: ωp = 0.2π, ωs = 0.3π, Ap = 1dB, As = 50dB » op=0.2; os=0.3; Ap=1; As=50; » [N,oc] = buttord(op,os,Ap,As); » [B,A] = butter(N,oc); % Plots... » [N oc] ans = 17 0.2218 Example (Digital Chebyshev I lowpass) Specifications: ωp = 0.3π, ωs = 0.4π, Ap = 0.5dB, As = 60dB 19 » op=0.3; os=0.4; Ap=0.5; As=60; » [N,oc] = cheb1ord(op,os,Ap,As); » [B,A] = cheb1(N,Ap,oc); % Plots... » [N oc] ans = 10 0.3000 Example (Digital Chebyshev II lowpass) Specifications: ωp = 0.35π, ωs = 0.45π, Ap = 0.1dB, As = 60dB » op=0.35; os=0.45; Ap=0.1; As=60; » [N,oc] = cheb2ord(op,os,Ap,As); » [B,A] = cheb2(N,As,oc); % Plots... » [N oc] ans = 12 0.4500 Example (Digital elliptic lowpass) Specifications: ωp = 0.4π, ωs = 0.55π, Ap = 1dB, As = 80dB » op=0.4; os=0.55; Ap=1; As=80; » [N,oc] = ellipord(op,os,Ap,As); » [B,A] = ellip(N,Ap,As,oc); % Plots... » [N oc] ans = 7 0.4000 20 5 Frequency transformations of lowpass filters Although the frequency transformation can be performed both in CT and in DT domains, there are some limitations in the CT case that make the DT frequency transformation more general ⇓ Therefore we will analyse the DT transformations in more detail, and will give a brief look at the CT case, just for completeness. In particular, the key limitation of CT frequency transformation is that the subsequent CT to DT conversion may be heavily affected be aliasing, if the impulse-invariance is used 5.1 Continuous-time frequency transformations Frequency transformations for continuous-time filters have been studied extensively. The following table summarizes the different transformations, assuming as template filter a lowpass with cutoff frequency Ωc = 1rad/s. Filter type Transform. Lowpass s→ Design parameters s Ωc Ωc = cutoff frequency Ωc = cutoff frequency ( Ω1 = lower cutoff frequency Ω = upper cutoff frequency ( 2 Ω1 = lower cutoff frequency Ω2 = upper cutoff frequency Highpass s→ Ωc s Bandpass s→ s2 +Ω1 Ω2 s(Ω2 −Ω1 ) Bandstop s→ s(Ω2 −Ω1 ) s2 +Ω1 Ω2 M ATLAB provides the following functions for analog filter conversion: lp2lp, lp2hp, lp2bp and lp2bs. Example (Lowpass to bandpass analog conversion) Specifications: Fp1 = 20Hz, Fp2 = 60Hz, Ap = 1dB, As = 40dB » Fp1 = 20; Fp2 = 60; Ap = 1; As = 40; % LP design (elliptic) » Omegap = 1; Omegas = 1.5; » [N,Omegac]=ellipord(Omegap,Omegas,Ap,As,’s’); » [C,D] = ellip(N,Ap,As,Oc,’s’); % LP->PB transformation » Omega0=sqrt(Omegap1*Omegap2);% Geometric mean » BW = Omegap2-Omegap1; » [B,A] = lp2bp(C,D,Omega0,BW); Observe: LP→PB and LP→BS double the filter order! 21 5.2 Discrete-time frequency transformations Problem formulation Given Hlp (w) having cutoff frequency θc Find a transformation w −1 ⇓ = G(z −1 ), z , rejω , w , pejθ such that H(z) , Hlp (w)|w−1 =G(z−1 ) matches HP, BP or BS... Constraints: • Rational H(z) ⇐ G(z −1 ) rational in z −1 • |w| < 1 ⇒ |z| < 1 (to preserve stability) • |w| = 1 ⇒ |z| = 1 (to be able to map the specifications) ( |G(e−jω )| = 1 jθ −jω j∠G(ejω ) (allpass) ⇒ e = |G(e )|e ⇔ −θ = ∠G(e−jω ) General solution It has been found that the most general allpass function satisfying the above conditions is w −1 = G(z −1 N Y z −1 − αk∗ )=± , 1 − αk z −1 k=1 with |αk | < 1 ∀k By properly choosing the values of N and αk , we obtain a variety of mapping (see the following table for the most useful ones) Common discrete-time mappings LP(θc ) → LP(ωc ), HP(ωc ), BP(ω1 < ω2 ), BS(ω1 < ω2 ) Filter type Transform. Design parameters Lowpass w−1 → Highpass w−1 → Bandpass −α1 z +α2 w−1 → − αz2 z−2 −α1 z −1 +1 Bandstop w−1 → z −1 −α 1−αz −1 α= z −1 +α 1+αz −1 cos[(θc +ωc )/2] α = − cos[(θ c −ωc )/2] cos[(ω2 +ω1 )/2] α = cos[(ω2 −ω1 )/2] K = cot[(ω2 − ω1 )/2] tan(θc /2) α1 = 2αK/(K + 1) α2 = (K − 1)/(K + 1) cos[(ω2 +ω1 )/2] α = cos[(ω 2 −ω1 )/2] K = tan[(ω2 − ω1 )/2] tan(θc /2) α1 = 2α/(K + 1) α2 = (1 − K)/(1 + K) −2 −1 z −2 −α1 z −1 +α2 α2 z −2 −α1 z −1 +1 22 sin[(θc −ωc )/2] sin[(θc +ωc )/2] LP(θc ) → HP(ωc ) As an example consider the LP → HP transformation: w−1 = G(z −1 ) = − e−jω + α z −1 + α −jθ ⇔ e = − 1 + αz −1 1 + αe−jω ω = tan−1 − −1 θ = tan − ⇓ (1 − α2 ) sin θ 2α + (1 + α2 ) cos θ (1 − α2 ) sin ω 2α + (1 + α2 ) cos ω In particular, the last equation allows the mapping of the desired band edge frequencies The above nonlinear relationship between θ and ω (see picture) causes a frequency warping for α 6= 0. ω π α = = 8 0. α 0.8π 5 0. 0.6π α = 0 α 0.4π = − α − 5 0. = 0.2π 8 0. θ 0.2π 0.4π 0.6π 0.8π π As in the bilinear transformation case, this warping does not distort piecewise-constant frequency response characteristics. Design procedure for LP → HP Specifications: ωs < ωp , Ap < As 1. θp = 1rad 2. anchor the cutoff f. to the passband edge f.: θc = θp and ωc = ωp cos[(θc +ωc )/2] 3. α = − cos[(θ c −ωc )/2] h i (1−α2 ) sin ωs 4. θs = tan−1 − 2α+(1+α (prewarping of ωs ) 2 ) cos ω s 5. Design a LP (Hlp (z)) with specifications: θs , θp , Ap , As −1 z +α 6. Map z −1 ← − 1+αz −1 to get the HP H(z) Example (LP → HP) Specifications: ωs = 0.45π, ωp = 0.6π, Ap = 1dB, As = 15dB » os = 0.45*pi; op = 0.6*pi; Ap = 1; As = 15; 1-2 » tp = 1; tc=tp; oc=op; 3 » al = -(cos((tc+oc)/2))/(cos((tc-oc)/2)); 23 4 » ts=atan(-(1-alˆ2)*sin(os)/ (2*al+(1+alˆ2)*cos(os))); 5 % LP design (Chebyshev I) » [N,omegac]=cheb1ord(tp/pi,ts/pi,Ap,As); » [Blp,Alp] = cheby1(N,Ap,omegac); −1 z +α 6 Given the prototype Hlp (z), it is easy to proceed analytically with the mapping z −1 = − 1+αz −1 ... 6 Design examples of IIR filters using M ATLAB • The procedure shown in the last example can be easily extended to all other transformations of interest. • In M ATLAB these procedures are incorporated in familiar digital filter design functions. • These functionalities are obtained again by pairs like (ellipord,ellip) properly overloaded, the former for order determination the latter for filter design The function prototypes for all kinds (Butterworth, Chebyshev’s,...) present the same formalism, therefore we can refer to only one type (Elliptic) for details. Order determination (Elliptic) Syntax: [N,omegac]=ellipord(omegap,omegas,Ap,As) The frequencies, expressed in units of π, have the following meaning: Lowpass omegap < omegas Highpass omegap > omegas Bandpass omegap=[opL,opH] and omegas=[osL,osH], such that osL < opL < opH < osH Bandstop omegap=[opL,opH] and omegas=[osL,osH], such that opL < osL < osH < opH omegac provides the appropriate cutoff frequency (or frequencies) in each case. Filter design (Elliptic) Syntax: Lowpass [B,A]=ellip(N,Ap,As,omegac), with omegac= ωp /π Highpass [B,A]=ellip(N,Ap,As,omegac,’high’), with omegac= ωp /π Bandpass [B,A]=ellip(N,Ap,As,omegac), with omegac= [ωpL /π, ωpH /π] Bandstop [B,A]=ellip(N,Ap,As,omegac,’stop’), with omegac= [ωpL /π, ωpH /π] Example (Butterworth highpass filter design) [butterHP.m] Specifications: ωs = 0.5π, ωp = 0.7π, Ap = 1dB, As = 40dB 24 » omegap = 0.7; Ap = 1; omegas = 0.5; As = 40; » [N,omegac] = buttord(omegap,omegas,Ap,As) N = 8 omegac = 0.6739 » [B,A] = butter(N,omegac,’high’); % Plots... Example (Chebyshev I bandpass filter design) [cheb1BP.m] Specifications: Lower stopband: Passband: Upper stopband: [0, 0.25π] [0.3π, 0.5π] [0.6π, π] Attenuation: Ripple: Attenuation: 40dB 0.5dB 50dB » omegap = [0.3 0.5]; omegas = [0.25 0.6]; » Ap = 0.5; As = 50; » [N,omegac] = cheb1ord(omegap,omegas,Ap,As); N N = 7 » [B,A] = cheby1(N,Ap,omegac); % Plots... Example (Chebyshev II bandstop filter design) [cheb2BS.m] Specifications: Lower passband: Stopband: Upper passband: [0, 0.2π] [0.3π, 0.6π] [0.75π, π] Ripple: Attenuation: Ripple: 0.5dB 40dB 0.5dB » omegap = [0.2 0.75]; omegas = [0.3 0.6]; » Ap = 0.5; As = 40; » [N,omegac] = cheb2ord(omegap,omegas,Ap,As); N N = 5 » [B,A] = cheby2(N,As,omegac,’stop’); % Plots... 25 Example (Elliptic bandpass filter design) [ellipBP.m] Specifications: Lower stopband: Passband: Upper stopband: [0, 0.2π] [0.3π, 0.6π] [0.7π, π] Attenuation: Ripple: Attenuation: 60dB 0.1dB 60dB » omegap = [0.3 0.6]; omegas = [0.2 0.7]; » Ap = 0.1; As = 60; » [N,omegac] = ellipord(omegap,omegas,Ap,As); N N = 6 » [B,A] = ellip(N,Ap,As,omegac); % Plots... 26