Download as pdf
Download as pdf
You are on page 1of 34
1094 Solved Examples and MATLAB Solutions, = 143,660,734) +2.8(- 05) + 1(.57)=4.123 Thus in line with our usual notations in this book we have the following structure Note that the system is table because magnitude of all reflection coefficients is less than unity (Vk |< 1,|kj)< 11a < 0) 3.868 4123 + +. vn MATLAB programs ® % Progran to obtain coefficients of IIR direct form from Lattice Ladder form >> k= [-0.7343, 0.05036, -0.57]; >> c= [4.12, 3.669, 2.8, 1]; >> [num, den] = late2tf(k,c) num = 0.99686130000000 1 .99940705396000 2.00001545200000 1.00000000000000 den = 1.00090000900000 -0.79998454800000 0 .48996922836000 ~0..57000000000000 Example 14 Design general lowpass, highpass, bandpass and bandstop FIR filters. Solution In this method we begin with the de: determine the corresponding unit by the Fourier transform relation sired frequency response specification Ha) and sample response hg(n). Indeed, hg(n) is related to H,(a) 40S ngmen “ not where L pe hao) ~ 5 f dae dey Thus. given H,(@), we can determine’ the unit sample response /14(n) by evaluating the integral. @ For a lowpass filter with magnitude of 1 and cut off frequency @, we have Hy) -o 4 0 = —<— Solved Examples and MATLAB Sotutions Was 0, 1 ¢ ‘1 hy(n) = = Jove dey = Si0("@.) ‘ Qn n@, 1 forn=0,wehave hy= —~ f dao N= Ye for n e OR Y,IN= Ye -0, 2fesin (nw, ) = no,” 2 fe, n=0 n#0 -2SnSo For highpass filter we have Ho) 0 nae 0 ® o; Le 1 f, hgoy= 1 fy 00" ag + faye" de. la) = Jove doo 2 J” forn=0. y(n) =a, n+ 4-0.) =1-2 fein Te 4 ee] hdn)=—|<—] +=] Also, si ele I aml I” Jo, similarly for bandpass filter we have Ho) - . ec ét 1096 | Solved Examples and MATLAB Solutions -0, h(n) = at (ye dot Jovem 1 forn=0, hain) = 5 [-,, + @,, + @,- We} =2(fer—fer) -o 5 fem Te 4 | a h —| +15 Also in) = 2 a L ral in |, ne, piney , abl ew -e" +t fen -"n] mn 2 mn => hin) = = [sin (e,,) ~sin (n®,,)] n@., . n@. = Ye, sin os = 2f,, sin i Forband stop filter we have Ho) a a a a a) han) = “| le"do+ fiedos fice a A 1 forn=0, h(n) mont [-@,, ++, +, +m-@,,] =1-2(f,, -f,) nT, yn 17, a Also van 2 [ ale | [eT jn 2a| jn , 2n| jn m, fe: Lent mn 27 Solved Examples and MATLAB Solutions 1097 = a [(sin (nz) - sin (ne,,)- sin (n@,,)) =2f, sin(n@,,) - 2p. sin(n@,,) no, 2 stn) (ete) 2j 7 nO, Ideal impulse responses for LP, HP, BP and BS filters. Filter h,(n), n#0 ha(n), n= 0 Lowpass oy, Snlame) x ; no, “ . sin(n@,) Highpass <%= 7 a fe no, 1% sin(n@,,) sin(n@, ) Bandpass 2h, 0, ~2fe, 0, 2h, ~f,) in(ne, ) in( ints (“4 ) sin(no, sin(n@, ) z a Bandstop ae ne, 1-26, Example 15 Explain the concept of designing an FIR filter using a window. Solution Ho) hae a 1 " 0 " ca 2 ° Desired Fresponse ofa LP ter, Impulse response ofa LP filter Window function of length say, M = 17 esired f-1 . hin) = hain) x in) hn) = hl us 1) =hin-8) (Causal hin) for implementation) 4098 Solved Examples and MATLAB Solutions Ho) =H,(a) * Wo) Ho) = Ha) * Wo) rt" poe { | \ | | \ ale awh Effect on F-response for n(n) of M = 25 Effect on F-response for a(n) of M Effect of windowing operation and causalty. Important Frequency-Domain Characteristics of Some Window Functions Type of | Approximate Peak Transition | Stopband | Window function.co(n window | transition width | sidelobe (dB) | width (Hz) | attenuation of main lobe (normalised) | _ (dB) 1. Rectangular) 4M -13 0.9/M 21 1 2. Hanning aM -32 3.1/M 44 0.5 +05 n cos Gi 3. Hamming, 8M —43 3.3/M 33 0.54 + 0.46 2nn cos M-l 4, Blackman 120M ~ 58 3.5/M 75 0.42 +05 ( 2nn ) cos M-1 + 0.08 cos ( Example 16 Design a lowpass FIR with 1 coefficients for the following specifications. Passband frequency edge = 0.25 KHz.and sampling frequency = | KHz. Use Rectangular window, Hamming window, and Hanning window in the design. Solution Given /,= 0.25 KHz, therefore 22 X250 Ky = Hey “19002 Ho) 1 oe o t G (a) Low pass filter characteristic of example 8.2.2 Solved Examples and MATI.AB Solutions 1099, « F ass filte \, w\|s> For a lowpass filter. ho) = : and 0, —slo\sx zs! | Thus ae H(w)e!°"d@ oo J (Hele"da 2n op _ Lsin 2 nn/2 Since h(n) is symmetrical, we only need to caleulate /14(1) for 0 ye? noe ° no3. ngQd= M3315 .1062 1 sin2a hyg)= ha = 9 =0 2 20 in2.57 — 0.06369 2 25" 0.3184, 0.5, 0. 3184.0, 0. 1062, 0, 0.06369 T lS) ul 5)* Thus Ay() = 40,06369, 0 0.1062, 0. Rectangular window have Jar window we he Forrectiye Is sens mmewry property of window We have , Using SY! ( 4y- ofa) = OF 3) = 03) = OC 2) = 0Q2)= OF 1) = (1) = 010) : = =o oo 53)7 2) Gy oat ere" forwetangular window design, we muluphy alicoetficients i a hgh since) tana “ne W(0)= hh) OO) “05x 1-05 (ly AE Y= hl): th) 203184 1=03184 AQy= he 2) ehyl2) w(2)= OX 1=0 B Solutions: 44100 Solved Examples and MATES hQd)= AC B= hg) x (3) =~ 01062 x 1 =~ 0-162 have A AY hylA) (4) = 0x1 =O h(S)~ h(- $)= hy (5) eS) = 006369 * 1 = 0.06369 hin) H 0.3184/ 0.06369 /| | 0.680) | jt ~s 34 fo -1 0 1 5 0.1062 0.1062 response of function h(n) = ln).0(") therefore this system cannot > d to right shift this system by Impusle An) is illustrated in Fig, (b), note that since h(n) #0 forn <8 (7 18g in practice. In order to obtain a causal system, we nee 1 =Sunits. 063692" + 0.02"! 0.106227 + 0.02 + 0.31842 440,525 4+0:31842° + 0.027 -0.10622 + 0.02? + 0.06369 =~ Note that the length of filter is 1] whereas the order is 10. MATLAB program Solution Design of FIR filter using Rectangular window coefficients using rectangular window >> % Program to compute low pass FIR filter >> fc = 0.5; Matlab procedure requires normalizing fc by half of Fs >> N= 11; % length of filter >> hn= firl((N-1), fc, boxcar(N)) Filter coefficients are tn = Columns 1 through 5 0.06053031223727 -0.00000000000000 =0. 10088385372879 0.00000000000000 0.30265156118637 Columns 6 through 10 0.47540396061029 0.30265156118637 0.00000000000000 -0. 10088 Column 11 0.06053031223727 Hamming Window Forhamming window v Os ns (ne Wray = 0.54 0.46 608 Solved Examples and MATLAB Solutions 1101 or equivalently Man 054--0-46c0s ( 2%.) ()s ( M-\)" 2 )°"* >) Since h(n)=hg() Wam() and sn wehi therefore, we use the following have aad compdcootiien of hid) fer 55453 cal Wear Want) 0.54 + 0.46 cos ( 2) =0154+0.4605( "| S fe a tis rength of filter se Ne 2 low, this time too the / (n) so obtained is not ble, therefore we right shift the plot of h(”) 1102 Solved Examples and MATLAB Solutions >> hd = firl((N-1), fe, boxcar(N)); >> wn = hanming(N); >> hn firl((Nel), fe, wn) The coefficients are mm Columns 1 through 5 0.00506031712484 -0.00000000000000 -0.04194287943134 0.00000000000009 0.28848482630264 Columns 6 through 10 0. 49679547200772 0.28848482630264 0.00000000000000 -0.04194287943134 - 0000000000000 Colum 11 0.00506031712484 Hanning Window We have Walt) = 05 +05 e0s{ 22") (Asn) M-1 2 2 2nn 05+05c0s(2") ~SSn5° (forM=11) Wran (0) Wan (1) = Whan (- 1) = 0.9045 Wrran (2) = Whan (- 2) = 0.6544 Wan (3) = Whaq (~ 3) = 0.3755 Whan (4) = Whag (-4)= 0.0955 Wan (5)= Whan (5) =0 Since A(n) = hylnt)- Wyn (1) = 1(0)= hy(O) Wan (0) =0.5 x 1 =0.5 W(L)= h1)= Ag (1), Why (1) = 0.3184 x 0.9045 = 0.2879 (2) = h(—2) = hy(2) Wan (2) = 0x 0.6544 = 0 4(3)= A(-3)= hy (3) Way (3) = ~ 0.1062 x0-3455 =~ 0.0367 (A)= h(-4) = hy(4) Wan (4) = 0X 0.0955 =O 1(5)= h(—5)= hig(S) Wan (5) = 0.0639 x0 = 0 Solved Examples and MATLAB Solutions 1403 han Whar) Hin) = gin) x al 1 \, vs (Homa os | {| Teese A | woes | | | 1 Veoarssy A \ you” ta n 2 LLL LL soos) p |b _, -o10e2 (0.0367) (a) Plot of function h,(n) (b) Plot of function Wyan()(C) Plot of function h(n) Once again h(n) = hl) Wyan(7) is not causal and must be causalised as described in previous designs. MATLAB program Solution Design of FIR filter using Hanning window >> % Program for computing low pass FIR filter coefficients using Hanning s> fc = 0.53 % this algorithm requires normalizing fc by half of Fs >> N=1l3% Jength of filter >> hd= Firl((N-1), fe, boxcar (N)) + >> wn = hann(N)5 s> ohn = firi((t-1). fc, wn) pm = Columns 1 through 5 window 0.0 0.0 — 0.0366 0.0 0.2872 Columns 6 through 10 0.4987 0.2872 0.0 — 0.0366 0.0 Column 11 0.0 Example 7 ; fl . Design a highpass filter to meet the following specifications. Cutoff frequency = 250 Sampling frequency FS 1 kHzand Filter length =7- 2 Je Filter length of 5 has been reinforced by defining rectangul Reader must observe that h(n) = h(n). xn), and in this case with the view of obtaining a causal filter directly, unlike in the previous examp! ue ) Nu) =hyay=—1 sin( = ) =0.22519 ” 4 Fe ctangular wit pa SUA WindOW, Way (0) = Wyey(1) = Wye (2)= West 3) = Wee =! h(n) =hy(n) - eo(n) Solved Examples and MATLAB Solutions 1107 (0) =h(4) = hy(0) : Wyee(0) = 0.15923 1 = 0.15923 (1) =h(3)=hy(1) - Wye 1) = 0.22519 = 0.22519 ad (2) =hg(2) Wygee(2) = 0.25 x 1 = 0.25 Thi us causal filter has H(z) = 0.159232" + 0.225192"! +0.252? + 0.225192" + 0.159232 4 Now frequency response, H(w) =}, h(nje™*" a0 = h(0)e+ h( e+ h(2)e78+ h(3)eF?+ hime? PO (p (0) (28+ e?%) + h(1) (e+ 27) + h(2)] © [h (2) + 2h(0) cos 2@+ 2h(1) cos O] = ¢?#{0.25 + 0.31847 cos 2 «+ 0.45038 cos 0] Frequency response could be obtained directly for M odd oe SYP (M-1) 4 = M Ma =e? (Wes }+2 z menpeose[ Bi =o P® [h(2) + 2h(0) cos 2+ 2h (1) cos @] ase O>% Program for computing low pas: normalised by 10, ie fs/2 gives 0.35 sefc = 0.35; % fe = (2+7)/2=3.5, >> N= 215 >> hn= firl((N-1), fc, hanning(N)) tn = Columns 1 through 5 -0.00064381414496 -0.00127273 0.00702084138692 Columns 6 through 10 .02567621285315 -0.05348848328662 -0.01371522034307 0.11837810768514 0.27749473394416 Columns 11 through 15 0. 34952485482004 0.27749473394416 0.11837810768514 -0.01371522034307 - 0.05348848328662 Columns 16 through 20 -0.02567621285315 0.00702084138692 0.01310990957519 0.00403044705778 - 0.00127273643142 Column 21 -0,00064381414496 643142 0.00403044705778 0. 1310990957519 Example 23 Design a lowpass filter to meet the following specifications: Passband edge = 1.5 kHz uansition width = 0.5 kHz, stopband attenuation > 55 dB and F,= 10kHz Solution Given/,~ 1.5 kHz Therefore, Solved Examples and MATLAB Solutions 1114 2nx500 A= —— =0.314 so Af= 0.05, 0, = 1.256 Also, 0. to @,= to = 1.099 so Jf.= 0.175 (normalised) attenuati ion of upto 58 dB can be obtained using Blackman window. For Blackman window ape 33 ~ M Thus, length of filter m= 23 267 0.05 2f,sin(n@,) wom ho = | nt ne0 335033 ze -n=0 ForBlackman window, @(n) = 0.42+0.5008 (225) + o0bo{ sz) 335533 =I M-1 a For window operation we have A(n) = hgln): O(n) Since h(n) is symmetrical, we only need to compute h(n) for0 % o> fc = 0.175; % normalised fs/2 >> N= 67; >> hn = firl((N-1), fc, blackman(N)) in = Columns 1 through 7 0.0000 = 0.0000 0.0000 Columns 8 through 14 —0,0002 0.0006 0.0010 Columns 15 through 21 0.0034 0.0039 ~~ - 0.0009 Columns 22 through 28 0.0090 = 0.0083 - 0.0218 Columns 29 through 35 -0.0410 -0.0713 -0.0161 Columns 36 through 42 0.1269 = -0.0161 - 0.0713 Columns 43 through 49 ~ 0.0118 —-0.0218 + 0.0083 Columns 50 through 56 0.0069 -0.0009 0.0039 Columns 57 through 63 0.0002 0.0010 0.0006 Columns 64 through 67 0.0001 0.0000 — - 0.0000 Example 24 Design a lowpass Butterworth filter to meet the fo IB passband gain = 0.89 WHO) A Passband frequency edge = 30 Hz attenuation = 0.20 stopband edge = 75 Hz 0.0001 0.0002 — 0.0069 - 0.0118 0.1269 — 0.0410 0.0090 0.0034 — 0.0002 0.0000 0.0001 — 0.0015 — 0.0062 0.0184 0.2826 0.0143 0.0126 0.0000 - 0.0004 — 0.0001 — 0.0022 0.0033 0.0374 0.3500 0.0374 0.0033 — 0.0022 - 0.0001 lowing specifications. — 0.004 0.0000 0.0126 0.0143 0.2826 0.0184 — 0.0062 — 0.0015 0.0001 Solved Examples and MATLAB Solutions 11413 Soin ‘olution We have Q,,= 20x30= 188.40 rad/s (,=30Hz) Q,= 20x 15=471 rad/s (f,=75 Hz) 20 log 0.89= — 1 dB 2010g0.20— ForButerwort, 22/98020= -13:984B \HQ)y=— Ts@0y" For given specifications we have 089= - 1 7 ony Similarly 020= |] orindB, ~ 13.98=-10 og Hf } Q, 471 c 1+] —— (2!) These equations can be solved to find N and Q... ioe] log | N= ae 10°" =1 0.9834 471 lo; 47 ) 0.3979 7 188.4 irst calculate the order, N = 2.471 or N = 3 (we must choose the higher round off talue wen Now in order to find Q, substitute N = 3 in the equation containing stopband edge frequency , oy olay By" or — Q.=277.32 rad/s ato ations for butterworth filter are given by Poleloe $,= 0,077 RAMEN for(k=0,1,...N- 1) rculate poles for normalised transfer function i.e. Q. cal k= 0,12 N=3 we have , For 2 in 2 = k=0 sym cos = FJsm 3G k=l 5 = cos m+jsin t= —1 cos Mt jgin bj B fe2 $2= COS 7 Jin A 2 For N=3, total poles in S place are 2x N= 6, however we choose N poles that lie only on the ‘or N=, left hand S-plane. 1414. solved Examples and MATLAB Solutions and Q, = | we have Thus for ~ (sth ts+l) _ However Q, = 277.32, we need to denormalised This transfer function is normalised for Q.= H(s) by Q,= 277.32 rad/s. H(s)|,0 5 = =—___2«_ (Now Substitute , = 277.32 rad/s) (542, (5 42,5427) Butterworth Polynomials Denominator of H(s) N (order) Denominator of H(S) 1 s+1 2. S?+1414S+1 3. (2 +S+1I) G+) 4. (S? + 0.7668 + 1) (S? + 1.8488 + 1) 5 (S? +0.618S + 1) (S? + 1.6188 + 1)(S +1) 6. (S? + 0.5188 + 1) (S? + 1.4148 + 1) (S? + 1.9328 + 1) 7. (S? + 0.4458 + 1) (S? + 1.2475 + 1)(S? + 1.8028 + 1)(S+ 1} MATLAB program Solution % Program to calculate the Order N and Wc of a low . Wp = 2*pi*30; Pass Butterworth filter > > > > ' >> RS = 13.985 fl (N,Wc] = buttord(Wp, Ws, Rp, Rs, 's') 23 We = 277.4569 Example 25 Design a digital lowpass Buttery, the following specifications, Passband ripple < 1.25 dB Passp,, Stopband attenuation 2 15 q al edge = 200 Hz Sampling frequency = 2 kHz Stopband edge = 300 Hz orth i f . filter using Bilinear Transformation Method to meet Solved Examples and MATLAB Solutions 1115 Solution Step I. Normalise angular bandedge frequencies with respect to sampling frequency. Thus o, = 2p _ 28X20 gag aa 2000 and o,= 28S, = 207300 _ 9 gy F, 2000 From specifications, — 1.25 dB < |H(@)| $0 dB 0<@<0.20 and |H(w)|<~15 4B 03S osm 2 Step II. Now prewarp frequencies corresponding to @, to @, using Q= = tan (2) Thus and (Note that Q and ware angular and digital frequencies respectively) Step III, Use required filter approximation formula to find Nand Q, corresponding to Q,, and Q,. In this case, for Butterworth approximation we have — TN (2) Q. Thus 2 7 (ey ‘| (for Q, = 0.649) an) ‘ (for Q.= 1.01) 9 0984 _ 5.125 or 6 HQ)= 20 log 1a “oe( 10) 0192 . te) (2) : ~15=~10log|1+| <2? ForN=6, eel a, yy Thus Q,= 0.7594 1116 Solved Examples and MATLAB Solutions For N= 6 we have 2x N= 12 poles in 360° i.e. with spacing of 30° or a 6 However, we only choose poles in Left Hand S-plane i.e. 6 poles. Since Nis even, poles will occur in conjugate pairs. x kN, JONG Thus for pole location we have S,=Q, e/"”? ¢ k =0,1,2,3,4,5 For prototype transfer function 2. = 1, we have in for k=0, so= el? 12 =-0.259 + j0.965 and S$, = -0.259-j0.965 combining these we gets” + 0.518 5+ I (approx). Similarly other poles will occur in conjugate pairs (5, and S,) and (S> and S;) and can be calculated for k= 1,4 and 2, 3. Step IV. Find the required transfer function. For convenience, Table | may be used for Butterworth polynomials that specifies denominator of H(s) for Q, . 1 5 -_—_ te Thus for N'=6 we have it) (s? +05185-+1)(s? +14145+ 1)(s? + 1.9325+1) However, we need to denormalise H(s) w.rt. 2, =0.7594 (cut-off frequency of required filtes) 6 (2.) (s7 +0.5182.5 +02)(? + 1.4140, 5 +02) +(s? +1.9320,5 + a?) eee ee __. (+ 0.3935 +0.577)(s? + 1.0735 +0.577)(s? +1478 + 0.577) Thus H(s)|,_ Step V. For Bilinear transformation substitute 2(z-1 s=of2c!)_,fz-1 = (4) 2) (for T= 1) Required transfer function H(z) is given below. 0.192 @ ‘Same methodology woul . 2 Would be used for Chebyshev approximation, however, order N, and Q- Id be different. . woul "nt. Once denormalised H (s) is obtained, replace Sby 2 ) to find H)- T OT ztl Solved Examples and MATLAB Solutions 1147 MATLAB program Solution >» ‘ Program to compute N and We of LP butterworth filter > N ae Dis Ws = 0.3*pis Rp = 1.25; Rs = 15s No. a i buttord(Wp, Ws, Rp, Rs, 's') We 0.7086537346682 oon a ng Program uses methodology of normalizing transfer function with i ge frequency rather than Wc, the cut off frequency) eee Compute frequency response of an IIR digital filter Wp = 200/1000; Ms = Rp =1.255 Rs = 15; IN, We] = buttord(hp, Ws, Rp, Rs); [z, p, k] = butter(n, 200/100) ; [b,a] = butter(N, 200/100) ; zplane(b,a) title('Pole zero plot of H(Z)') [H,f] = freqz(b, a, 256, Fs); plot(f, abs(H)) title('f-response of LP digital Butterworth filter with Wp=200 and Ws=300') frequency response of LP digital fiter ip = 100 and Ws = 150 300/1000; Y¥YYYYY Ye YY ¥ Pole zero pltotH@2) po 7 1 | 08 1 06 ] 1 oa} Imaginary Part 02 0 02 4 ; Magnitude 06 | 08 a 0 A jt ° = a 700 200 300 400 600 600 700 800 900 1000 7 Real Part = 05 frequency Example 26 Design 4 digital lowpass specifications. filter using Butterworth approximation to meet following of 512 Hz. 4418 Solved Examples and MATLAB Solutions The prewarped frequencies corresponding to/,, = | 20 Hzand f,= 170 Hzare 2 Q,= 2 tan( Se bt Fi Solution 2 o, a,= 2 tan {2}. and 2 n(%) Forbilinear transformation s= 2(2—7]. T(t! Reader is advised to use 2, = tan { 2 | and Q, = tan (% | and s= { 2=+] because the oF 2 zl 2 - ‘. , 2 cancels out at numerator and denominator during course of calculations of order factor of filter and also H(2). Thus for F,= 512 Hz, 0,* 22x) =0.46875 A = 2 9 5st00n 312 6 Q,= tan (see) =0.9063 2 and Q,= tan (= B)a1ns8 Now for Butterworth characteristic we have oy ~16=~10log] 1+] “HF | > N=287=3 Thus, the normalized 3rd order filter is given by HM) = —~—_— O° Beery Now denormalising H1(s) by the required prewarped cut-off frequency Sp = 0.9063 we have a (ata) * —*_)ai (aa 0.9063 0.9063 0.9063 - 0.7444 (s? + 0.90635 + 0.8213) (s + 0.9063) z-1) , } +-as003( 25 z+ zt Als) = Now — H()=H(s) 0.7444 oot} +0506

You might also like