Upcoming SlideShare
×

# Chapter14

374 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
374
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
13
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Chapter14

1. 1. Chapter 14Finite Impulse Response (FIR) Filters
2. 2. Learning Objectives  Introduction to the theory behind FIR filters:  Properties (including aliasing).  Coefficient calculation.  Structure selection.  Implementation in Matlab, C, assembly and linear assembly.hapter 14, Slide 2 Dr. Naim
3. 3. Introduction  Amongst all the obvious advantages that digital filters offer, the FIR filter can guarantee linear phase characteristics.  Neither analogue or IIR filters can achieve this.  There are many commercially available software packages for filter design. However, without basic theoretical knowledge of the FIR filter, it will be difficult to use them.hapter 14, Slide 3 Dr. Naim
4. 4. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0 x[n] represents the filter input, bk represents the filter coefficients, y[n] represents the filter output, N is the number of filter coefficients (order of the filter).hapter 14, Slide 4 Dr. Naim
5. 5. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] FIR equation k =0 -1 -1 -1 -1 x(n) z z z z b 0 b 1 b2 b N-1 x x x x + + + y(n) Filter structurehapter 14, Slide 5 Dr. Naim
6. 6. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0  If the signal x[n] is replaced by an impulse δ [n] then: N −1 y[ n ] = ∑b δ [n − k ] k k =0 y[ 0] = b0δ [ 0] + b1δ [ − 1] +  + bk δ [ − N ]hapter 14, Slide 6 Dr. Naim
7. 7. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0  If the signal x[n] is replaced by an impulse δ [n] then: N −1 y[ n ] = ∑b δ [n − k ] k k =0 y[ n] = b0δ [ n] + b1δ [ n − 1] +  + bk δ [ n − N ]hapter 14, Slide 7 Dr. Naim
8. 8. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0  If the signal x[n] is replaced by an impulse δ [n] then: N −1 y[ n ] = ∑b δ [n − k ] k k =0 1 for n = k δ [n − k ] =  0 for n ≠ khapter 14, Slide 8 Dr. Naim
9. 9. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0  Finally: b0 = h[ 0] b1 = h[1]  bk = h[ k ]hapter 14, Slide 9 Dr. Naim
10. 10. Properties of an FIR Filter  Filter coefficients: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] k =0 With: bk = h[ k ]  The coefficients of a filter are the same as the impulse response samples of the filter.hapter 14, Slide 10 Dr. Naim
11. 11. Frequency Response of an FIR Filter  By taking the z-transform of h[n], H(z): N −1 H ( z ) = ∑ h[ n] z − n n =0  Replacing z by ejω in order to find the frequency response leads to: ( ) N −1 H ( z ) z =e jω = H e jω = ∑ h[ n] e − jnω n =0hapter 14, Slide 11 Dr. Naim
12. 12. Frequency Response of an FIR Filter  Since e-j2π k = 1 then: N −1 N −1 H ( z ) z =eω +2π = ∑ h[ n] e − jn ( ω + 2π ) =∑ h[ n] e − jnω n =0 n =0  Therefore: H ( e jω+2 kπ ) = H ( e jω )  FIR filters have a periodic frequency response and the period is 2π .hapter 14, Slide 12 Dr. Naim
13. 13. Frequency Response of an FIR Filter  Frequency response: ( ) ( ) H e jω + 2 kπ = H e jω x[n] FIR y[n] x[n] y[n] Freq Freq Fs/2 Fs/2hapter 14, Slide 13 Dr. Naim
14. 14. Frequency Response of an FIR Filter  Solution: Use an anti-aliasing filter. x[n] x(t) ADC FIR y[n] Analogue Anti-Aliasing x(t) y[n] Freq Freq Fs/2 Fs/2hapter 14, Slide 14 Dr. Naim
15. 15. Phase Linearity of an FIR Filter  A causal FIR filter whose impulse response is symmetrical is guaranteed to have a linear phase response. h(n) h(n) N = 2n + 2 N = 2n + 1 n n 0 1 n n+1 2n 2n+1 0 1 n-1 n n+1 2n-1 2n Even symmetry Odd symmetryhapter 14, Slide 15 Dr. Naim
16. 16. Phase Linearity of an FIR Filter  A causal FIR filter whose impulse response is symmetrical (ie h[n] = h[N-1- n] for n = 0, 1, …, N-1) is guaranteed to have a linear phase response. N− Phase  = 1 Condition  − k  Phase Property Filter Type  2  h[ ]=N − 1] n h[ n − Odd Symmetry – Type 1 kω Linear phase Positive Symmetry Even Symmetry – Type 2hapter 14, Slide 16 Dr. Naim
17. 17. Phase Linearity of an FIR Filter  Application of 90° linear phase shift: o IH I 90 + Reverse delay + Signal separation delay - Forward Q 90o + QH I = A cos ω f t + B sin ω r t  π  π IH + Q = 2 B cos ωr t IH = A cos ω f t +  + B sin  ωr t +   2  2 Q = A sin ω f t + B cos ω r t = − A sin ω f t + B cos ωr t QH − I = 2 B sin ω f thapter 14, Slide 17 Dr. Naim
18. 18. Design Procedure  To fully design and implement a filter five steps are required: (1) Filter specification. (2) Coefficient calculation. (3) Structure selection. (4) Simulation (optional). (5) Implementation.hapter 14, Slide 18 Dr. Naim
19. 19. Filter Specification - Step 1 |H(f)| pass-band stop-band 1 f c : cut-off frequency f s /2 f(norm) (a) |H(f)| pass-band transition band stop-band |H(f)| (dB) (linear) ∆p δ 1+ p 0 1 δ 1− p pass-band -3 ripple stop-band ripple ∆s δs f s /2 f(norm) f sb : stop-band frequency f c : cut-off frequency f pb : pass-band frequency (b)hapter 14, Slide 19 Dr. Naim
20. 20. Coefficient Calculation - Step 2  There are several different methods available, the most popular are:  Window method.  Frequency sampling.  Parks-McClellan.  We will just consider the window method.hapter 14, Slide 20 Dr. Naim
21. 21. Window Method  First stage of this method is to calculate the coefficients of the ideal filter.  This is calculated as follows: π 1 hd ( n ) = ∫ H ( ω )e jωn dω 2π −π ωc 1 = 2π ∫ 1 ⋅ e jωn dω −ω c  2 f c sin ( nω c )  for n ≠ 0 = nω c   2 fc for n = 0hapter 14, Slide 21 Dr. Naim
22. 22. Window Method  Second stage of this method is to select a window function based on the passband or attenuation specifications, then determine the filter length based on the required width of the transition band. Normalised Transition Stopband Attenuation Window Type Passband Ripple(dB) Width (∆ f(Hz)) (dB) 0.9 Rectangular 0.7416 21 N 3.1 Hanning 0.0546 44 N 3.3 Hamming 0.0194 53 N 5.5 Blackman 0.0017 74 N 2.93 →β = 4.54 N 0.0274 50 Kaiser 5.71 →β = 8.96 N 0.000275 90 Using the Hamming N= 3.3 = 3.3 ⋅ 8kHz = 132 Window: ∆f (1.2 − 1.4 ) kHzhapter 14, Slide 22 Dr. Naim
23. 23. Window Method  The third stage is to calculate the set of truncated or windowed impulse response coefficients, h[n]: N −1 N −1 − ≤n≤ for N = odd h( n ) = hd ( n ) ⋅ W ( n ) for 2 2 N N for N = even − ≤n≤ 2 2  2πn  Where: W ( n ) = 0.54 + 0.46 cos   N   2πn  for −66 ≤ n ≤ 66 = 0.54 + 0.46 cos   133 hapter 14, Slide 23 Dr. Naim
24. 24. Window Method  Matlab code for calculating coefficients: close all; clear all; fc = 8000/44100; % cut-off frequency N = 133; % number of taps n = -((N-1)/2):((N-1)/2); n = n+(n==0)*eps; % avoiding division by zero [h] = sin(n*2*pi*fc)./(n*pi); % generate sequence of ideal coefficients [w] = 0.54 + 0.46*cos(2*pi*n/N); % generate window function d = h.*w; % window the ideal coefficients [g,f] = freqz(d,1,512,44100); % transform into frequency domain for plotting figure(1) plot(f,20*log10(abs(g))); % plot transfer function axis([0 2*10^4 -70 10]); figure(2); stem(d); % plot coefficient values xlabel(Coefficient number); ylabel (Value); title(Truncated Impulse Response); figure(3) freqz(d,1,512,44100); % use freqz to plot magnitude and phase response axis([0 2*10^4 -70 10]);hapter 14, Slide 24 Dr. Naim
25. 25. Window Method Truncated Impulse Response 0.4 0.3 0.2 h(n) 0.1 0 -0.1 0 20 40 60 80 100 120 140 Coefficient number, n 0 Magnitude (dB) -20 -40 -60 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Frequency (Hz) 4 x 10 0 Phase (degrees) -2000 -4000 -6000 0 0.5 1 1.5 2 Frequency (Hz) 4 x 10hapter 14, Slide 25 Dr. Naim
26. 26. Realisation Structure Selection - Step 3  Direct form structure for an FIR filter: N −1 H ( z ) = ∑ bk z − k k =0 Y ( z) = H ( z) ⋅ X ( z) y ( n ) = b0 x( n ) + b1 x( n − 1) + .... + bN −1 x( n − N + 1) -1 -1 -1 x(n) z z z b b b b 0 1 2 N-1 + + + y(n)hapter 14, Slide 26 Dr. Naim
27. 27. Realisation Structure Selection - Step 3  Direct form structure for an FIR filter: N −1 H ( z ) = ∑ bk z − k k =0 N −1 ∑ ( ) 2 H ( z) = bk z − k + z N − k −1 k =0 N −1 N −1 ∑b (z ) 2 − H ( z) = k −k + z N − k −1 + b N −1 z 2 k =0 2hapter 14, Slide 27 Dr. Naim
28. 28. Realisation Structure Selection - Step 3 (a) N even. z -1 z -1 z -1 z -1 z -1 b0 (b) N odd. + b1 + + b2 + + b N/2-1 + + y(n) (a) x(n) -1 -1 -1 -1 -1 -1 z z z z z z b0 + b1 + + b2 + + b(N-1)/2 b (N-3)/2 + + y(n) + (b)hapter 14, Slide 28 Dr. Naim
29. 29. Realisation Structure Selection - Step 3  Direct form structure for an FIR filter: N −1 H ( z ) = ∑ bk z − k k =0  Cascade structures: N −1 H ( z) = ∑ bk z − k = b0 + b1 z −1 + b2 z − 2 + ... + bN −1 z − ( N −1) k =0  b1 −1 b2 − 2 bN −1 − ( N −1)  = b0 1 + z + z + ... + z   b0 b0 b0  ∏ (1 + b ) M = b0 k ,1 z −1 + bk , 2 z − 2 k =1hapter 14, Slide 29 Dr. Naim
30. 30. Realisation Structure Selection - Step 3  Direct form structure for an FIR filter: N −1 H ( z ) = ∑ bk z − k k =0  Cascade structures: x(n) b 0 y(n) + + + z -1 z -1 z -1 b 1,1 b 2,1 b M,1 + + + z -1 z -1 z -1 b 1,2 b 2,2 b M,2hapter 14, Slide 30 Dr. Naim
31. 31. Implementation - Step 5  Implementation procedure in ‘C’ with fixed-point:  Set up the codec (LinksCodecSetup.pdf).  Transform: N −1 y[ n] = ∑ bk ⋅ x[ n − k ] to ‘C’ code. k =0 (LinksFIRFixed.pdf)  Configure timer 1 to generate an interrupt at 8000Hz (LinksTimerSetup.pdf).  Set the interrupt generator to generate an interrupt to invoke the Interrupt Service Routine (ISR) (LinksInterruptSetup.pdf).hapter 14, Slide 31 Dr. Naim
32. 32. Implementation - Step 5  Implementation procedure in ‘C’ with floating-point: Same set up as fixed-point plus:  Convert the input signal to floating-point format.  Convert the coefficients to floating-point format.  With floating-point multiplications there is no need for the shift required when using Q15 format.  See LinksFIRFloat.pdfhapter 14, Slide 32 Dr. Naim
33. 33. Implementation - Step 5  Implementation procedure in assembly: Same set up as fixed-point, however:  N −1 y[ n] = ∑ bk ⋅ x[ n − k ] is written in assembly. k =0 (LinksFIRFixedAsm.pdf)  The ISR is now declared as external.hapter 14, Slide 33 Dr. Naim
34. 34. Implementation - Step 5  Implementation procedure in assembly: The filter implementation in assembly is now using circular addressing and therefore:  The circular pointers and block size register are selected and initialised by setting the appropriate values of the AMR bit fields.  The data is now aligned using: #pragma DATA_ALIGN (symbol, constant (bytes))  Set the initial value of the circular pointers, see LinksFIRFixedAsm.pdf.hapter 14, Slide 34 Dr. Naim
35. 35. Implementation - Step 5 b0 x0 b1 x1 b2 x2 b3 x3 y0 = b0*x0 + b1*x1 + b2*x2 + b3*x3 y[n] time 0 1 2 Circular addressing link slide.hapter 14, Slide 35 Dr. Naim
36. 36. Implementation - Step 5 b0 x4 b1 x1 b2 x2 b3 x3 y0 = b0*x0 + b1*x1 + b2*x2 + b3*x3 y1 = b0*x4 + b1*x1 + b2*x2 + b3*x3 y[n] time 0 1 2 Circular addressing link slide.hapter 14, Slide 36 Dr. Naim
37. 37. Implementation - Step 5 b0 x4 b1 x5 b2 x2 b3 x3 y0 = b0*x0 + b1*x1 + b2*x2 + b3*x3 y1 = b0*x4 + b1*x1 + b2*x2 + b3*x3 y2 = b0*x4 + b1*x5 + b2*x2 + b3*x3 y[n] time 0 1 2 Circular addressing link slide.hapter 14, Slide 37 Dr. Naim
38. 38. FIR Code  Code location:  CodeChapter 14 - Finite Impulse Response Filters  Projects:  Fixed Point in C: FIR_C_Fixed  Floating Point in C: FIR_C_Float  Fixed Point in Assembly: FIR_Asm_Fixed  Floating Point in Assembly: FIR_Asm_Floathapter 14, Slide 38 Dr. Naim
39. 39. Chapter 14Finite Impulse Response (FIR) Filters - End -