CHAPTER 7 filter design techniques 7.0 introduction 7.1design of discrete-time IIR filters from continuous-time filters 7.1.1 filter design by impulse invariance 7.1.2 filter design by bilinear transform 7.1.3 not low pass filter design and other method 7.2 design of FIR filters by windowing. 7.3 summary 7.0 introduction ideal frequency selective filter band-stop filter:notch filter;quality factor of band-pass filter=pass-band width/center frequency Figure 7.1 impulse response of ideal low-pass filter,noncausal,unrealizable hd (n) 1 c 2 H d (e c j )e jn d sin( c n) n , n ...... Specifications for filter design :given in frequency domain phase:linear? magnitude:given by a tolerance scheme analog or digital,absolute or relative absolute specification magnitude response of equivalent analog system passband tolerance 3dB cutoff frequency 1/ Figure 7.2 2 stopband tolerance passband cutoff frequency monotonous descent cc stopband cutoff frequency relative specifications:maximum magnitude in passband is normalized to 1, viz. 0dB p 20 * log10(1 p) 0 maximum attenuation in passband s 20 * log10 s 0 minimum attenuation in stopband 3dB cutoff frequency: | H (e j c ) | 1 / 20 log10 | H (e 2 j c ) | 3dB magnitude response of equivalent analog system: H eff j H (e ) | T | | T ( j) 0 | | T digital specification, finally: p pT , s sT Specifications for bandpass and bandstop filters: up and down passband cutoff frequency, up and down stopband cutoff frequency Design steps: (1)decide specifications according to application (2)decide type according to specification:generally , if the phase is required , choose FIR. (3)approach specifications using causal and stable discretetime system: viz. design H(z0) or h[n],nonuniform (4)choose a software or hardware realization structure, take effects of limited word length into consideration H(z) or h[n] 7.1 design of discrete-time IIR filters from continuous-time filters ala log y low pass digital A/ D frequency transform ala log y high low pass pass digital A/ D high pass attention:original analog filter and equivalent analog filter is different, their frequency response is not always the same 7.1.0 introduction of analogy filter 7.1.1filter design by impulse invariance 7.1.2 filter design by bilinear transform 7.1.0 introduction of analog filter comparison: 1.wave 2.the same order, increase performance 3.increase design complexity (A)(C)small aliasing in the impulse invariance design technique BW design formula: specificationsystem function magnitude frequency function: | H c ( j) |2 1 ( / c ) N log p take the specifications into system function and get the results from equation group: c 1 p OR s k c e N 1 H c (s) get system function: 10 10 1 s s 10 10 1 k 0 1 s sk 2 1 s 10 2 k 1 1 j 2 N 2 1 1 s 10 p 10 2N 1 10 H c ( s ) H c ( s ) |s j p c 1 confirm the poles of system function: (in the left half plane) 2N 2N 1 , k 0 N 1 c N N 1 (s s k 0 k ) EXAMPLE design a low pass analogy filter: p 2 1000rad / s, s 2 2000rad / s, p 1dB, s 15dB [N,Wc]=buttord(2000*pi,4000*pi,1,15, 's') [Bs,As]=butter(N,Wc, 's') [H,W]=freqs(Bs,As); plot(W/2/pi,20*(log10(abs(H)))) axis([1000,2000,-16,0]) grid on OUTPUT: N= 4 Wc = 8.1932e+003 Bs = 1.0e+015 * 0 0 0 0 4.5063 As = 1.0e+015 * 0.0000 0.0000 0.0000 0.0014 4.5063 b0 b1s b2 s b3 s b4 s 2 H c ( s) 3 4 a0 a1s a2 s a3 s a4 s 2 3 4 Or: [N,Wc]=buttord(2000*pi,4000*pi,1,15, 's') [z,p,k]=butter(N,Wc, 's' ) Output: z = Empty matrix: 0-by-1 p = 1.0e+003 * -7.5695 + 3.1354i -7.5695 - 3.1354i -3.1354 + 7.5695i -3.1354 - 7.5695i k = 4.5063e+015 H c ( s) k ( s p0 )( s p1 )( s p2 )( s p3 ) EXAMPLE design a low pass cheby analogy filter: p 2 1000rad / s, s 2 2000rad / s, p 1dB, s 15dB [N,Wc]=cheb1ord(2000*pi,4000*pi,1,15, 's') [Bs,As]=cheby1(N,1,Wc, 's') [H,W]=freqs(Bs,As); plot(W/2/pi,20*(log10(abs(H)))) axis([0,4000,-30,0]) grid on EXAMPLE design a low pass cheby analogy filter: p 2 1000rad / s, s 2 2000rad / s, p 1dB, s 15dB [N,Wc]=cheb2ord(2000*pi,4000*pi,1,15, 's') [Bs,As]=cheby2(N,15,Wc, 's') [H,W]=freqs(Bs,As); plot(W/2/pi,20*(log10(abs(H)))) axis([0,4000,-30,0]) grid on EXAMPLE design a high pass analogy filter: p 2 2000rad / s, s 2 1000rad / s, p 1dB, s 15dB [N,Wc]=buttord(4000*pi,2000*pi,1,15, 's') [Bs,As]=butter(N,Wc, 'high', 's') [H,W]=freqs(Bs,As); plot(W/2/pi,20*(log10(abs(H)))) axis([0,4000,-16,0]) grid on transformation from analog filter to digital filter: H(s)H(z),viz. mapping from S plane to Z plane, must satisfy: the same frequency response(map imaginary axis to the unit circle); causality and stability is preserved(map poles from left half plane to the inside circle)。 S plane Z plane imaginary axis the unit circle H a (s ) H ( z) poles in left half plane inside the unit circle 7.1.1 filter design by impulse invariance according to : h[ n] Td hc [ nTd ] h[ n ]T h [ nT ] d c d H c ( s ) hc (t ) h[ n] H ( z ) conversion formula: N 1 H c ( s) Ak ss k 0 k N 1 H ( z ) H c (s) 1 s sk Td 1 e sk Td z 1 Td Ak 1 e k 0 s k Td z 1 Relationship between poles(causal and stable): relation between frequencies: Td , , S plane Z plane jΩ 3π/Td π/Td -π/Td -3π/Td sk e s k Td relation between frequency response: when aliasing is small, the frequency response is the same. 2 j H (e ) H k c( j jk ) Td Td strongpoint:linear frequency mapping; shortcoming:aliasing in frequency response。 restriction in application:can not used in high-pass and bandstop filter Design steps: (1)[equivalent analog ' T , ' T p S specificat ion p S ,digital p p / Td , S S / Td digital specificat ion prototype specificat ion ] analog specificat ion (2)design Hc (s) (3) H ( z ) H c (s) 1 s sk Td 1 e sk Td z 1 about Td: independent of T; do not influence aliasing; arbitrary value,generally, take 1(attention(1)and(3)have the same value). EXAMPLE design a BW digital lowpasss filter , need : p 0.2 , s 0.4 , p 1dB, s 12dB, wp=0.2*pi; ws=0.4*pi ap=1; as=12 Td=1; Wp=wp/Td; [N,Wc]=buttord(Wp,Ws, ap , as, 's') [Bs,As]=butter(N,Wc, 's') [Bz,Az]=impinvar(Bs,As,1/Td) [H,W]=freqs(Bs,As); plot(W/pi,20*(log10(abs(H))), 'r*') hold on [H,w]=freqz(Bz,Az); plot(w/pi,20*(log10(abs(H)))) axis([0.2,0.4,-20,0]) grid Ws=ws/Td 7.1.2 filter design by bilinear transform design thought: S 平面 jΩ S1 平面 z 平面 jΩ1 Im(z) +π/T σ Re(z) σ1 -π/T Ω=(-∞,∞) ω=(-π,π) Ω1=(-π/T,π/T) design formula: H ( z ) H c ( s) | 1 2 1 z s Td 1 z 1 left half s-plane inside the unit circle in the z-plane(causality and stability are preserved); imaginary axis of the s-plane the unit circle in z-plane (the same frequency response), one-by-one mapping relation between frequencies: Td 2 arctan 2 tan Td 2 2 relation between frequency response: H (e j ) H c ( j) tan Td 2 2 prewarp : p 2 tan p Td 2 s 2 tan s Td 2 strongpoint:no aliasing; shortcoming:nonlinear。 restriction in application: can not used in differentiator. design steps: (1) ' T , ' T p S [equivalent analog system specificat ion p S digital specificat ion ] p 2 tan( p / 2 ), S 2 tan( s / 2 ) digital specificat ion specificat ions of prototype analog filter Td Td (2) Hc (s) (3) H ( z ) H c ( s) | 1 2 1 z s Td 1 z 1 about Td: independent of T; arbitrary value,generally, take 1(attention(1)and(3)have the same value). EXAMPLE design a lowpass filter , need p 0.2613 , s 0.4018 , p 0.75 dB, s 20 dB, wp=0.2613*pi; ws=0.4018*pi; ap=0.75; as=20; Td=1; Ws=2/Td*tan(ws/2); Wp=2/Td*tan(wp/2) [N,Wc]=buttord(Wp,Ws,ap,as,’s’) [Bs,As]=butter(N,Wc, ‘s’) [Bz,Az]=bilinear(Bs,As,1/Td) [H,W]=freqs(Bs,As); plot(W/pi,20*(log10(abs(H))),’Rx‘) hold on [H,w]=freqz(Bz,Az); plot(w/pi,20*(log10(abs(H)))) ylabel(‘虚线:模拟滤波器幅度[dB] 实线:数字滤波器幅度[dB]’) xlabel(‘虚线:模拟角频率[*π弧度/秒] 实线:数字角频率[*π弧度]’) axis([0.25,0.5,-20,-0.45]) grid OR wp=0.2613*pi; ws=0.4018*pi;ap=0.75; [N,wc]=buttord(wp/pi,ws/pi,ap,as) [Bz,Az]=butter(N,wc) [H,w]=freqz(Bz,Az); plot(w/pi,20*(log10(abs(H)))) as=20 EXAMPLE design a highpass filter , need p 0.6 , s 0.5 , p 1dB, s 12dB, [N,Wc]=buttord(0.6,0.5,ap,as) [Bz,Az]=butter(N,Wc, 'high') [H,w]=freqz(Bz,Az); plot(w/pi,20*(log10(abs(H)))) grid EXAMPLE 0 0.5rad , pl 0.45rad , pu 0.55rad : 3dB sl 0.4rad , su 0.6rad : 10dB [N,wc]=buttord([0.45 0.55],[0.4 0.6],3,10) %双线性变换法 [B,A]=butter(N,wc) [H,w]=freqz(B,A); plot(w/pi,20*(log10(abs(H)))) ylabel(‘20log|H(ejω)| [dB]’) xlabel(‘数字角频率[*π弧度]’) axis([0.4,0.6,-10,0]); grid on Output: N= 2 wc = 0.4410 B = 0.0271 A = 1.0000 0.5590 0 -0.0541 0 1.4838 0 0.0271 0 0.5920 7.1.3 IIR summary 1.design steps (1)equivalent analog system specificat ion p ' p T , S 'S T p p / Td , S S / Td p 2 Td tan( p / 2), S 2 Td digital specificat ion specificat ions of prototype analog filter tan( s / 2) (2)H a ( s) 1 (3) H a ( s ) s sk s 2 Td 1 e sk Td 1 z 1 z 1 H(z ) Td 1 z 1 2. impulse invariance: frequency axis is linear many-to-one mapping , aliasing in frequency response, inapplicable to high-pass filter. bilinear transformation: frequency axis is one-to-one mapping with aberrance, no aliasing in frequency response, inapplicable to differentiator 7.1.4 frequency conversion Frequency conversion in analog domain: lowpass lowpass :s s / c lowpass highpass :s c / s lowpass bandpass :s ( s c1 c 2 ) /[ s ( c 2 c1 )] 2 lowpass bandstop :s [ s ( c 2 c1 )] /( s c1 c 2 ) 2 c 2 : up cutoff frequency, c1:down cutoff frequency Frequency conversion in digital domain: lowpass lowpass :z 1 lowpass highpass :z 1 z 1 1 1 z z 1 1 1 z z lowpass bandpass :z 1 2 k 1 k 1 z lowpass bandstop :z 1 2 k 1 k 1 2k k 1 z 2 2k k 1 z 2 z 1 2k k 1 z 1 2k k 1 k 1 k 1 z 1 1 k 1 k 1 z 1 1 , k is dependent of filter cutoff frequency before and after conversion 7.2 design of FIR filters by windowing 7.2.1 design ideas 7.2.2 properties of commonly used windows 7.2.3 effect to frequency response 7.2.4 design step 7.2.1 design ideas hd (n) IFT ( H d (e j H( e d )) j ) 2 M 1 w[ n ] h[n] hd [n] wM [n] (d )W (e j ) ( f ) H (e j sin[ ( M 1) / 2] sin( / 2) ) 1 2 H d (e j ) W (e j ) Gibbs phenomenon: frequency response oscillate at wc. transition width of filer’smainlobe width of window spectrum length and shape of window’s passband-stopband error of filter’ssidelobe amplitude of window spectrum window’s shape The smaller mainlobe width, the narrower transition width of filter’s; The smaller sidelobe amplitude of window spectrum, the smaller relative error of filter’s. M increases mainlobe width of window spectrum minishes filter oscillate more quickly, transition width minishes, relative amplitude of oscillation is preserved. In order to improve relative amplitude of oscillation, we need to change the shape of window’s. 7.2.2 properties of commonly used windows 0nM 1, (1)rec tan gular : w[n] 0, other 2n M , 0n M 2 2n M ( 2)bartlett (triangular ) : w[ n] 2 , nM M 2 other 0, 2n 0.5 0.5 cos 0nM (3) hanning : w[ n] M , other 0 2n 0.54 0.46 cos 0nM ( 4) ham min g : w[ n] M , other 0 2n 4n 0.42 0.5 cos 0.08 cos 0nM (5)blackman : w[ n] M M , other 0 A general designation: Blackman window family, except triangular window Figure 7.21 1 I (1 [(n M ) / M ]2 ) 2 0 2 2 (6)kaiser : w[n] I0 ( ) 0 Figure 7.24(a) 0nM other (a)-(e) attenuation of sidelobe increases, width of mainlobe increases. M=20 As B increases, attenuation of sidelobe increases, width of mainlobe increases. B=6 As N increases: attenuation of sidelobe is preserved width of mainlobe decreases. Figure 7.24(b)(c) Transition width is a little less than mainlobe width Table 7.1 7.2.3 effect to frequency response attenuation of window spectrum’s sidelobe attenuation of filter’s stopband width of window spectrum’s mainlobetransition width of filter’s check the table for Blackman window; formulas of Kaiser window: 0.1102( A 8.7) 0.584( A 21) 0.4 0.07886( A 21) 0 A 50 21 A 50 A 21 A8 2.285M A:attenuation of stopband, Δω:transition width (5.50) 7.2.4 design step 1. Write the ideal impulse response: c ( p s ) / 2 jM j j ( ) H d (e ) H d ( )e e 2 0 1 j jn hd [n] H 2 d (e )e pass band stop band d 2.Comfirm the shape of window’s based on attenuation of stopband: min( p , s ) A 20 log 10 (1)check the table for Blackman window (2)calculation for Kaiser window 0.1102( A 8.7) 0.584( A 21) 0.4 0.07886( A 21) 0 A 50 21 A 50 A 21 3.Comfirm length of window’s based on transition width(M is even): | s p | (1) check the table for Blackman window: compute the length of window’s based on width of mainlobe: (2) calculation for Kaiser window : M M D 2 A8 2.285 4.Cut the ideal impulse response h[n] hd [n] w[n] j 5. validate H (e ),correct c , M , (Kaiser•) , , A We can think that the 4 specifications is c transformed into: The same with IIR, maybe the specification is equivalent analog one. Blackman family Example 1 design a FIR high pass filter , need : p 0.7 , s 0.54 , p 3dB, s 40dB (1) c ( p s ) / 2 0.62 hd [n] 1 2 H d (e sin[ (n M / 2)] (n M / 2) j )e jn d sin[ 0.62 (n M / 2)] 0.62 ( n M / 2) (2) min( , ) min( 1 10 p s p / 20 ,10 , n ...... s / 20 ) 0.01, A 40dB hamming (3) | | 8 / 2 (0.7 0.54) , M 25 26 p s M (4) sin[ (n 13)] sin[0.62 (n 13)] 2n h[n] 0 . 54 0 . 46 cos( ) R27 [n] (n 13) 25 (n 13) (5)validate the frequency response in MATLAB h=fir1(26,0.62, 'high',hamming(27)) H=fft(h,512); plot([0:511]/256,20*log10(abs(H))) axis([0.5,0.7,-50,0]); grid on (6)correct h=fir1(24,0.665, 'high',hamming(25)) H=fft(h,512); plot([0:511]/256,20*log10(abs(H))) axis([0.5,0.7,-80,0]); grid on h= 0.0001 -0.0538 -0.0538 0.0004 0.0023 0.0014 0.0358 -0.0040 -0.0040 0.1288 0.0009 0.0023 0.0004 0.0104 -0.0170 0.0009 0.0358 -0.2727 0.3357 -0.2727 0.1288 0.0014 -0.0170 0.0104 0.0001 Example 2 Kaiser family design a FIR high pass filter , need : p 0.7 , s 0.54 , p 3dB, s 40dB Solution1: (1) c ( p s ) / 2 0.62 hd [ n ] 1 H 2 d (e j )e jn d (2) min( , ) min( 1 10 p s p sin[ (n M / 2)] (n M / 2) / 20 ,10 s / 20 sin[ 0.62 (n M / 2)] 0.62 (n M / 2) ) 0.01, A 40dB 0.5842(40 21) 0.4 0.07886(40 21) 3.3953 (3) M 40 8 2.285(0.7 0.54 ) 27.86 28 (4) h[n] sin[ (n 14)] sin[ 0.62 (n 14)] w[n] (n 14) , n ...... (5)validate and correct in MATLAB h=fir1(18,0.662, 'high', kaiser (19,3.2953)); H=fft(h,512); k=0:511; subplot(1,2,1); plot(k/256,20*log10(abs(H))); grid on; subplot(2,2,2); plot(k/256,20*log10(abs(H))); axis([0.5,0.55,-50,-0]); grid on subplot(2,2,4); plot(k/256,20*log10(abs(H))); axis([0.65,0.75,-5,0]); grid on Example 3 plot the response to signal x[n] 10 cos(0.1 ) 3sin(0.8 ) R20[n] h=fir1(18,0.5, 'high',kaiser(19,6)); n=[0:100]; x=10*cos(0.1*pi*n)+3*sin(0.8*pi*n) ; subplot(2,1,1); plot(n,x) y=filter(h,1,x) ; subplot(2,1,2); plot(n,y) 7.2.5 FIR summary w[n] shape length W (e j ) H (e j ) attenuation of sidelobe attenuation of stopband (the first row in the table)( the third row in the table) width of mainlobe transition width (the second row) (the second row /2) 7.3 brief introduction of other filter design techniques using matlab 1. 2. 3. 4. IIR: minimum mean square error in frequency domain: invfreqz( ) FIR: frequency sampling :fir2( ) FIR: minimum mean square error :firls( ) FIR: Parks-McCellan/Remez arithmetic: remez( ) 7.4 summary FIR digital filter IIR digital filter finite-length IR infinite-length IR no non-zero poles, stable non-zero poles, stable? realization: convolution /recursion recursion realize linear phase easily can not realize linear phase in deed stable higher order maybe instable because of rounding lower order because of recursion FFT no fast arithmetic summary 7.1 7.2 7.3 design of IIR(continuous-time filter) 7.1.1 impulse invariance 7.1.2 bilinear transform design of FIR(windowing) 7.2.1 design ideas 7.2.2 properties of commonly used windows 7.2.3 effect to frequency response 7.2.4 design step comparison between IIR and FIR requirements: understand the principles of impulse invariance and bilinear transform and their mapping characteristic, implication; understand design ideas of windowing; design various filters using MATLAB. difficulties: relationship among prototype analog filter, digital filter and equivalent analog filter; effects of shape and length of window’s to system characteristic; why impulse invariance and bilinear transform can not be used in high-pass filter design。 exercise and experiment 7.16 7.18 7.22(a)(b) the second experiment 50 52 56 57 59 7.23