Presentation is loading. Please wait.

Presentation is loading. Please wait.

17 Nov'09Comp30291: Section 41 University of Manchester School of Computer Science Comp30291 Digital Media Processing 2009-10 Section 4 ‘Design of FIR.

Similar presentations


Presentation on theme: "17 Nov'09Comp30291: Section 41 University of Manchester School of Computer Science Comp30291 Digital Media Processing 2009-10 Section 4 ‘Design of FIR."— Presentation transcript:

1 17 Nov'09Comp30291: Section 41 University of Manchester School of Computer Science Comp30291 Digital Media Processing 2009-10 Section 4 ‘Design of FIR digital filters’

2 17 Nov'09Comp30291: Section 42 4.1.Introduction FIR digital filter of order M implemented by programming the signal-flow-graph shown below. Its difference equation is: y[n] = a 0 x[n] + a 1 x[n-1] + a 2 x[n-2] +... + a M x[n-M] z -1 x[n] y[n] a0a0 a1a1... a M-1 aMaM

3 17 Nov'09Comp30291: Section 43 10th order FIR digital filter z -1 ++++++++++ x[n] y[n] a0a0 a1a1 a2a2 a 10 a9a9 a8a8 a3a3 a4a4 a5a5 a7a7 a6a6

4 17 Nov'09Comp30291: Section 44 Its impulse-response is {h[n]} = {..., 0,..., a 0, a 1, a 2,..., a M, 0,...} Taking DTFT of impulse-response gives the frequency-response: Background, objective & methodology Objective is to choose a 0, a 1,..., a M such that H(e j  ) is close to some target frequency-response H’(e j  ) ). Inverse DTFT of H’(e j  ) gives required impulse-response : Methodology is to use inverse DTFT to get an impulse- response {h[n]} & then realise some approximation to it.

5 17 Nov'09Comp30291: Section 45 Observations about the inverse-DTFT It is an integral It has complex numbers Range of integration is from -  to  so it involves negative frequencies.

6 17 Nov'09Comp30291: Section 46 Reminder about integration ab t (Have +ve &  ve areas) x(t)

7 17 Nov'09Comp30291: Section 47 Reminder about complex numbers Let x = a + j.b, j =  [-1] Modulus: |x| =  [a 2 + b 2 ] Arg(x)=tan -1 (b/a) + { .sign(b) if a < 0} = tan2(b,a) = angle(a + j.b) : range -  to  Polar: x = Re j  where R = |x| &  = Arg(x) De Moivre: e j  = cos(  ) + j.sin(  ) e -j  = cos(  ) - j.sin(  )  e j  + e -j  = 2cos(  ) & e j  - e -j  = 2 j.sin(  ) Complex conjugate: x* = a - j.b = Re -j  That’s about it!

8 17 Nov'09Comp30291: Section 48 What about the negative frequencies? Examine the DTFT formula for H(e j  ). If h[n] real then h[n]e j  is complex-conj of h[n]e -j . Adding up terms gives H(e -j  ) as complex conj of H(e j  ). G(  ) = G(-  ) since G(  ) = |H(e j  )| & G(  ) = H(e -j  )| (Mod of a complex no. is Mod of its complex conj.)  (-  ) =  (  ) since  (  ) = Arg(H(e j  ) ) &  (-  ) = Arg(H(e -j  )) (Arg of a complex no. is  Arg of its complex conj).

9 17 Nov'09Comp30291: Section 49 Gain & phase response graphs with  ve frequencies G(  )   -- 0  -- -()-()  As G(-  ) = G(  ), gain-response is always symmetric about  =0 As  (  ) =  (  ), phase-response is always anti-symmetric about  = 0

10 17 Nov'09Comp30291: Section 410 Assume we require lowpass filter whose gain-response approximates the ideal 'brick-wall' gain-response: If we take phase-response  (  ) = 0 for all , the required target frequency-response is: 4.2. Design of an FIR low-pass filter  G()G()  /3  /3 0  -- 1

11 17 Nov'09Comp30291: Section 411 By inverse DTFT, required impulse-response is:

12 17 Nov'09Comp30291: Section 412 To complete the calculation:

13 17 Nov'09Comp30291: Section 413 Graph of sinc(x) against x x 12 -2-33 1 sinc(x) -4 Main ‘lobe’ ‘Zero-crossings’ at x =  1,  2,  3, etc. ‘Ripples’

14 17 Nov'09Comp30291: Section 414 Plotting this ‘sinc’ graph in MATLAB clear all; close all; clc; x = [-10: 0.1 : 10]; y = sinc(x); figure(1); plot(x,y); grid on; title('sinc function'); xlabel( 'x'); ylabel('sinc(x)'); legend('sinc(x)', 'Location','Best'); axis([-10 10 -0.3 1]);

15 17 Nov'09Comp30291: Section 415 Graph of sinc(x) against x ‘Main lobe’ ‘Ripples’ ‘Zero-crossings’ at x =  1,  2,  3, etc

16 17 Nov'09Comp30291: Section 416 Impulse-response for this ideal (brick-wall) lowpass filter

17 17 Nov'09Comp30291: Section 417 Plotting this ‘stem’ graph in MATLAB n=[-20:20]; h = (1/3)*sinc(n/3); figure(1); stem(n,h,'.:'); grid on; title('h[n] = (1/3) sinc(n/3)'); xlabel( 'n'); ylabel('h[n]'); legend('(1/3)sinc(n/3)', 'Location','Best'); axis([-20 20 -0.1 0.35]); for n=-20:20, disp(sprintf('n:%2d, h[n]: %6.3f',n,h(n+21))); end;

18 17 Nov'09Comp30291: Section 418 Reading from the graph or the MATLAB display, we get: {h[n]} = {..., -0.055, -0.07, 0, 0.14, 0.28, 0.33, 0.28, 0.14, 0, -0.07, -0.055,... } A digital filter with this impulse-response would have exactly the ideal frequency-response we applied to the inverse-DTFT. ‘Brick-wall’ low-pass gain response & phase = 0 for all . But {h[n]} has non-zero samples extending from n = -  to , Not a finite impulse-response. Also not causal. Not realisable in practice. ‘Ideal’ impulse-response

19 17 Nov'09Comp30291: Section 419 (2) Delay resulting sequence by M/2 samples to ensure that the first non-zero sample occurs at n = 0. Step (1) is ‘truncation’ or ‘windowing’ applied symmetrically about n=0. To produce a realisable impulse-response {h[n]}: Assume M is order of required filter & that M is even.

20 17 Nov'09Comp30291: Section 420 n h[n] = (1/3)sinc(n/3) Starting with ‘ideal’ impulse-response:

21 17 Nov'09Comp30291: Section 421 n n h[n] M=10 Truncate to  M/2 Delay by M/2 samples

22 17 Nov'09Comp30291: Section 422 If M=10, finite impulse-response obtained is: {...0, -0.055, -0.07, 0, 0.14, 0.28, 0.33, 0.28, 0.14, 0, -0.07, -0.055, 0... } Obtained by truncating & delaying {h[n]} for ‘ideal’ lowpass digital filter with cut-off  /3 radians/sample. Taking M = 4, we would obtain: {.., 0,.., 0, 0.14, 0.28, 0.33, 0.28, 0.14, 0,..,0,..} Resulting causal impulse-response now realised by setting: a n = h[n] for n = 0,1,2,...,M. Causal & finite impulse-response

23 17 Nov'09Comp30291: Section 423 Gain & phase responses may be derived by MATLAB. FIR filter realisation (M=4) z -1 z z -1 x[n] y[n] 0.28 0.14 0.33 0.14 a0a0 a1a1 a2a2 a4a4 a3a3 + ( Note:4th order FIR filter has 4 delays & 5 multipliers ).

24 17 Nov'09Comp30291: Section 424 Plot gain & phase responses of 4 th order FIR filter FCFC Fs/2 -6dB  /3  Fs/6 -21 dB Straight line Jumps by 180 O Gain drops to -  dB

25 17 Nov'09Comp30291: Section 425 MATLAB prog for truncating & plotting gain & phase n=[-20:20]; h = (1/3)*sinc(n/3); M=4; % FIR filter order Fs = 8000; % Sampling freq (Hz) for n=-M/2 : M/2 a(n + M/2 + 1) = h(n+21); end; figure(1); freqz(a,1,200,Fs);

26 17 Nov'09Comp30291: Section 426 Gain-response of 4 th order FIR filter (zoomed) Gain starts at 0 dB in pass-band & falls to -6 dB at cut-off frequency. There are two ‘stop-band ripples’ & gain is  -21 dB at peak of first. FCFC Fs/2 -6dB  /3  Fs/6 05001000150020002500300035004000 -60 -40 -20 0 20 Frequency (Hz) Magnitude (dB) -21 dB Gain drops to -  dB

27 17 Nov'09Comp30291: Section 427 Phase-lag response of 4 th order FIR filter F Hz 400020001000 0 100 200 300 O   /2 22 Phase-lag FCFC Fs/2 3000 Linear phase in pass-band Don’t worry about 180 degree jumps in stop-band for now.

28 17 Nov'09Comp30291: Section 428 Why do we not get a zero phase-response? We started by specifying that phase = 0 for all .  (  )  -- We ended up with a phase-response as follows:  -- -()-()  Only pass-band part is shown here Phase response affected by the delay of M/2 samples.

29 17 Nov'09Comp30291: Section 429 Estimation of phase-delay from slope For a linear phase LTI system, -  (  ) /  is ‘phase-delay’ in sampling intervals. Look at phase-response graph in pass-band. Phase decreases by 180 o in 2000Hz (Fs = 8000 Hz)  radians in  /2 radians/second -  (  ) /      /2 = 2 sampling intervals So the phase-delay is 2. Not a surprise as we delayed the impulse-response by 2 samples to make it causal (M=4).

30 17 Nov'09Comp30291: Section 430 Using MATLAB functions ‘fir1’ & ‘freqz’ Same result obtained using ‘fir1’ as follows: c = fir1(4, 0.33, rectwin(5), 'noscale'); Reason for rectwin(5) & ‘noscale’ will be clear later. To plot gain & phase response: freqz(c, 1, 500, Fs); Plots 500 points & frequency-axis to range 0-Fs/2 !! Plots  (  ) against  rather than phase lag -  (  ). Phase ‘unwrapped’ to avoid 360 o jumps.

31 17 Nov'09Comp30291: Section 431 Gain & phase responses of 4 th order FIR filter by MATLAB

32 17 Nov'09Comp30291: Section 432 Effect of truncating {h[n]} to  M/2 & delaying by M/2 samples Gain & phase responses different from those originally specified. Gain-response: cut-off rate not ‘brick-wall’,  0 dB at 0 Hz & drops to  -6 dB at cut-off frequency, ‘ripples’ and ‘zeros’ appear in stop-band, peak of the first ripple at about -21dB. Phase-response: not zero for all  as originally specified, linear phase in pass-band -  (  )/  = M/2 for |  |   /3; phase-delay = M/2 sampling intervals. Jumps of 180 o occur in stop-band. Jumps of 360 o avoided by unwrapping.

33 17 Nov'09Comp30291: Section 433 Can we improve low-pass filter by increasing order to ten? Taking 11 terms of { (1/3)sinc(n/3)} we get, after delaying by 5 samples: {...0,-0.055,-.069, 0,.138,.276,.333,.276,.138,0,-.069,-.055,0,...}. To obtain same result from MATLAB7: c = fir1(10, 0.33, rectwin(11), 'noscale'); freqz(c);

34 17 Nov'09Comp30291: Section 434 10th order FIR digital lowpass filter(  /3 rect) z -1 ++++++++++ x[n] y[n] -.055 -.07 0 -.055 -.07 0 0.14.28.33 0.14.28 When coeffs are symmetric, the filter is linear phase.

35 17 Nov'09Comp30291: Section 435 For 10th order low-pass filter with  C =  /3:

36 17 Nov'09Comp30291: Section 436 Gain & phase responses of 20th order lowpass FIR filter with  C =  /3

37 17 Nov'09Comp30291: Section 437 Gain & phase responses of 60th order lowpass FIR filter with  C =  /3

38 17 Nov'09Comp30291: Section 438 Gain & phase of 100th order low-pass FIR filter with  C =  /3

39 17 Nov'09Comp30291: Section 439 Gain-response of 10th order lowpass FIR filter with  C =  /3

40 17 Nov'09Comp30291: Section 440 Gain response of 20th order lowpass FIR filter with  C =  /3

41 17 Nov'09Comp30291: Section 441 Cut-off rate increases as order (M) increases. Number of stop-band ripples increases with order. Gain at peak of first ripple after cut-off remains at -21 dB. Remains exactly ‘linear phase’ in pass-band but slope of phase-response (=phase-delay) increases since -  (  ) /  = M/2. NB: freqz ‘unwraps’ phase-response avoiding 360 o jumps! Filter not really improving with increasing order. To improve matters we need to discuss ‘windowing’. Effect of increasing order on gain & phase responses

42 17 Nov'09Comp30291: Section 442 By truncating {h[n]} for ideal filter, we effectively multiplied {h[n]} by a rectangular window sequence {r M+1 [n]} to produce {h[n]} where 4.3. Windowing M/2-M/2 r M+1 [n] n

43 17 Nov'09Comp30291: Section 443 Sudden transitions to zero at rectangular window edges cause the stop-band ripples we saw in the gain-response graphs. Why is this? It may be shown that DTFT of {r M+1 [n]} is: Effect of rectangular window on freq-response

44 17 Nov'09Comp30291: Section 444 DTFT of rect-window {r M+1 [n]} with M=20 Purely real Looks a bit like sinc. Height of main lobe = M+1 Area of main lobe  2  Width = 4  /(M+1)

45 17 Nov'09Comp30291: Section 445 MATLAB program to plot R M+1 (e j  ) M = 20; W = -3.2 : 0.001 : 3.2; if W==0, R=M+1; else R=sin((M+1)*W/2)./sin(W/2); end; figure(1); plot(W,R); grid on; title(sprintf('Dirichlet K of order %d ', M)); axis([-3.2 3.2 -M*0.3 M+2]); xlabel('radians/sample'); ylabel('R');

46 17 Nov'09Comp30291: Section 446 Frequency-domain convolution Multiplying two sequences {x[n]} & {[y[n]} to produce {x[n].y[n]} is called ‘time-domain multiplication’. It may be shown that if {x[n]} has DTFT X(e j  ) & [y[n]} has DTFT Y(e j  ) then the DTFT of {x[n].y[n]} is: This is frequency domain convolution. ‘Multiply, find the area then scale by 1/ 2  ’ Time-domain multiplication  freq-domain convolution.

47 17 Nov'09Comp30291: Section 447 Apply this formula to rectangular window If H(e j  ) has ideal brick-wall gain-response, & R M+1 (e j  ) is as shown in previous graph, convolving H(e j  ) with R M+1 (e j  ) reduces cut-off rate & introduces stop-band ripples. The sharper the main-lobe of R M+1 (e j  ) and the lower the ripples, the better. Multiplying an ideal impulse-resp {h[n]} by the rect window {r M+1 [n]} causes H(e j  ) to be ‘convolved’ with R M+1 (e j  ).

48 17 Nov'09Comp30291: Section 448 Illustration for ideal  /3 lowpass filter What happens to area under curve as  increases from 0 to  ?

49 17 Nov'09Comp30291: Section 449  =0   /3  /3  Area under curve  /3 to  +  /3 when  =0 R M+1 (e j  )  2 

50 17 Nov'09Comp30291: Section 450  =  /6  Area under curve  /3 to  +  /3 when  =  /6   /2  /6 R M+1 (e j  )  2 

51 17 Nov'09Comp30291: Section 451  =  /3  Area under curve  /3 to  +  /3 when  =  /3  2  /3 0 R M+1 (e j  )    

52 17 Nov'09Comp30291: Section 452  =  /2  Area under curve  /3 to  +  /3 when  =  /2  5  /6  /6 R M+1 (e j  )  0

53 17 Nov'09Comp30291: Section 453  =2  /3  Area under curve  /3 to  +  /3 when  =2  /3   /3   0 R M+1 (e j  )

54 17 Nov'09Comp30291: Section 454 Conclusions from these graphs Ripples arise from freq-domain convolution between ideal freq-response & R M+1 (e j  ). At  =0, area is 2  so gain is 1 which is 0 dB. At  =  C (=  /3), area is half of 2 , so gain  0.5 (  6 dB) as half of main lobe lies between    /3 &  +  /3. As  is increased from  /3, main lobe no longer included, so area comes from the ripples. Ripples are small & alternately +ve & negative, so area & therefore the gain will be small. But area will increase & decrease (ripple) as  increases.

55 17 Nov'09Comp30291: Section 455 Levels of ripples reduced if {r M+1 [n]} replaced by non-rectangular window sequence { w M+1 [n] }. Produces a more gradual transition at the window edges. Simple non-rectangular window sequence is Hann window It’s a ‘raised cosine’ with M+1 non-zero samples centred on n=0. 4.4. Non-rectangular windows n M/2  M/2 w M+1 [n]

56 17 Nov'09Comp30291: Section 456 Hann window w 21 [n]

57 17 Nov'09Comp30291: Section 457 Hann window w 41 [n]

58 17 Nov'09Comp30291: Section 458 ‘Hamming’ & other ‘Hann’ windows Slightly different formulae exist for the Hann window. In practice, the difference is usually unimportant. MATLAB has 2 functions: ‘hann’ & ‘hanning’. ‘hanning(M+1)’ gives our Hann window {w M+1 [n]} But it’s shifted by 1+M/2 samples to start at n=1. Best known non-rectangular window is ‘Hamming’. Its name & its formula are fairly similar to ‘Hann’:

59 17 Nov'09Comp30291: Section 459 Hamming window w 21 [n]

60 17 Nov'09Comp30291: Section 460 Hamming window w 41 [n]

61 17 Nov'09Comp30291: Section 461 Multiplying {h[n]} by {w M+1 [n]} instead of {r M+1 [n]} gradually tapers impulse-response towards zero at window edges. To understand why this reduces stop-band ripples, compare DTFT of {w M+1 [n]} with DTFT of {r M+1 [n]} with M=20. Effect of non-rectangular windows

62 17 Nov'09Comp30291: Section 462 DTFT of Hann window {w M+1 [n]} Height of main lobe = 1 + M/2 (  half that of rect window) Area of main lobe  2  (same as rect window) Width of main lobe 8  /M (  twice that of rect window) It may be shown that: W M+1 (e j  ) = 0.5R M+1 (e j  ) + 0.25R M+1 (e j(  -  /(1+M/2)) ) + 0.25R M+1 (e j(  +  /(1+M/2)) )  Purely real only for a window that is symmetric about  =0.

63 17 Nov'09Comp30291: Section 463 DTFT of Hamming window {hw M+1 [n]} Height of main lobe = 1 + 0.54M (  half that of rect window) Area of main lobe  2  (same as rect window) Width of main lobe  8  /M (  twice that of rect window) It may be shown that: HW M+1 (e j  ) = 0.54R M+1 (e j  ) + 0.23R M+1 (e j(  -  /(1+M/2)) ) + 0.23R M+1 (e j(  +  /(1+M/2)) )  Let’s stay with Hann for now as the differences are small.

64 17 Nov'09Comp30291: Section 464 To plot DTFT of Hann & Rect windows clear all; close all; clc M=20; W = -3.2:0.001: 3.2; W=W+0.0000001; % Sorry R=sin((M+1)*W/2)./sin(W/2); W1=W-pi/(1+M/2); W2=W+pi/(1+M/2); R1=sin((M+1)*W1/2)./sin(W1/2); R2=sin((M+1)*W2/2)./sin(W2/2); Hann=0.5*R + 0.25*R1+0.25*R2; figure(1); plot(W,Hann,W,R); grid on; title(sprintf('DTFT of Hann & Rect windows, order %d ', M)); axis([-3.2 3.2 -M*0.3 (M+2)]); xlabel('radians/sample'); ylabel(‘DTFT'); legend('Hann','Rect','Location','Best');

65 17 Nov'09Comp30291: Section 465 Plot on dB scale 20.log 10 (abs(DTFT))

66 17 Nov'09Comp30291: Section 466 Ripples in W 21 (e j  ) greatly reduced in comparison to R 21 (e j  ). This is good! Main lobe W 21 (e j  ) less sharp & lower in comparison to R 21 (e j  ). Reduces sharpness of the cut-off Price paid for reducing stop-band ripples. Comparing DTFT of Rect & Hann windows

67 17 Nov'09Comp30291: Section 467 Ideal  /3 lowpass filter with Hann window As before, consider what happens to area under curve as  increases from 0 to , but now with Hann window ?

68 17 Nov'09Comp30291: Section 468  =0   /3  /3  Area under curve  /3 to  +  /3 when  =0 W M+1 (e j  )  2  radians/sample DTFT of Hann window

69 17 Nov'09Comp30291: Section 469  =  /3  2  /3 0  Area under curve  /3 to  +  /3 when  =  /3 W M+1 (e j  )    radians/sample DTFT of Hann window

70 17 Nov'09Comp30291: Section 470  =  /2 5  /6  /6  Area under curve  /3 to  +  /3 when  =  /2 W M+1 (e j  )   0.1 radians/sample DTFT of Hann window

71 17 Nov'09Comp30291: Section 471  =2  /3  /3 Area under curve  /3 to  +  /3 when  =2  /3 W M+1 (e j  )     0 radians/sample DTFT of Hann window

72 17 Nov'09Comp30291: Section 472 Conclusions from these graphs Have plotted freq-domain convolution between an ideal freq-response & DTFT of Hann window. At  =0, area is 2  so gain is 1 as for rect window. At  =  /3, area is  (half of main lobe), so gain  0.5 (-6dB) as for rect window. As  is increased from  /3, area of main lobe disappears more gradually than for rect window. Ripples of DTFT of Hann window are much smaller than for rect window, so ripples in the area & therefore the gain will be much reduced. Slower cut-off (bad) but reduced stopband ripples (good)

73 17 Nov'09Comp30291: Section 473 Ideal impulse-response was found to be: {h[n]} = { …....., 0.14, 0.28, 0.33, 0.28, 0.14, ………} When M = 4, Hann window is: {w 5 [n]} = {..,0,..,0, 0.25, 0.75, 1, 0.75, 0.25, 0,..,0,..} Multiplying term by term & delaying by M/2 = 2 samples we get: {..,0,..,0, 0.04, 0.21, 0.33, 0.21, 0.04, 0,..,0,..} Consider again low-pass filter with cut-off  /3 radians/sample Applying 4th order Hann window

74 17 Nov'09Comp30291: Section 474 Resulting ‘Hann-windowed’ FIR filter of order 4: Its gain-response is shown on next slide. z -1 z z -1 x[n] y[n] 0.21 0.04 0.33 0.04 a0a0 a1a1 a2a2 a4a4 a3a3 +

75 17 Nov'09Comp30291: Section 475 Gain-resp from MATLAB: 4 th order (Hann)

76 17 Nov'09Comp30291: Section 476 To design 10th order FIR lowpass filter with Hann window & cut-off frequency  /3 (  Fs/6): Effect of increasing order to 10 clear all; M=10 for n= -M/2 : M/2 w = 0.5 *(1+cos(n*pi/(1+M/2)) ); c(1+n+M/2) = (1/3)*sinc(n/3)*w; end; Fs = 8000; freqz(c,1,500,Fs); axis([0 4000 -60 0]);

77 17 Nov'09Comp30291: Section 477 10th order FIR lowpass (  /3, Hann) z -1 ++++++++++ x[n] y[n] -.004 -.017 0 -.004 -.017 0 0.1.257.333 0.1.257 Since coeffs are symmetric, filter is exactly linear phase.

78 17 Nov'09Comp30291: Section 478 Gain & phase resp for 10th order FIR (  /3,Hann)

79 17 Nov'09Comp30291: Section 479 ‘fir1’ uses ‘windowing method’ we have just seen. By default it uses a Hamming window. Also scales coeffs to make gain exactly 0 dB at 0 Hz To design 10th order FIR lowpass filter with Hamming window & cut-off frequency  /3 (  Fs/6): c=fir1(10, 0.33); Use of MATLAB function ‘fir1’

80 17 Nov'09Comp30291: Section 480 10th order FIR lowpass (  /3, Hamming) z -1 ++++++++++ x[n] y[n] -.005 -.01 0 -.005 -.01 0 0.1.25.33 0.1.25 Again, coeffs are symmetric so filter is exactly linear phase.

81 17 Nov'09Comp30291: Section 481 Gain & phase resp for 10th order FIR (  /3,Hamming)

82 17 Nov'09Comp30291: Section 482 Effect of windowing on freq-response of FIR digital filter Effect is to gradually reduce amplitude of ideal impulse-response towards zero at edges of window rather than to abruptly truncate. Effect on gain-response of FIR filter obtained is: i) to greatly reduce stop-band ripples ( good ). ii) to reduce the cut-off rate ( bad ). Phase-response is not affected in the pass-band. We can improve the cut-off rate by going to higher orders. Graphs next are for Hann window with M=10, 20 & 60:

83 17 Nov'09Comp30291: Section 483 Tenth order FIR filter with  C =  /3 ( Hann window )

84 17 Nov'09Comp30291: Section 484 20th order FIR filter with  C =  /3 (Hann window)

85 17 Nov'09Comp30291: Section 485 60th order FIR filter with  C =  /3 (Hann window)

86 17 Nov'09Comp30291: Section 486 Tenth order FIR filter with  C =  /3 ( Hann window )

87 17 Nov'09Comp30291: Section 487 20th order FIR filter with  C =  /3 (Hann window)

88 17 Nov'09Comp30291: Section 488 Reduced from about –21 dB to about –44 dB. At frequency of first stop-band ripple: since 20log 10 (1/10) =  20 dB, amplitude reduced by factor  10 with rect window. since 20 log 10 (1/100) =  40 dB, amplitude reduced by factor >100 with Hann window. i.e. 5 sin(  t) becomes 0.5 sin(  t) or 0.05 sin(  t). What do we do if this is not good enough? Answer, use a different window (e.g. Hamming, Kaiser) Hamming window similar to Hann but slightly better. Effect of Hann window on first stop-band ripple

89 17 Nov'09Comp30291: Section 489 Offers a range of options from rectangular, through Hamming towards even lower stop-band ripples. Ripple reduction at expense of less sharp cut-off rate. MATLAB command: KW = kaiser(M+1,beta) gives a Kaiser window array of length M+1 for any value of beta > 0. When beta (  ) = 0, this is a rectangular window & when beta = 5.4414 we get a Hamming window. Increasing beta further gives further reduced stop-band ripples with a reduced cut-off sharpness. 4.5. Kaiser window

90 17 Nov'09Comp30291: Section 490 Order 60 FIR LPF c/o  /3 designed with Kaiser window (  =5)

91 17 Nov'09Comp30291: Section 491 Order 60 FIR LPF c/o  /3 designed with Hamming window

92 17 Nov'09Comp30291: Section 492 Order 60 FIR LPF c/o  /3 designed with Kaiser window (  =8)

93 17 Nov'09Comp30291: Section 493 Order 100 FIR LPF (  /3) designed with Kaiser window (  =8)

94 17 Nov'09Comp30291: Section 494 100 th order FIR LPF (  /3) designed with Hamming window

95 17 Nov'09Comp30291: Section 495 Order 100 FIR LPF (  /3) designed with Kaiser window (  =10)

96 17 Nov'09Comp30291: Section 496 clear all; beta = 5; N=60; kw = kaiser(N+1,beta); hw=hamming(N+1); a=fir1(N, 0.33, rectwin(N+1), 'noscale'); for n=1:N+1 akw(n)=a(n)*kw(n); ahw(n) = a(n)*hw(n); end; figure(1); freqz(akw); grid on; figure(2); freqz(ahw); grid on; My MATLAB test program

97 17 Nov'09Comp30291: Section 497 Plot of Kaiser window (beta = 10)

98 17 Nov'09Comp30291: Section 498 4.6. Highpass, bandpass & bandstop linear phase FIR filters Can be designed almost as easily as low-pass. Remember to define required gain-response G(  ) from -  to +  Make G(-  ) = G(  ). Band-pass filter with pass-band from F S /8 to F S /4 has following gain response ideally:-

99 17 Nov'09Comp30291: Section 499 Applying inverse DTFT (not forgetting negative  ): Taking  (  ) = 0 for all  initially as before, we obtain: Can evaluate this, apply window & delay as before. Use MATLAB to get {h[n]} FIR band-pass filter (  /4 to  /2)

100 17 Nov'09Comp30291: Section 4100 100th order FIR band-pass filter(  /4-  /2 Rect)

101 17 Nov'09Comp30291: Section 4101 FIR filter design in MATLAB c = fir1(10,0.33,'high') designs a 10th order high-pass filter. c = fir1(10,[0.2 0.4],'bandpass') designs a 10th order band-pass filter with cut-off frequencies 0.2  and 0.4 . c = fir1(20,[0.2 0.4],'stop') designs a 20th order band-stop filter with cut-off frequencies 0.2  and 0.4 . By default ‘fir1’ uses a ‘Hamming’ window (very similar to a Hann) and scales the pass-band gain to 0 dB. Linear phase response obtained.

102 17 Nov'09Comp30291: Section 4102 4.7. Summary of ‘windowing method’ To design FIR filter of even order M, with gain-response approximating G(  ) & linear phase, 1) Set H(e j  ) = G(  ). This assumes  (  ) = 0. 2) I-DTFT to produce ideal impulse-response {h[n]}. 3) Window to  M/2 using chosen window. 4) Delay windowed impulse-response by M/2 samples. 5)Realise by setting multipliers of FIR filter. MATLAB routine fir1 does all this for LP, HP, BP, BS

103 17 Nov'09Comp30291: Section 4103 Instead H(e j  ) = e j0 G(  ), we get H(e j  ) = e -j  M/2 G(  ) G(  ) is distorted version of G(  ) due to windowing. Phase-response is  (  ) = -  M/2 in pass-band Linear phase with phase-delay: -  (  ) /  = M/2 samples. Filter coeffs are symmetric about M/2. e.g. {…2, -3, 5, 7, 5, -3, 2, …} M =6 (even) {…, 1, 3, 5, 5, 3, 1, …} M=5 (odd) This is because the FIR filter is linear phase. Properties of resulting FIR digital filter

104 17 Nov'09Comp30291: Section 4104 = e -5j  /2 (e 5j  /2 +3e 3j  /2 +5e j  /2 +5e -j  /2 +3e -3j  /2 +e -5j  /2 ) = e -5j  /2 (2cos(2.5  ) + 6cos (1.5  ) + 10cos(  /2) ) = G(  )e j  (  ) with  (  ) = -5  /2. Hence  (  ) /  = -5/2 = constant, so H(e j  ) is linear phase. Demonstrate that an FIR filter whose impulse- response is symmetric is linear phase. Let {h[n]} = {…, 1, 3, 5, 5, 3, 1, …} (symmetric)

105 17 Nov'09Comp30291: Section 4105 4.8 Using MATLAB SP Toolbox See notes

106 17 Nov'09Comp30291: Section 4106 Better than windowing technique, but more complicated. Available in MATLAB. Design 40 th order FIR lowpass filter whose gain is unity (0 dB) in range 0 to 0.3  radians/sample & zero in range 0.4  to . a = remez (40, [0, 0.3, 0.4, 1], [1, 1, 0, 0] ); The 41 coefficients will be found in array ‘a’. Produces 'equi-ripple' gain-responses where peaks of stop-band ripples are equal rather than decreasing with increasing frequency. Highest peak in stop-band lower than for FIR filter of same order designed by windowing technique to have same cut-off rate. There are 'equi-ripple' pass-band ripples. 4.9. Remez Exchange Algorithm method

107 17 Nov'09Comp30291: Section 4107 Gain of 40 th order FIR lowpass filter designed by ‘Remez’

108 17 Nov'09Comp30291: Section 4108 FIR digital filters often implemented in mobile equipment. Low power fixed point DSP processors are used. Typically with a basic 16-bit word-length. Must be programmed using only integer arithmetic. Take 4 th order FIR filter with impulse response: {….. 0.04, 0.21, 0.33, 0.21, 0.04, …...}. Rounding each coeff to nearest integer clearly a mistake. Multiply each coeff by a large constant, e.g. 100, then round:. A 0 = 4, A 1 = 21, A 2 = 33, A 3 = 21, A 4 = 4. We must divide the output by same constant. Instead of 100, choose a power of two for the constant. 4.10. Fixed point implementat n of FIR digital filters

109 17 Nov'09Comp30291: Section 4109 Dividing by a power of two (e.g. 1024) is very simple It’s just an ‘arithmetic right-shift’ operation. Available instruction on DSPs. The larger the constant, the more accurate the coefficients. Careful not to choose too large a constant If integers produced get too large, we risk overflow Difficult balancing act between inaccuracy & overflow. If constant is 2^10 (=1024), rounded 4th order coeffs become: A0 = 35 A1 = 212 A2 = 341 A3 = 212 A4 = 35 MATLAB prog on next slide uses integer arithmetic Ready to be ported to a DSP Fixed point implementation (cont)

110 17 Nov'09Comp30291: Section 4110 4 th order low-pass filter using integer arithmetic only A = [35 212 341 212 35] ; x = [0 0 0 0 0 ] ; while 1 x(1) = input( 'X = '); Y = A(1)*x(1); for k = 5 : -1: 2 Y = Y + A(k)*x(k); x(k) = x(k-1); end; Y = round( Y/1024); %Arith right-shift 10 places disp([' Y = ' num2str(Y)]); end;

111 17 Nov'09Comp30291: Section 4111 FIR filters easy to program in fixed point arithmetic. Never become unstable as there is no feedback. Can be exactly linear phase In some cases, overflows can be allowed to occur since if gain is never greater than 1, you know that a +ve overflow will eventually be cancelled out by a  ve overflow or vice versa. This works if you do not use ‘saturation mode’ arithmetic which avoids ‘wrap-round’. Can risk overflow more readily with FIR digital filters than with IIR digital filters, & thus have greater coefficient accuracy. Disadvantage: FIR need higher orders than IIR (later). 4.11. Advantages of FIR filters compared with IIR

112 17 Nov'09Comp30291: Section 4112 Scaling by 1024, is adopting a 'Q-format' of ten. Programmer assumes a binary point to exist ten bit positions from the right within the 16-bit word. DSP language: ‘Q-format’

113 17 Nov'09Comp30291: Section 4113 PROBLEMS 1. Design a 100th order FIR low-pass digital filter with cut-off at f S /4 with & without a Hann window. Use MATLAB to compare gain responses obtained. 2. Design 10th order FIR bandpass filter with cut-off frequencies at  /4 &  /2. 3. Write MATLAB program for one of these filters using integer arithmetic only. 4. Design a 4th order FIR high-pass filter with cut-off at  /3. 5. Do all FIR filters have exactly linear phase responses? 6. Explain why IIR digital filters cannot have exactly linear phase responses. 7. Explain why it is impossible to implement an ideal ‘brick-wall’ LPF. 8. Show that  (  ) = -k  corresponds to a delay of k samples. 9. Rearrange even order linear phase FIR filter to reduce no. of multipliers. 10. Do FIR filters have passband ripples as well as stopband ripples? 11. Explain why FIR filters have stopband ripples where IIR filters do not. 12. Explain why the gain of an FIR low pass filter with 0 dB gain at zero frequency reduces to -6 dB at its cut-off frequency.

114 17 Nov'09Comp30291: Section 4114 Questions 10 & 6 10. Yes but you can hardly see them. 6. For linear phase, impulse-response must be symmetric about some value of n, say n=M. If it is an IIR it goes on for ever as n  . So it must go on for ever backwards as n  - . Would have to be non-zero for values on n<0; i.e. non-causal. n h[n] If h[n] symmetric & IIR it must be non-causal M


Download ppt "17 Nov'09Comp30291: Section 41 University of Manchester School of Computer Science Comp30291 Digital Media Processing 2009-10 Section 4 ‘Design of FIR."

Similar presentations


Ads by Google