Chapter 7 Finite Impulse Response(FIR) Filter Design 1. Features of FIR filter Characteristic of FIR filter N y ( n) h( k ) x ( n k ) k 0 N H ( z ) h( k ) z k k 0 – FIR filter is always stable – FIR filter can have an exactly linear phase response – FIR filter are very simple to implement. Nonrecursive FIR filters suffer less from the effect of finite wordlength than IIR filters 2/74 2. Linear phase response Phase response of FIR filter H (e jT N ) h(k )e j kT (1) k 0 = H (e jT ) e j ( ) where ( ) arg H (e jT ) (2) – Phase delay p and group delay g p ( ) g d ( ) d 3/74 – Condition of linear phase response ( ) (3) ( ) (4) Where and is constant Constant group delay and phase delay response 4/74 • If a filter satisfies the condition given in equation (3) – From equation (1) and (2) ( ) N = tan 1 h(n) sin nT n 0 N h(n) cos nT n 0 thus N tan = h(n) sin nT n 0 N h(n) cos nT n 0 5/74 N h(n) cos nT sin sin nT cos 0 n 0 N h(n) sin( nT ) 0 n 0 h(n) h( N n 1), 0n N NT / 2 – It is represented in Fig 7.1 (a),(b) 6/74 • When the condition given in equation (4) only – The filter will have a constant group delay only – It is represented in Fig 7.1 (c),(d) h( n) h( N n) NT / 2 /2 7/74 Center of symmetry Fig. 7-1. 8/74 Table 7.1 A summary of the key point about the four types of linear phase FIR filters 9/74 Example 7-1 (1) Symmetric impulse response for linear phase response. No phase distortion h(n) h( N n) or h(n) h( N n) (2) h(n) h( N n), 0 n N , N 10 h(0) h(10) h(1) h(9) h(2) h(8) h(3) h(7) h(4) h(6) 10/74 • Frequency response H ( ) H ( ) H (e jT ) 10 = h(k )e jkT k 0 =h(0) h(1)e jT h(2)e j 2T h(3)e j 3T h(4)e j 4T h(5)e j 5T +h(6)e j 6T h(7)e j 7T h(8)e j 8T h(9)e j 9T h(10)e j10T =e j 5T [h(0)e j 5T h(1)e j 4T h(2)e j 3T h(3)e j 2T h(4)e jT h(5) +h(6)e jT h(7)e j 2T h(8)e j 3T h(9)e j 4T h(10)e j 5T ] H ( )=e j 5T [h(0)(e j 5T e j 5T ) h(1)(e j 4T e j 4T ) h(2)(e j 3T e j 3T ) h(3)(e j 2T e j 2T ) h(4)(e jT e jT ) h(5)] e j 5T [2h(0) cos(5T ) 2h(1) cos(4T ) 2h(2) cos(3T ) 2h(3) cos(2T ) 2h(4) cos(T ) h(5)] 5 H ( )= a(k ) cos(kT )e j 5T H ( ) e j ( ) k 0 5 where H ( ) = a(k ) cos(kT ) k 0 ( ) 5T 11/74 (3) N 9 h(0) h(9) h(1) h(8) h(2) h(7) h(3) h(6) h(4) h(5) H ( )=e j 9T /2 [h(0)(e j 9T e j 9T ) h(1)(e j 7T e j 7T ) h(2)(e j 5T e j 3T ) h(3)(e j 3T e j 3T ) h(4)(e jT e jT )] e j 9T /2 [2h(0) cos(9T / 2) 2h(1) cos(7T / 2) 2h(2) cos(5T / 2) 2h(3) cos(3T / 2) 2h(4) cos(T / 2)] = H ( ) e j ( ) 5 where H ( )= b(k ) cos[ ( k 1/ 2)T ] k 1 ( ) (9 / 2)T N 1 b ( k ) 2h( k ), k 1, 2, 2 , N 1 2 12/74 3. Zero distribution of FIR filters Transfer function for FIR filter N H ( z ) h( k ) z k k 0 N H ( z ) h( N k ) z k k 0 0 = h( k ) z k z N k N =z N H ( z 1 ) 13/74 Four types of linear phase FIR filters – H ( z ) have zero at z z0 z0 re j z0 1 r 1e j h(n) is real and z0 is imaginary z0* re j ( z0* ) 1 r 1e j (1 re j z 1 )(1 re j z 1 )(1 r 1e j z 1 )(1 r 1e j z 1 ) 14/74 – If zero on unit circle r 1, 1/ r 1 z0 e j z0 1 e j z0* (1 e j z 1 )(1 e j z 1 ) – If zero not exist on the unit circle (1 rz 1 )(1 r 1 z 1 ) – If zeros on z 1 (1 z 1 ) 15/74 Necessary zero Necessary zero Necessary zero Necessary zero Fig. 7-2. 16/74 4. FIR filter specifications Filter specifications p peak passband deviation (or ripples) r stopband deviation p passband edge frequency r stopband edge frequency s sampling frequency 17/74 ILPF Satisfies spec’s Fig. 7-3. 18/74 Characterization of FIR filter N y ( n) h( k ) x ( n k ) k 0 N H ( z ) h( k ) z k k 0 – Most commonly methods for obtaining h(k ) • Window, optimal and frequency sampling methods 19/74 5. Window method FIR filter – Frequency response of filter H I ( ) – Corresponding impulse response hI (n) 1 hI (n) 2 H I ( )e j n d – Ideal lowpass response 1 1 c j n j n hI (n) 1 e d e d 2 2 c 2 f c sin( nc ) , n 0, - n nc = 2 fc , n0 20/74 Fig. 7-4. 21/74 Truncation to FIR h(n) hI (n)w(n) H(e j ) 1 2 1 2 "windowing" H I (e j ) W(e j ) H I (e j )W(e j ( ) )d – Rectangular Window 1 , n 0,1,..., N w(n) 0 , elsewhere 22/74 Fig. 7-5. 23/74 Fig. 7-6. 24/74 Fig. 7-7. 25/74 Table 7.2 summary of ideal impulse responses for standard frequency selective filters hI (n) hI (n) hI (n) f c , f1 and f 2 are the normalized passband or stopband edge frequencies; N is the length of filter 26/74 Common window function types – Hamming window 0.54 0.46cos 2 n / N , 0 n N w n 0 , elsewhere F 3.32 / N where N is filter length and F is normalized transition width 27/74 – Characteristics of common window functions Fig. 7-8. 28/74 Table 7.3 summary of important features of common window functions 29/74 – Kaiser window 2 2 n N I0 1 N wn , 0n N I0 0 , elsewhere where I 0 ( x) is the zero-order modified Bessel function of the first kind ( x / 2) k I 0 ( x) 1 k ! k 1 L 2 where typically L 25 30/74 • Kaiser Formulas – for LPF design A 20log10 ( ) min( p , s ) if A 21dB 0, 0.5842( A 21)0.4 0.07886( A 21), if 21dB A 50dB 0.1102( A 8.7) if A 50dB N A 7.95 14.36F 31/74 Example 7-2 – Obtain coefficients of FIR lowpass using hamming window Passband cutoff frequency f p : 1.5kHz Transition width f : 0.5kHz Stopband attenuation 50dB Sampling frequency f s : 8kHz • Lowpass filter sin nc 2 f , n0 c hI n nc 2 fc , n0 F f / f s 0.5 / 8 0.0625 N 3.32 / F 3.32 / 0.0625 53.12 N 54 32/74 • Using Hamming window 0 n 54 h(n) hI (n) w(n) w(n) 0.54 0.46 cos(2 n / 54) 0 n 54 fc' f p f / 2 (1.5 0.25) 1.75[kHz ] fc fc' / f s 1.75 / 8 0.21875 N 2 f sin ( n ) c c 2 , N hI (n) (n )c 2 2 fc , n N , 0 n N 2 n N 2 33/74 2 0.21875 sin(27 2 0.21875) 27 2 0.21875 0.00655 n 0 : hI (0) w(0) 0.54 0.46 cos(0) 0.08 h(0) hI (0) w(0) 0.00052398 2 0.21875 sin( 26 2 0.21875) 26 2 0.21875 0.011311 n 1 : hI (1) w(1) 0.54 0.46 cos(2 / 54) 0.08311 h(1) hI (1) w(1) 0.00094054 34/74 2 0.21875 sin( 25 2 0.21875) 25 2 0.21875 0.00248397 n 2 : hI (2) w(2) 0.54 0.46 cos(2 2 / 54) 0.092399 h(2) hI (2) w(2) 0.000229516 2 0.21875 sin(1 2 0.21875) 1 2 0.21875 0.312936 n 26 : hI (26) 35/74 w(26) 0.54 0.46cos(2 26 / 54) 0.9968896 h(26) hI (26) w(26) 0.3112226 n 27 : hI (27) 2 f c 2 0.21875 0.4375 w(27) 0.54 0.46 cos(2 27 / 54) 1 h(27) hI (27) w(27) 0.4375 36/74 Fig. 7-9. 37/74 Example 7-3 – Obtain coefficients using Kaiser or Blackman window Stopband attenuation : 40dB passband attenuation : 0.01dB f : 500 Hz Transition region Sampling frequency f s : 10kHz Passband cutoff frequency f p : 1200 Hz 20 log(1 p ) 0.01dB, 20log( r ) 40dB, p 0.00115 r 0.01 r p 0.00115 38/74 • Using Kaiser window N A 7.95 58.8 7.95 70.82 14.36F 14.36(500 /10000) N 71 0.1102(58.8 8.7) 5.52 f c f c' / f s 1, 450 /10, 000 0.145 N 2 f c sin n c 2 hI (n) , 0n N N n c 2 39/74 h(n) hI (n) w(n) n 0 : hI (0) 2 0.145 sin(35.5 2 0.145) 35.5 2 0.145 0.00717 2 2 n N I0 1 N I (0) w(0) 0 0.023 I0 ( ) I 0 (5.52) h(0) hI (0) w(0) 0.000164935 40/74 n 1: hI (1) 2 0.145 sin(34.5 2 0.145) 34.5 2 0.145 0.0001449 2 69 I 0 5.52 1 71 I (1.3) w(1) 0 0.0337975 I 0 (5.52) I 0 (5.52) h(1) h(1) hI (1)w(1) 0.000004897 41/74 n 2 : hI (2) 2 0.145 sin(34.5 2 0.145) 33.5 2 0.145 0.007415484 2 69 I 0 5.52 1 71 I (1.8266) w(2) 0 0.04657999 I 0 (5.52) I 0 (5.52) h(2) h(2) hI (2) w(2) 0.000345413 42/74 n 35 : hI (35) 2 0.145 sin(0.5 2 0.145) 0.5 2 0.145 0.280073974 2 1 I 0 5.52 1 71 I (5.51945) w(35) 0 0.999503146 I 0 (5.52) I 0 (5.52) h(35) h(35) hI (35)w(35) 0.279934818 43/74 Fig. 7-10. 44/74 Summary of window method 1. Specify the ‘ideal’ or desired frequency response of filter, H I ( ) 2. Obtain the impulse response, hI (n), of the desired filter by evaluating the inverse Fourier transform 3. Select a window function that satisfies the passband or attenuation specifications and then determine the number of filter coefficients 4. Obtain values of w( n ) for the chosen window function and the values of the actual FIR coefficients, h(n), by multiplying hI (n) by w( n ) h(n) hI (n) w(n) 45/74 Advantages and disadvantages – Simplicity – Lack of flexibility – The passband and stopband edge frequencies cannot be precisely specified – For a given window(except the Kaiser), the maximum ripple amplitude in filter response is fixed regardless of how large we make N 46/74 6. The optimal method Basic concepts – Equiripple passband and stopband E ( ) W ( )[ H I ( ) H ()] Weighted Approx. error Weighting function Ideal desired response Practical response min[max E() ] • For linear phase lowpass filters – m+1 or m+2 extrema(minima and maxima) where m=(N+1)/2 (for type1 filters) or m =N/2 (for type2 filters) 47/74 Practical response Ideal response Fig. 7-11. 48/74 Fig. 7-12. 49/74 – Optimal method involves the following steps • Use the Remez exchange algorithm to find the optimum set of extremal frequencies • Determine the frequency response using the extremal frequencies • Obtain the impulse response coefficients 50/74 Optimal FIR filer design N H ( z ) h( k ) z k k 0 where h( n) h( n) N /2 N /2 k 1 k 0 H ( ) h(0) 2h(k ) cos kT a(k ) cos kT where a (0) h(0) and a(k ) 2h(k ), k 1, 2, ,N /2 Let f / 2 f s T / 2 1 , H1 f 0 , 1 W f k 1 0 f fp f r f 0.5 , 0 f fp , f r f 0.5 This weighting function permits different peak error in the two band 51/74 H ( f ) H (e j 2 f N /2 ) a (k ) cos k 2 f k 0 E ( f ) W ( f )[ H ( f ) H I ( f )] where f are 0, f p and f r ,0.5 min[max E( f ) ] Find a(k ) 52/74 – Alternation theorem Let F 0, f p f r , 0.5 If E ( f ) has equiripple inside bands F and more than m+2 extremal point then H ( f ) HI ( f ) E ( fi ) E ( fi 1 ) e, f0 f1 fl where e i 0,1, , l 1 (l m 1) max f 0, f p & f r ,0.5 E( f ) 53/74 • From equation (7-33) and (7-34) W ( fi ) H ( fi ) H I ( fi ) (1)i e, i 0,1, 2, , m 1 • Equation (7-35) is substituted equation (7-32) m a(k ) cos 2 kf k 0 i H I ( fi ) (1)i e , W ( fi ) i 0,1, 2, , m 1 • Matrix form cos 4 f 0 1 cos 2 f 0 1 cos 2 f cos 4 f1 1 1 cos 2 f m cos 4 f m 1 cos 2 f m 1 cos 4 f m 1 cos 2 mf 0 cos 2 mf1 cos 2 mf m cos 2 mf m 1 a (0) H I ( f 0 ) 1/ W ( f1 ) a (1) H I ( f1 ) ( 1) m / W ( f m ) a (m) H I ( f m ) ( 1) m ! / W ( f m 1 ) e H I ( f m 1 ) 1/ W ( f 0 ) 54/74 – Summary Step 1. Select filter length as 2m+1 Step 2. Select m+2 f i point in F Step 3. Calculate a(k ) and e using equation (7) Step 4. Calculate E ( f ) using equation (5). If E( f ) e in some of f , go to step 5, otherwise go to step 6 Step 5. Determine m local minma or maxma points Step 6. Calculate h(0) a(0), h(k ) a(k ) / 2 when k 1, 2, where H ( z ) N h( k ) z ,m k k 0 55/74 – Example 7-4 • Specification of desired filter – Ideal low pass filter – Filter length : 3 – pT 1[rad], rT 1.2[rad] – k 2 • Normalized frequency f0 0.5 / 2 , f1 1/ 2 , f 2 1.2 / 2 56/74 • From H I ( f0 ) H I ( f1 ) 1, H I ( f 2 ) 0, W ( f0 ) W ( f1 ) 1/ 2 and W ( f 2 ) 1 1 0.8776 2 a(0) 1 1 0.5403 2 a(1) 1 1 0.3624 1 e 0 a(0) 0.645, a(1) 2.32, e 0.196 H ( f ) 0.645 2.32 cos 2 f : not the optimal filter • Cutoff frequency f 0 1 2 f1 1.2 2 f 2 0.5 H I ( f 0) 1, H I ( f1) H I ( f 2) 0, W ( f 0) 0.5, and W ( f1) W ( f 2) 1 57/74 1 0.5403 2 a(0) 1 1 0.3624 1 a(1) 0 1 1 1 e 0 a(0) 0.144, a(1) 0.45, e 0.306 H ( f ) 0.144 0.45cos 2 f : has the minimum max E( f ) (N=3) 58/74 Fig. 7-13. 59/74 Optimization using MATLAB – Park-McClellan – Remez b remez(N,F, M ) b remez(N,F, M, WT ) where N is the filter order (N+1 is the filter length) F is the normalized frequency of border of pass band M is the magnitude of frequency response WT is the weight between ripples 60/74 – Example 7-5 • Specification of desired filter – Band pass region : 0 – 1000Hz – Transition region : 500Hz – Filter length : 45 – Sampling frequency : 10,000Hz • Normalized frequency of border of passband F [0, 0.2, 0.3, 1] • Magnitude of frequency response M [1 1 0 0] 61/74 Table 7-4. 62/74 Fig.7-14. 63/74 – Example 7-6 • Specification of desired filter – Band pass region : 3kHz – 4kHz – Transition region : 500Hz – Pass band ripple : 1dB – Rejection region : 25dB – Sampling frequency : 20kHz • Frequency of border of passband F [2500, 3000, 4000, 4500] M [0 1 0] 64/74 • Transform dB to normal value Ap p 10 20 1 Ap 10 where band 20 1 r 10 Ar 20 A p and A ripple value(dB) of pass band and rejection r • Filter length – Remezord (MATLAB command) 65/74 Table 7-5. 66/74 Fig. 7-15. 67/74 7. Frequency sampling method Frequency sampling filters – Taking N samples of the frequency response at intervals of kFs / N k 0,1, , N 1 – Filter coefficients h(n) 1 h( n) N N 1 j (2 / N ) nk H ( k ) e k 0 where H (k ), k 0,1, , N 1 are samples of the ideal or target frequency response 68/74 – For linear phase filters (for N even) N2 1 1 h( n) 2 H (k ) cos[2 k (n ) / N ] H (0) N k 1 where ( N 1) / 2 – For N odd • Upper limit in summation is ( N 1) / 2 69/74 Fig. 7-16. 70/74 – Example 7-7 1 N /21 (1) Show the h(n) 2 H (k ) cos[2 k (n ) / N ] H (0) N k 1 • Expanding the equation 1 h( n) N h(n) is real value N 1 H (k ) e j 2 nk / N k 0 N 1 1 N H (k ) e 1 N N 1 H (k ) e 1 N N 1 H (k ) cos[2 k (n ) / N ] j sin[2 k (n ) / N ] 1 N N 1 j 2 k / N e j 2 kn / N k 0 j 2 ( n ) k / N k 0 k 0 H (k ) cos[2 k (n ) / N ] k 0 71/74 (2) Design of FIR filter – Band pass region : 0 – 5kHz – Sampling frequency : 18kHz – Filter length : 9 Fig. 7-17. 72/74 • Samples of magnitude in frequency 1, H (k ) 0, k 0,1, 2 k 3, 4 Table 7-6. 73/74 8. Comparison of most commonly method – Window method • The easiest, but lacks flexibility especially when passband and stopband ripples are different – Frequency sampling method • Well suited to recursive implementation of FIR filters – Optimal method • Most powerful and flexible 74/74