Design Digital Filter Specifications • Usually, either the magnitude and/or the • Objective - Determination of a realizable phase (delay) response is specified for the transfer function G(z) approximating a design of digital filter for most applications given frequency response specification is an important step in the development of a • In some situations, the unit sample response digital filter or the step response may be specified • If an IIR filter is desired, G(z) should be a • In most practical applications, the problem stable real rational function of interest is the development of a realizable approximation to a given magnitude • Digital filter design is the process of response specification deriving the transfer function G(z)

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Specifications Digital Filter Specifications • We discuss in this course only the • As the impulse response corresponding to magnitude approximation problem each of these ideal filters is noncausal and • There are four basic types of ideal filters of infinite length, these filters are not with magnitude responses as shown below realizable j j HLP(e ) HHP(e ) • In practice, the magnitude response 1 1 specifications of a digital filter in the

  passband and in the stopband are given with  –     c 0 c – c 0  c j j HBS(e ) HBP (e ) some acceptable tolerances

–1 1 • In addition, a transition band is specified between the passband and stopband     –    – c2 c1 c1  c2  – c2 – c1  c1 c2  Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Specifications Digital Filter Specifications ω • For example, the magnitude response G(e j ) • As indicated in the figure, in the passband, ≤ ω ≤ ω of a digital lowpass filter may be given as defined by 0 p , we require that jω ≅ ±δ indicated below G(e ) 1 with an error p , i.e., −δ ≤ jω ≤ +δ ω ≤ ω 1 p G(e ) 1 p , p

ω ≤ ω ≤ π •In the stopband, defined by s , we jω ≅ δ require that G ( e ) 0 with an error s , i.e., jω ≤ δ ω ≤ ω ≤ π G(e ) s , s

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

1 Digital Filter Specifications Digital Filter Specifications ω • p - passband edge frequency ω • s - stopband edge frequency • Specifications are often given in terms of δ loss function ( ω ) = − 20 log G ( e j ω ) in dB • p - peak ripple value in the passband G 10 δ • Peak passband ripple • s - peak ripple value in the stopband jω α = − −δ • Since G ( e ) is a periodic function of ω, p 20log10 (1 p ) dB ω and G ( e j ) of a real-coefficient digital • Minimum stopband attenuation filter is an even function of ω α = − δ s 20log 10 ( s ) dB • As a result, filter specifications are given only for the frequency range 0 ≤ ω ≤ π

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Specifications Digital Filter Specifications • Magnitude specifications may alternately be • Here, the maximum value of the magnitude given in a normalized form as indicated in the passband is assumed to be unity below

• 1 / 1 + ε 2 - Maximum passband deviation, given by the minimum value of the magnitude in the passband

• 1 - Maximum stopband magnitude A

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Specifications Digital Filter Specifications • In practice, passband edge frequency Fp and stopband edge frequency F s are • For the normalized specification, maximum specified in Hz value of the gain function or the minimum • For digital filter design, normalized value of the loss function is 0 dB bandedge frequencies need to be computed • Maximum passband attenuation - from specifications in Hz using α = ( + ε 2 ) Ω 2πF max 20 log 10 1 dB ω = p = p = π p 2 FpT • For δ << 1 , it can be shown that FT FT p Ω π α ≅ −20log (1− 2δ ) ω = s = 2 Fs = π max 10 p dB s 2 FsT FT FT

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

2 Selection of Filter Type Digital Filter Specifications • The transfer function H(z) meeting the frequency response specifications should be = = •Example - Let F p 7 kHz, F s 3 kHz, and a causal transfer function = FT 25 kHz • For IIR digital filter design, the IIR transfer − •Then function is a real rational function of z 1 : 3 2π (7×10 ) − − − ω = = 0.56π p + p z 1 + p z 2 +L+ p z M p × 3 H (z) = 0 1 2 M 25 10 + −1 + −2 +L+ −N d0 d1z d2 z dN z π × 3 ω = 2 (3 10 ) = π • H(z) must be a stable transfer function and s 3 0.24 25×10 must be of lowest order N for reduced computational complexity Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Selection of Filter Type Selection of Filter Type • For FIR digital filter design, the FIR • Advantages in using an FIR filter - transfer function is a polynomial in z−1 with real coefficients: (1) Can be designed with exact , N (2) Filter structure always stable with H (z) = å h[n]z−n n=0 quantized coefficients • Disadvantages in using an FIR filter - Order • For reduced computational complexity, of an FIR filter, in most cases, is degree N of H(z) must be as small as possible considerably higher than the order of an equivalent IIR filter meeting the same • If a linear phase is desired, the filter coefficients must satisfy the constraint: specifications, and FIR filter has thus higher computational complexity h[n] = ± h[N − n] Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Design: Digital Filter Design: Basic Approaches Basic Approaches • This approach has been widely used for the • Most common approach to IIR filter design - following reasons: (1) Convert the digital filter specifications (1) Analog approximation techniques are into an analog prototype lowpass filter highly advanced specifications (2) They usually yield closed-form • (2) Determine the analog lowpass filter solutions transfer function H (s) (3) Extensive tables are available for a analog filter design • (3) Transform H ( s ) into the desired digital a (4) Many applications require digital transfer function G(z) simulation of analog systems

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

3 Digital Filter Design: Digital Filter Design: Basic Approaches Basic Approaches • An analog transfer function to be denoted as • Basic idea behind the conversion of H a (s) into G ( z ) is to apply a mapping from the P (s) H (s) = a s-domain to the z-domain so that essential a D (s) a properties of the analog frequency response where the subscript “a” specifically are preserved indicates the analog domain • Thus mapping function should be such that • A digital transfer function derived from H a (s) – Imaginary ( j Ω ) axis in the s-plane be shall be denoted as mapped onto the unit circle of the z-plane P(z) G(z) = – A stable analog transfer function be mapped D(z) into a stable digital transfer function Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Digital Filter Design: Digital Filter Design: Basic Approaches Basic Approaches • FIR filter design is based on a direct Basic Approaches approximation of the specified magnitude • Three commonly used approaches to FIR response, with the often added requirement filter design - that the phase be linear (1) Windowed Fourier series approach • The design of an FIR filter of order N may be accomplished by finding either the (2) Frequency sampling approach length-(N+1) impulse response samples{h[n]} (3) Computer-based optimization methods or the (N+1) samples of its frequency ω response H (e j )

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Digital Filter Design: Bilinear Bilinear Transformation Transformation Method • Bilinear transformation - • Digital filter design consists of 3 steps: æ −1 ö (1) Develop the specifications of H ( s ) by 2 ç1− z ÷ a s = ç − ÷ T è1+ z 1 ø applying the inverse bilinear transformation to specifications of G(z) • Above transformation maps a single point in the s-plane to a unique point in the (2) Design Ha (s) z-plane and vice-versa (3) Determine G(z) by applying bilinear transformation to Ha (s) • Relation between G(z) and H a ( s ) is then given by • As a result, the parameter T has no effect on = æ − −1 ö G(z) Ha (s) = 2ç1 z ÷ G(z) and T = 2 is chosen for convenience s ç − ÷ T è1+z 1 ø Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

4 Bilinear Transformation • Inverse bilinear transformation for T = 2 is Bilinear Transformation + z = 1 s 1− s • Mapping of s-plane into the z-plane = σ + Ω •Fors o j o 2 2 (1+σ ) + jΩ 2 (1+σ ) + Ω z = o o Þ z = o o −σ − Ω −σ 2 + Ω2 (1 o ) j o (1 o ) o σ = → = • Thus, o 0 z 1 σ < → < o 0 z 1 σ > → > o 0 z 1 Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Bilinear Transformation Bilinear Transformation = jω • For z e with T = 2 we have • Mapping is highly nonlinear − − jω jΩ = 1 e = j tan(ω / 2) • Complete negative imaginary axis in the s- + − jω 1 e plane from Ω = −∞ toΩ = 0 is mapped into or Ω = tan(ω / 2) the lower half of the unit circle in the z-plane from z = − 1 to z =1 • Complete positive imaginary axis in the s- plane from Ω = 0 to Ω = ∞ is mapped into the upper half of the unit circle in the z-plane from z = 1 toz = −1

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Bilinear Transformation Bilinear Transformation • Nonlinear mapping introduces a distortion • Steps in the design of a digital filter - ω ω in the frequency axis called frequency (1) Prewarp ( p , s ) to find their analog Ω Ω warping equivalents ( p , s ) • Effect of warping shown below (2) Design the analog filter Ha (s) (3) Design the digital filter G(z) by applying bilinear transformation to Ha (s) • Transformation can be used only to design digital filters with prescribed magnitude response with piecewise constant values • Transformation does not preserve phase response of analog filter

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

5 IIR Digital Filter Design Using Bilinear Transformation IIR Digital Filter Design Using •Example - Consider Bilinear Transformation Ω = c • Rearranging terms we get Ha (s) s + Ω −1 c = 1−α ⋅ 1+ z G(z) − • Applying bilinear transformation to the above 2 1−α z 1 we get the transfer function of a first-order where digital lowpass − Ω − ω 1 c 1 tan( c / 2) − α = = Ω (1+ z 1) 1+ Ω 1+ tan(ω / 2) = −1 = c c c G(z) Ha (s) =1−z −1 −1 s − − + Ω + 1+z 1 (1 z ) c (1 z )

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Digital Filter Design Using IIR Digital Filter Design Using Bilinear Transformation Bilinear Transformation •Example - Consider the second-order analog •Then G(z) = H (s) − −1 a s=1 z notch transfer function 1+z−1 − − 2 2 + Ω2 − − Ω2 1 + + Ω2 2 s + Ω = (1 o ) 2(1 o ) z (1 o ) z = o − − Ha (s) 2 2 + Ω2 + − − Ω2 1 + + Ω2 − 2 s + B s + Ω (1 o B) 2(1 o ) z (1 o B) z o − − 1+α 1− 2β z 1 + z 2 for which H ( jΩ ) = 0 = ⋅ a o − β +α −1 +α −2 = ∞ = 2 1 2 (1 )z z Ha ( j0) Ha ( j ) 1 Ω 1+ Ω2 − B 1− tan(B / 2) • o is called the notch frequency where α = o = w Ω = Ω = 1+ Ω2 + B 1+ tan(B / 2) • If H a ( j 2 ) H a ( j 1 ) 1 / 2 then o w = Ω − Ω 1− Ω2 B 2 1 is the 3-dB notch bandwidth β = o = cosω + Ω2 o Copyright © 2001, S. K. Mitra 1 o Copyright © 2001, S. K. Mitra

IIR Digital Filter Design Using IIR Digital Filter Design Using Bilinear Transformation Bilinear Transformation •Example - Design a 2nd-order digital notch • Thus filter operating at a sampling rate of 400 Hz 0.954965 −1.1226287 z−1 + 0.954965z−2 with a notch frequency at 60 Hz, 3-dB notch G(z) = − −1 + −2 bandwidth of 6 Hz 1 1.1226287 z 0.90993z ω = π = π • The gain and phase responses are shown below • Thus o 2 (60/ 400) 0.3 2 = π = π 0 Bw 2 (6/ 400) 0.03 1 -10 • From the above values we get 0 -20 α = Gain, dB 0.90993 -30 radians Phase, -1

β = -40 -2 0.587785 0 50 100 150 200 0 50 100 150 200 Frequency, Hz Frequency, Hz Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

6 IIR Lowpass Digital Filter Design IIR Lowpass Digital Filter Design Using Bilinear Transformation Using Bilinear Transformation •Example - Design a lowpass Butterworth • Prewarping we get digital filter with ω = 0 . 25 π , ω = 0 . 55 π , Ω = ω = π = p s p tan( p / 2) tan(0.25 / 2) 0.4142136 α ≤ α ≥ p 0 . 5 dB, and s 15 dB Ω = ω = π = s tan( s / 2) tan(0.55 / 2) 1.1708496 • Thus • The inverse transition ratio is ε 2 = 0.1220185 A2 = 31.622777 1 Ω = s = 2.8266809 j0 Ω • If G ( e ) = 1 this implies k p j0.25π ≥ − • The inverse discrimination ratio is 20log10 G(e ) 0.5 2 π 1 A −1 20log G(e j0.55 ) ≤ −15 = =15.841979 10 ε k1 Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Lowpass Digital Filter Design IIR Lowpass Digital Filter Design Using Bilinear Transformation Using Bilinear Transformation •We then get log10 (1/ k1) Ω = Ω = • Thus N = = 2.6586997 c 1.419915( p) 0.588148 log (1/ k) 10 •3rd-order lowpass Butterworth transfer Ω = • We choose N = 3 function for c 1 is Ω 1 • To determine c we use H (s) = an (s +1)(s2 + s +1) 2 1 1 H ( jΩ ) = = Ω = a p + Ω Ω 2N + ε 2 • Denormalizing to get c 0 . 588148 we 1 ( p / c ) 1 arrive at æ s ö H (s) = H ç ÷ a an è 0.588148ø Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Lowpass Digital Filter Design Design of IIR Highpass, Bandpass, Using Bilinear Transformation and Bandstop Digital Filters • Applying bilinear transformation to Ha (s) • First Approach - we get the desired digital transfer function (1) Prewarp digital frequency specifications G(z) = H (s) − −1 a s=1 z 1+z −1 of desired digital filter G D ( z ) to arrive at • Magnitude and gain responses of G(z) shown frequency specifications of analog filter H D (s) below: of same type 1 0 (2) Convert frequency specifications of H (s) 0.8 -10 D 0.6 into that of prototype analog lowpass filter -20 0.4 Gain, dB Magnitude H LP (s) -30 0.2 (3) Design analog lowpass filter H (s) 0 -40 LP 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 ω/π Copyrightω/π © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

7 Design of IIR Highpass, Bandpass, Design of IIR Highpass, Bandpass, and Bandstop Digital Filters and Bandstop Digital Filters

(4) Convert H L P ( s ) into H D ( s ) using • Second Approach - inverse frequency transformation used in (1) Prewarp digital frequency specifications Step 2 of desired digital filter G D ( z ) to arrive at (5) Design desired digital filter G D ( z ) by frequency specifications of analog filter H D (s) applying bilinear transformation to H LP (s) of same type

(2) Convert frequency specifications of H D (s) into that of prototype analog lowpass filter H LP (s)

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

Design of IIR Highpass, Bandpass, IIR Highpass Digital Filter Design and Bandstop Digital Filters • Design of a Type 1 Chebyshev IIR digital highpass filter (3) Design analog lowpass filter H (s) = = LP • Specifications: F p 700 Hz, F s 500 Hz, (4) Convert H ( s ) into an IIR digital α = α = = LP p 1 dB, s 32 dB, F T 2 kHz transfer function G ( z ) using bilinear LP • Normalized angular bandedge frequencies transformation 2πF π × (5) Transform G ( z ) into the desired ω = p = 2 700 = π LP p 0.7 digital transfer function GD (z) FT 2000 π π × • We illustrate the first approach ω = 2 Fs = 2 500 = π s 0.5 FT 2000

Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Highpass Digital Filter Design IIR Highpass Digital Filter Design • Prewarping these frequencies we get • MATLAB code fragments used for the design Ωˆ = ω = p tan( p / 2) 1.9626105 [N, Wn] = cheb1ord(1, 1.9626105, 1, 32, ’s’) Ωˆ = ω = s tan( s / 2) 1.0 [B, A] = cheby1(N, 1, Wn, ’s’); • For the prototype analog lowpass filter choose [BT, AT] = lp2hp(B, A, 1.9626105); Ω = p 1 [num, den] = bilinear(BT, AT, 0.5); Ω Ωˆ p p Ω = 0 • Using Ω = − we get s 1.962105 Ωˆ -10 Ω = • Analog lowpass filter specifications: p 1 , -20 Ω = α = α = Gain, dB -30 s 1 . 926105 , p 1 dB, s 32 dB -40 -50 0 0.2 0.4 0.6 0.8 1 ω/π Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

8 IIR Bandpass Digital Filter Design IIR Bandpass Digital Filter Design • Design of a Butterworth IIR digital bandpass = Ωˆ − Ωˆ = • Width of passband Bw p2 p1 0.777771 filter Ωˆ 2 = Ωˆ Ωˆ = ω = π ω = π o p1 p2 1.393733 • Specifications: p 1 0 . 45 , p 2 0 . 65 , Ωˆ Ωˆ =1.23010325 ≠ Ωˆ 2 ω = π ω = π α =1 α = 40 s1 s2 o s 1 0 . 3 ,s2 0.75 , p dB, s dB Ωˆ Ωˆ • We therefore modify s 1 so that s 1 and • Prewarping we get Ωˆ s 2 exhibit geometric symmetry with Ωˆ = ω = Ωˆ 2 p1 tan( p1 / 2) 0.8540807 respect to o Ωˆ = ω = •We setΩˆ = 0.5773031 p2 tan( p2 / 2) 1.6318517 s1 Ωˆ = tan(ω / 2) = 0.5095254 • For the prototype analog lowpass filter we s1 s1 Ω = Ωˆ = ω = choose p 1 s2 tan( s2 / 2) 2.41421356 Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Bandpass Digital Filter Design IIR Bandpass Digital Filter Design Ωˆ 2 − Ωˆ 2 • MATLAB code fragments used for the design • Using Ω = − Ω o we get p Ωˆ [N, Wn] = buttord(1, 2.3617627, 1, 40, ’s’) Bw [B, A] = butter(N, Wn, ’s’); 1.393733 − 0.3332788 Ω = = 2.3617627 [BT, AT] = lp2bp(B, A, 1.1805647, 0.777771); s × 0.5773031 0.777771 [num, den] = bilinear(BT, AT, 0.5);

• Specifications of prototype analog 0 Butterworth lowpass filter: -10 -20 Ω = 1 , Ω = 2 . 3617627 , α = 1 dB, p s p Gain, dB -30 α = -40 s 40 dB -50 0 0.2 0.4 0.6 0.8 1 ω/π Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

IIR Bandstop Digital Filter Design IIR Bandstop Digital Filter Design • Design of an elliptic IIR digital bandstop filter Ωˆ Ωˆ Ωˆ • We therefore modify p 1 so that p 1 and p2 ω = π ω = π • Specifications: s 1 0 . 45 , s 2 0 . 65 , exhibit geometric symmetry with respect to ω = π ω = π α = α = Ωˆ 2 p 1 0 . 3 ,p2 0.75 , p 1 dB, s 40 dB o Ωˆ = • Prewarping we get •We set p1 0.577303 Ωˆ = Ωˆ = s1 0.8540806, s2 1.6318517, • For the prototype analog lowpass filter we Ω = Ωˆ = 0.5095254, Ωˆ = 2.4142136 choose s 1 p1 p2 Ωˆ B = Ωˆ − Ωˆ = • Using Ω = Ω w we get • Width of stopband Bw s2 s1 0.777771 s Ωˆ 2 − Ωˆ 2 o Ωˆ 2 = Ωˆ Ωˆ =1.393733 × o s2 s1 Ω = 0.5095254 0.777771 = Ω Ω = ≠ Ω2 p 0.4234126 ˆ p2 ˆ p1 1.230103 ˆ o 1.393733− 0.3332787 Copyright © 2001, S. K. Mitra Copyright © 2001, S. K. Mitra

9 IIR Bandstop Digital Filter Design • MATLAB code fragments used for the design [N, Wn] = ellipord(0.4234126, 1, 1, 40, ’s’); [B, A] = ellip(N, 1, 40, Wn, ’s’); [BT, AT] = lp2bs(B, A, 1.1805647, 0.777771); [num, den] = bilinear(BT, AT, 0.5);

0 -10 -20

Gain, dB -30 -40

-50 0 0.2 0.4 0.6 0.8 1 ω/π Copyright © 2001, S. K. Mitra

10