ELEN E4810: Digital Signal Processing Topic 7: Filter types and structures 1. More filter types 2. Minimum and maximum phase 3. Filter implementation structures Dan Ellis 2013-10-30 1 1. More Filter Types We have seen the basics of filters and a range of simple examples Now look at a couple of other classes: Dan Ellis Comb filters - multiple pass/stop bands Allpass filters - only modify signal phase 2013-10-30 2 Comb Filters Replace all system delays z-1 with longer delays z-L + x[n] y[n] z-L z-L z-L z-L → System that behaves ‘the same’ at a longer timescale Dan Ellis 2013-10-30 3 Comb Filters ‘Parent’ filter impulse response h[n] becomes comb filter output as: g[n] = {h[0] 0 0 0 0 h[1] 0 0 0 0 h[2]..} L-1 zeros Thus, G (z ) = n g[n]z = h[n]z n Dan Ellis 2013-10-30 n nL ( ) =H z L 4 Comb Filters Hence frequency response: ( ) = H (e ) Ge j H(ej!) jL parent frequency response compressed & repeated L times G(ej!) Low-pass response → L copies of H(ej!) pass ! = 0, 2 π/L, 4 π/L... cut ! = π/L, 3 π/L, 5 π/L... useful to enhance Dan Ellis a harmonic series 2013-10-30 5 Allpass Filters Allpass filter has |A(ej!)|2 = K for all ! i.e. spectral energy is not changed Phase response is not zero (else trivial) phase correction special effects 5 e.g. 0 |H(ω)| Magnitude (dB) −5 −10 −15 −20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Normalized Frequency (×π rad/sample) 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Normalized Frequency (×π rad/sample) 0.8 0.9 1 θ(ω) Phase (degrees) 0 −100 −200 −300 −400 Dan Ellis 2013-10-30 6 Allpass Filters Allpass has special form of system fn: d M + d M 1z 1 + ...+ d1z ( M 1) + z M AM (z ) = ± ( M 1) 1 1+ d1z + ...+ d M 1z + d M z M = ±z M ( ) DM z 1 = DM (z ) mirror-image polynomials AM(z) has poles λ where DM(λ) = 0 → AM(z) has zeros ≥ = 1/λ = λ-1 Dan Ellis 2013-10-30 7 Allpass Filters AM (z ) = ±z DM (z ) Any (stable) DM can be used: 1 poles from 1/DM(z) 0 −1 −3 −2 −1 Phase is always decreasing: → -Mº at ! = º Dan Ellis 0 1 arg{H(z)} reciprocal zeros from DM(z-1) Im{z} ( ) DM z M 1 2 Re{z} peak group delay 0 −π −2π −3π 0 2013-10-30 0.2 0.4 0.6 0.8 ω/π 1 8 M Allpass Filters Why do mirror-img poly’s give const gain? Conj-sym system fn can be factored as: AM (z ) = ( K i z * 1 i ) i(z i ) * 1 * 1 K i i z ( i z ) = i(z i ) o * i ZP λi ej! *i e-j! + complex conjugate p/z z = ej! → z-1 = e-j! also on u.circle... Dan Ellis 2013-10-30 1 9 2. Minimum/Maximum Phase In AP filters, reciprocal roots have.. same effect on magnitude (modulo const.) different effect on phase In normal filters, can try substituting reciprocal roots reciprocal of stable pole will be unstable × reciprocals of zeros? → Variants of filters with same magnitude response, different phase Dan Ellis 2013-10-30 10 Minimum/Maximum Phase Hence: z-b H1(z) = z - a H2(z) = a |H(ej b(z - 1/b) z-a a b 3 3 2 2 1 1 0 0 reciprocal zero.. 1/b .. same mag.. )| 0.5 (H(ej )) 0 0 -0.5 - .. added phase lag 0.5 -0.5 0 Dan Ellis 0.2 0.4 0.6 0.8 / - 0 2013-10-30 0.2 0.4 0.6 0.8 / 11 Minimum/Maximum Phase For a given magnitude response All zeros inside u.circle → minimum phase All zeros outside u.c. → maximum phase (greatest phase dispersion for that order) Otherwise, mixed phase i.e. for a given magnitude response several filters & phase fns are possible; minimum phase is canonical, ‘best’ Dan Ellis 2013-10-30 12 Minimum/Maximum Phase Note: Min. phase + Allpass = Max. phase o o polezero cancl’n o o (z )(z z Dan Ellis ) x (z )(z ) = (z )(z ) * z (z )(z ) o * 1 * 1 2013-10-30 1 o * 1 13 Inverse Systems hi[n] is called the inverse of hf[n] iff hi [n] h f [n] = [n] ( ) ( ) j j H e H e =1 Z-transform: f i x[n] Hf(z) y[n] Hi(z) w[n] W (z ) = H i (z )Y (z ) = H i ( z )H f ( z ) X ( z ) = X (z ) w[n] = x [n] i.e. Hi(z) recovers x[n] from o/p of Hf(z) Dan Ellis 2013-10-30 14 Inverse Systems What is Hi(z)? H i (z)H f (z) = 1 H i (z ) = 1/ H f (z ) Hi(z) is reciprocal polynomial of Hf(z) P (z) D( z ) H f (z) = H i (z) = D( z ) P (z ) Just swap poles and Hf(z) zeros: Dan Ellis poles of fwd → zeros of bwd zeros of fwd → poles of bwd o o o 2013-10-30 Hi(z) 15 Inverse Systems When does Hi(z) exist? Causal+stable → all H (z) poles inside u.c. i → all zeros of Hf(z) must be inside u.c. → Hf(z) must be minimum phase H (z) zeros outside u.c. → unstable H (z) f i H (z) zeros on u.c. → unstable H (z) f i ( ) ( ) H i e j = 1/ H f e j = 1/0 = → only invert if min.phase, Dan Ellis 2013-10-30 lose... ! Hf(ej!) ≠ 0 16 System Identification x[n] H(z) y[n] Inverse filtering = given y and H, find x System ID = given y (and ~x), find H Just run convolution backwards? y[n] = h[k ] x [n k ] k=0 y[0] = h[0] x [0] h[0] deconvolution but: errors accumulate y[1] = h[0] x [1] + h[1] x [0] h[1]... Dan Ellis 2013-10-30 17 System Identification x[n] H?(z) y[n] + noise Better approach uses correlations; Cross-correlate input and output: rxy [] = y[] x [] = h? [] x [] x [] = h? [] rxx [] If rxx is ‘simple’, can recover h?[n]... e.g. (pseudo-) white noise: rxx [] [] h? [n] rxy [] Dan Ellis 2013-10-30 18 System Identification Can also work in frequency domain: S xy ( z ) = H ? (z ) S xx ( z ) make a const. x[n] is not observable → Sxy unavailable, but Sxx(ej!) may still be known, so: j j * j Syy (e ) = Y (e )Y (e ) = H (e ) X (e )H (e ) X (e ) = H (e ) S (e ) j j j 2 * j * j j xx Use e.g. min.phase to rebuild H(ej!)... Dan Ellis 2013-10-30 19 3. Filter Structures Many different implementations, representations of same filter Different costs, speeds, layouts, noise performance, ... Dan Ellis 2013-10-30 20 Block Diagrams Useful way to illustrate implementations Z-transform helps analysis: y[n] Y ( z ) = G1 ( z )[ X ( z ) + G2 ( z )Y ( z )] G1(z) Y (z )[1 G1 (z )G2 (z )] = G1 (z ) X (z ) G2(z) Y (z) G1 (z ) H (z) = = X (z ) 1 G1 ( z )G2 ( z ) Approach x[n] + Dan Ellis Output of summers as dummy variables Everything else is just multiplicative 2013-10-30 21 Block Diagrams More complex example: + -Æ x[n] + y[n] w1 + -± Ø ∞ z-1 W1 = X z 1W3 w2 + w3 1 " z-1 1 Y = z W3 + W1 Y + z ( + ) + z ( ) = X 1+ z 1 ( + ) + z 2 ( ) 1 2 stackable 2nd order section Dan Ellis 2013-10-30 W2 = W1 z W2 1 W3 = z W2 + W2 W1 W2 = 1+ z 1 1 z + W1 W3 = 1 1+ z ( ) 22 Delay-Free Loops Can’t have them! + u Β y Α + v y = B(v + Au) u=x+y y = B(v + A(x + y)) At time n = 0, setup inputs x and v ; need u for y, also y for u →can’t calculate 1 Algebra: 1 BA y(1 Dan Ellis BA) = Bv + BAx Bv + BAx y= 1 BA x BA 1 BA y 2013-10-30 + x + B 1 BA u B 1 BA v can simplify... 23 Equivalent Structures Modifications to block diagrams that do not change the filter e.g. Commutation H = AB = BA A ≡ B B A Factoring AB+CB = (A+C)·B x1 x1 A(z)B(z) + x2 C(z)B(z) fewer blocks Dan Ellis A(z) y + x2 B(z) C(z) less computation 2013-10-30 24 y Equivalent Structures x Transpose z-1 b3 input output y 1 2 Y = b1 X + b2 z X + b3 z X 1 1 = b1 X + z b2 X + z b3 X ( Dan Ellis b2 ) 2013-10-30 ≡ z-1 b1 + reverse paths adders nodes z-1 + b1 b2 z-1 b3 + y x 25 FIR Filter Structures Direct form “Tapped Delay Line” h0 h2 y[n] = h0 x [n] + h1 x [n 1] + ... z-1 h3 h4 y = 4 h x k=0 k [n k ] Transpose + h3 z-1 h2 z-1 + + h4 z-1 h1 z-1 h1 z-1 + x + z-1 + z-1 + x + h0 y Re-use delay line if several inputs xi for single output y ? Dan Ellis 2013-10-30 26 FIR Filter Structures Cascade factored into e.g. 2nd order sections H (z ) = h0 + h1z 1 + h2 z 2 + h3 z 3 = h0 1 0 z 1 1 1z 1 1 1* z 1 ( )( )( ) 2 2 1 1 = h0 (1 0 z )(1 2 Re{1 }z + 1 z ) h0 + z-1 ≥0 + x z-1 z-1 Dan Ellis 2013-10-30 y -2Re{≥1} |≥1|2 27 FIR Filter Structures Linear Phase: n Symmetric filters with h[n] = (-)h[N - n] z-1 z-1 b0 b1 ... + + + z-1 + y[n] = b0 ( x [n] + x [n 4 ]) +b1 ( x [n 1] + x [n 3]) +b2 x [n 2] z-1 x b2 y half as many multiplies Also Transpose form: gains first, feeding folded delay/sum line Dan Ellis 2013-10-30 28 IIR Filter Structures IIR: numerator + denominator p0 + p1z 1 + p2 z 2 + ... H (z) = 1+ d1z 1 + d2 z 2 + ... 1 = P (z) D( z ) Dan Ellis z-1 p1 p2 + FIR z-1 + p0 -d1 z-1 -d2 z-1 2013-10-30 all-pole IIR 29 IIR Filter Structures Hence, Direct form I p0 p1 z-1 p2 -d1 z-1 -d2 z-1 Commutation → Direct form II (DF2) p0 + Dan Ellis -d1 z-1 p1 -d2 z-1 p2 + z-1 + 2013-10-30 • same signal ∴ delay lines merge • “canonical” = min. memory usage 30 IIR Filter Structures Use Transpose on FIR/IIR/DF2 p1 z-1 p2 z-1 + p0 + x y + -d1 -d2 “Direct Form II Transpose” Dan Ellis 2013-10-30 31 Factored IIR Structures Real-output filters have Æ conjugate-symm roots: −Ø 1 H (z) = 1 1 1 ( + j )z 1 ( j )z ( Ø )( Can always group into 2nd order terms with real coefficients: ( )( ) H (z) = 1 1 2 2 2 1 z 1 2 z + ( + ( ) ( 1 2 2 2 )z )... real root p0 1 1z 1 1 2 2 z 1 + ( 22 + 22 )z 2 ... Dan Ellis 2013-10-30 32 ) Cascade IIR Structure + + + p0 + + x Implement as cascade of second order sections (in DFII) z-1 -∞1 Æ1 2Æ2 fwd gain factored out y + z-1 z-1 z-1 -2∞2 z-1 −(Æ22+Ø22) ∞22+±22 Second order sections (SOS): Dan Ellis modular - any order from optimized block well-behaved, real coefficients (sensitive?) 2013-10-30 33 Second-Order Sections ‘Free’ choices: Optimize numerical properties: grouping of pole pairs with zero pairs order of sections avoid very large values (overflow) avoid very small values (quantization) e.g. Matlab’s zp2sos Dan Ellis attempt to put ‘close’ roots in same section intersperse gain & attenuation? 2013-10-30 34 Second Order Sections Factorization affects intermediate values Original System (2 pair poles, zeros) Dan Ellis Factorization 1 Factorization 2 2013-10-30 35 Parallel IIR Structures Can express H(z) as sum of terms (IZT) N = (1 z 1 )F (z ) z= H (z) = consts + =11 z 1 Or, second-order terms: 0 k + 1k z 1 H (z) = 0 + k 1+ z 1 + z 2 1k 2k Suggests parallel realization... Dan Ellis 2013-10-30 36 Parallel IIR Structures ∞0 + ∞01 + -Æ11 z-1 + x ∞12 + ∞02 + -Æ22 z-1 ∞11 -Æ21 z-1 -Æ12 z-1 y Sum terms become parallel paths Poles of each SOS are from full TF System zeros arise from output sum Why do this? Dan Ellis stability/sensitivity reuse common terms 2013-10-30 37