Download presentation
Presentation is loading. Please wait.
Published byOsborne Williamson Modified over 9 years ago
1
21 Oct'08Comp30291: Section 41 University of Manchester School of Computer Science Comp30291 Digital Media Processing 2007-08 Section 4 ‘Design of FIR digital filters’
2
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: Section 46 Reminder about integration ab t (Have +ve & ve areas) x(t)
7
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: Section 48 Bits of MATHs e a.e b = e (a+b) (e a ) 2 = e 2a |A|.|B| = |A.B| but |A+B| |A| + |B| etc.
9
21 Oct'08Comp30291: Section 49 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).
10
21 Oct'08Comp30291: Section 410 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
11
21 Oct'08Comp30291: Section 411 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
12
21 Oct'08Comp30291: Section 412 By inverse DTFT, required impulse-response is:
13
21 Oct'08Comp30291: Section 413 To complete the calculation:
14
21 Oct'08Comp30291: Section 414 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’
15
21 Oct'08Comp30291: Section 415 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]);
16
21 Oct'08Comp30291: Section 416 Graph of sinc(x) against x ‘Main lobe’ ‘Ripples’ ‘Zero-crossings’ at x = 1, 2, 3, etc
17
21 Oct'08Comp30291: Section 417 Impulse-response for this ideal (brick-wall) lowpass filter
18
21 Oct'08Comp30291: Section 418 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;
19
21 Oct'08Comp30291: Section 419 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
20
21 Oct'08Comp30291: Section 420 (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’ To produce a realisable impulse-response {h[n]}: Assume M is order of required filter & that M is even.
21
21 Oct'08Comp30291: Section 421 n h[n] = (1/3)sinc(n/3) Starting with ‘ideal’ impulse-response:
22
21 Oct'08Comp30291: Section 422 n n h[n] M=10 Truncate to M/2 Delay by M/2 samples
23
21 Oct'08Comp30291: Section 423 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
24
21 Oct'08Comp30291: Section 424 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 ).
25
21 Oct'08Comp30291: Section 425 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
26
21 Oct'08Comp30291: Section 426 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);
27
21 Oct'08Comp30291: Section 427 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
28
21 Oct'08Comp30291: Section 428 Phase-lag response of 4 th order FIR filter F Hz 400020001000 0 100 200 300 O /2 22 Phase-lag FCFC Fs/2 3000 Linear phase in pass-band Don’t worry about 180 degree jumps in stop-band for now.
29
21 Oct'08Comp30291: Section 429 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.
30
21 Oct'08Comp30291: Section 430 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).
31
21 Oct'08Comp30291: Section 431 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.
32
21 Oct'08Comp30291: Section 432 Gain & phase responses of 4 th order FIR filter by MATLAB
33
21 Oct'08Comp30291: Section 433 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.
34
21 Oct'08Comp30291: Section 434 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);
35
21 Oct'08Comp30291: Section 435 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 The coeffs are symmetric because the filter is linear phase.
36
21 Oct'08Comp30291: Section 436 For 10th order low-pass filter with C = /3:
37
21 Oct'08Comp30291: Section 437 Gain & phase responses of 20th order lowpass FIR filter with C = /3
38
21 Oct'08Comp30291: Section 438 Gain & phase responses of 60th order lowpass FIR filter with C = /3
39
21 Oct'08Comp30291: Section 439 Gain & phase of 100th order low-pass FIR filter with C = /3
40
21 Oct'08Comp30291: Section 440 Gain-response of 10th order lowpass FIR filter with C = /3
41
21 Oct'08Comp30291: Section 441 Gain response of 20th order lowpass FIR filter with C = /3
42
21 Oct'08Comp30291: Section 442 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
43
21 Oct'08Comp30291: Section 443 By truncating {h[n]} for ideal filter, we effectively multiplied {h[n]} by a rectangular window sequence {r M [n]} to produce {h[n]} where 4.3. Windowing M/2-M/2 r M [n] n
44
21 Oct'08Comp30291: Section 444 Sudden transitions to zero at rectangular window edges cause the stop-band ripples we saw in the gain-response graphs. Why is this? Consider DTFT of {r M [n]} Effect of rectangular window on freq-response when 0, 2 ,...
45
21 Oct'08Comp30291: Section 445 DTFT of rect-window {r M [n]} When = 0, R M (e j ) = M+1 Shows R M (e j ) for M=20 Purely real. Looks a bit like sinc. Has main-lobe & ripples. Ripples cause stop-band ripples in gain-resp
46
21 Oct'08Comp30291: Section 446 MATLAB program to plot R M (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');
47
21 Oct'08Comp30291: Section 447 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: Time-domain multiplication is equivalent to frequency-domain convolution. *Appendix B
48
21 Oct'08Comp30291: Section 448 Apply this formula to rectangular window If H(e j ) has ideal brick-wall gain-response, & R M (e j ) is as shown in previous graph, convolving H(e j ) with R M (e j ) reduces cut-off rate & introduces stop-band ripples. The sharper the main-lobe of R M (e j ) and the lower the ripples, the better. Multiplying an ideal impulse resp {h[n]} by the rect window {r M [n]} causes H(e j ) to be ‘convolved’ with R M (e j ).
49
21 Oct'08Comp30291: Section 449 Illustration for ideal /3 lowpass filter What happens to area under curve as increases from 0 to ?
50
21 Oct'08Comp30291: Section 450 =0 /3 /3 Area under curve /3 to + /3: 1
51
21 Oct'08Comp30291: Section 451 = /6 /3 /3 Area 1
52
21 Oct'08Comp30291: Section 452 = /3 /3 /3 Area 0.5
53
21 Oct'08Comp30291: Section 453 = /2 /3 /3 Area 0 (ripples)
54
21 Oct'08Comp30291: Section 454 =2 /3 /3 /3 Area 0 (ripples)
55
21 Oct'08Comp30291: Section 455 Conclusions from these graphs Ripples arise from freq-domain convolution between ideal freq-response & R M (e j ). At = C (= /3), gain is 0.5 ( 6 dB) because half of main lobe lies between - /3 & /3.
56
21 Oct'08Comp30291: Section 456 Levels of ripples reduced if {r M [n]} replaced by non-rectangular window sequence { w M [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 [n]
57
21 Oct'08Comp30291: Section 457 Hann window w 20 [n]
58
21 Oct'08Comp30291: Section 458 Hann window w 40 [n]
59
21 Oct'08Comp30291: Section 459 ‘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 [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’:
60
21 Oct'08Comp30291: Section 460 Hamming window w 20 [n]
61
21 Oct'08Comp30291: Section 461 Hamming window w 40 [n]
62
21 Oct'08Comp30291: Section 462 Multiplying {h[n]} by {w M [n]} instead of {r M [n]} gradually tapers impulse-response towards zero at window edges. To understand why this reduces stop-band ripples, compare DTFT of {w M [n]} with DTFT of {r M [n]}. Hann window with M=20. Effect of non-rectangular windows
63
21 Oct'08Comp30291: Section 463 DTFT of Hann window {w M [n]} Formula was needed for plotting previous graph. w M [n] = 0.5(1+cos( n/(1+M/2) ) r M [n] = 0.5r M [n]+ 0.25(e j n/(1+M/2) + e -j n/(1+M/2) )r M [n] where {r M [n]} is rect window. We know R M (e j ) already. It is easy to show that multiplying {w M [n]} by {e -jDn } for any constant D gives us: R M (e j( - D) ) W M (e j ) = 0.5R M (e j ) + 0.25R M (e j( - /(1+M/2)) ) + 0.25R M (e j( + /(1+M/2)) ) Purely real only for a window that is symmetric about =0.
64
21 Oct'08Comp30291: 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
21 Oct'08Comp30291: Section 465 Plot on dB scale 20.log 10 (abs(DTFT))
66
21 Oct'08Comp30291: Section 466 Ripples in W 20 (e j ) greatly reduced in comparison to R 20 (e j ). This is good! Main lobe W 20 (e j ) less sharp & lower in comparison to R 20 (e j ). Reduces sharpness of the cut-off Price to be paid for reducing stop-band ripples. Comparing DTFT of Rect & Hann windows
67
21 Oct'08Comp30291: Section 467 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 4 [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
68
21 Oct'08Comp30291: Section 468 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 +
69
21 Oct'08Comp30291: Section 469 Gain-resp from MATLAB: 4 th order (Hann)
70
21 Oct'08Comp30291: Section 470 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]);
71
21 Oct'08Comp30291: Section 471 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 Coeffs are symmetric because filter is exactly linear phase.
72
21 Oct'08Comp30291: Section 472 Gain & phase resp for 10th order FIR ( /3,Hann)
73
21 Oct'08Comp30291: Section 473 ‘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’
74
21 Oct'08Comp30291: Section 474 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 because filter is exactly linear phase.
75
21 Oct'08Comp30291: Section 475 Gain & phase resp for 10th order FIR ( /3,Hamming)
76
21 Oct'08Comp30291: Section 476 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 below are for 10 th, 20 th & 60th order ( Hann windowed ):
77
21 Oct'08Comp30291: Section 477 Tenth order FIR filter with C = /3 ( Hann window )
78
21 Oct'08Comp30291: Section 478 20th order FIR filter with C = /3 (Hann window)
79
21 Oct'08Comp30291: Section 479 60th order FIR filter with C = /3 (Hann window)
80
21 Oct'08Comp30291: Section 480 Tenth order FIR filter with C = /3 ( Hann window )
81
21 Oct'08Comp30291: Section 481 20th order FIR filter with C = /3 (Hann window)
82
21 Oct'08Comp30291: Section 482 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, 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
83
21 Oct'08Comp30291: Section 483 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(N,beta) produces a Kaiser window array of length N 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
84
21 Oct'08Comp30291: Section 484 Order 60 FIR LPF c/o /3 designed with Kaiser window ( =5)
85
21 Oct'08Comp30291: Section 485 Order 60 FIR LPF c/o /3 designed with Hamming window
86
21 Oct'08Comp30291: Section 486 Order 60 FIR LPF c/o /3 designed with Kaiser window ( =8)
87
21 Oct'08Comp30291: Section 487 Order 100 FIR LPF ( /3) designed with Kaiser window ( =8)
88
21 Oct'08Comp30291: Section 488 100 th order FIR LPF ( /3) designed with Hamming window
89
21 Oct'08Comp30291: Section 489 Order 100 FIR LPF ( /3) designed with Kaiser window ( =10)
90
21 Oct'08Comp30291: Section 490 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
91
21 Oct'08Comp30291: Section 491 Plot of Kaiser window (beta = 10)
92
21 Oct'08Comp30291: Section 492 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:-
93
21 Oct'08Comp30291: Section 493 Applying inverse DTFT (not forgetting negative ): Taking ( ) = 0 for all initially as before, we obtain: Can evaluate this, apply window & delay as before. But there is an easier way to get {h[n]} FIR band-pass filter ( /4 to /2)
94
21 Oct'08Comp30291: Section 494 H(e j ) = H 1 (e j ) H 2 (e j ) = (1/2)sinc(n/2) (1/4)sinc(n/4) for < n < -- /4 /2-- - /2- /4 11 H 1 (e j ) H 2 (e j ) Impulse-response for ideal Fs/4-Fs/2 band-pass filter
95
21 Oct'08Comp30291: Section 495 100th order FIR band-pass filter( /4- /2 Rect)
96
21 Oct'08Comp30291: Section 496 Exercise By a similar method, or otherwise, show that the impulse- response for an ideal zero phase 'brick-wall' high-pass filter with cut-off frequency /6 radians per sample (i.e. one twelfth of the sampling frequency) is: h[n] = sinc(n) - (1/6)sinc(n/6) for - < n <
97
21 Oct'08Comp30291: Section 497 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.
98
21 Oct'08Comp30291: Section 498 Technique not restricted to ‘conventional’ gain-responses. Design an FIR filter whose gain-response approximates: Exercise: Other FIR digital filters Solution: h[n]= (1/2)sinc(n/2) 0.5 (1/4)sinc(n/4) for < n <
99
21 Oct'08Comp30291: Section 499 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
100
21 Oct'08Comp30291: Section 4100 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
101
21 Oct'08Comp30291: Section 4101 = 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)
102
21 Oct'08Comp30291: Section 4102 4.8. Further applications of windowing design technique Technique even more powerful than has been yet indicated Not restricted to linear phase filters. Consider some further examples of its use. 4.8.1 Fractional sampling interval delay filter: 4.8.2. Differentiator: 4.8.3. Hilbert transformer: See notes for details (no exam questions on this)
103
21 Oct'08Comp30291: Section 4103 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
104
21 Oct'08Comp30291: Section 4104 Gain of 40 th order FIR lowpass filter designed by ‘Remez’
105
21 Oct'08Comp30291: Section 4105 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
106
21 Oct'08Comp30291: Section 4106 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)
107
21 Oct'08Comp30291: Section 4107 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;
108
21 Oct'08Comp30291: Section 4108 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
109
21 Oct'08Comp30291: Section 4109 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’
110
21 Oct'08Comp30291: Section 4110 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. Show that if { h[n] } is real, H( e -j ) = H*( e j ) and hence that: 7. Show that if H(e j ) is linear phase with phase delay N samples, with N an integer, its impulse-response is symmetric about n=N. 8. Design 6th order linear phase FIR filter whose gain-response approximates that shown in fig 4.13. 9. Show that ( ) = -k corresponds to a delay of k samples. 10. Rearrange even order linear phase FIR filter to reduce no. of multipliers. 11. Do FIR filters have passband ripples as well as stop band ripples? 12. Explain why IIR digital filters cannot have exactly linear phase responses.
111
21 Oct'08Comp30291: Section 4111 Discussion of Question 10 z -1 + + + AMAM A0A0 A M-2 A M-1 x[n] y[n] Alternative signal-flow graph is given below. Check that it has the same impulse response as normal one. Note that multiplier order is reversed. It has advantage that input to all multipliers is same.
112
21 Oct'08Comp30291: Section 4112 Discussion of question 10 (cont) + A0A0 A3A3 A2A2 A1A1 x[n] y[n] z -1 + + + + + Linear phase filter can be rearranged to save multipliers as follows: Usual FIR signal-flow graph can also be rearranged when linear phase. Exercise for you.
113
21 Oct'08Comp30291: Section 4113 Questions 11 & 12 11. Yes but you can hardly see them. 12. 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
114
21 Oct'08Comp30291: Section 4114 Appendix A: Effect of delaying {h[n]} by M/2 samples If DTFT of {h[n]} is G( ), the DTFT of {h[n-M/2] is: The phase lead is now - M/ 2 instead of zero. Phase-delay - ( ) / = M/2 sampling intervals.
115
21 Oct'08Comp30291: Section 4115 Appendix B: Proof of frequency-domain convolution DTFT of {x[n].y[n]} is: Time-domain multiplication is equivalent to frequency-domain convolution.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.