Presentation is loading. Please wait.

Presentation is loading. Please wait.

ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact:

Similar presentations


Presentation on theme: "ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact:"— Presentation transcript:

1 ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu Office Hours: Room 2030 Class web site: http://ee.lamar.edu/gleb/ dsp/index.htm http://ee.lamar.edu/gleb/ dsp/index.htm

2 ELEN 5346/4304 DSP and Filter Design Fall 2008 2 Preliminary considerations FIR filter: unit-pulse responsetransfer function (11.2.1) Here M-1 is the filter order. M is the number of filter’s coefficients. Assuming that M is odd: BTW, using our “rational notation”: (11.2.2) (11.2.3)

3 ELEN 5346/4304 DSP and Filter Design Fall 2008 3 Preliminary considerations For an FIR filter to have a linear phase: That means an even symmetry of the coefficients. (11.3.1) (11.3.2) Remember: FIR filters are always stable (no poles other than at the origin)!

4 ELEN 5346/4304 DSP and Filter Design Fall 2008 4 Preliminary considerations Since the filter is stable: Here is a real function of frequency. (11.4.1) As a result of symmetry: (11.4.2)

5 ELEN 5346/4304 DSP and Filter Design Fall 2008 5 Preliminary considerations Therefore: Generalized linear phase We can use to design ANY amplitude of frequency response: LPF, HPF, BPF,… When changes sign, the phase undergoes an abrupt change of 180 0 In M is even: (11.5.1) (11.5.2)

6 ELEN 5346/4304 DSP and Filter Design Fall 2008 6 Preliminary considerations An FIR filter will also have a linear phase in the case of odd symmetry of filter coefficients (antisymmetric impulse response), i.e.: It can be shown that (11.6.1) (11.6.2) (11.6.3) Therefore: (11.6.4) BTW: (11.6.5) (11.6.6)

7 ELEN 5346/4304 DSP and Filter Design Fall 2008 7 Preliminary considerations Thus: Generalized linear phase (11.7.1) Summarizing, a unit-pulse response of a GLP FIR filter must satisfy: (11.7.2) (11.7.3) (11.7.4) We only need to specify (M-1)/2 (odd M) or M/2 unique coefficients (even M).

8 ELEN 5346/4304 DSP and Filter Design Fall 2008 8 Preliminary considerations Combining (11.7.2) and (11.7.3), we arrive at: (11.8.1) Example: if M = 5: Has two pairs of reciprocal zeros. firls(4,[0 0.25],[1 0]);

9 ELEN 5346/4304 DSP and Filter Design Fall 2008 9 Preliminary considerations There are four types of real GLP FIR filters: indicate “structural zeros” Type I: symmetric h n, odd M (number of coefficients) – even order. Type II: symmetric h n, even M Type III: antisymmetric h n, odd M Type IV: antisymmetric h n, even M

10 ELEN 5346/4304 DSP and Filter Design Fall 2008 10 Preliminary considerations 1. For M = 4, symmetrical pulse response ( Type II FIR): 2. For M = 4, antisymmetrical pulse response ( Type IV FIR): 3. For M = 5, antisymmetrical pulse response ( Type III FIR): (11.10.1) (11.10.2) (11.10.3) This is where structural zeros come from…

11 ELEN 5346/4304 DSP and Filter Design Fall 2008 11 Preliminary considerations As a result of structural zeros… Type II FIR HPF would have a zero at  - specs will be violated! Type III FIR HPF would have a zero at  - specs will be violated! Type IV FIR LPF would have a zero at 0 - specs will be violated! If something like tis happens, increase or decrease the FIR order to change the type of your filter. We need to be careful with selection of filter orders!

12 ELEN 5346/4304 DSP and Filter Design Fall 2008 12 1. Least-square error minimization The desired magnitude response (something we specify): (11.12.1) Filter coefficients could be found as: Example: Ideal LPF (11.12.2) (11.12.3) Not causal, infinite length! We need to preserve the main features while making the filter causal.

13 ELEN 5346/4304 DSP and Filter Design Fall 2008 13 1. Least-square error minimization The filter specified by (11.12.3) has an infinite impulse response. Therefore, we need to truncate it at some point to make an FIR filter. As a criterion for such truncation, we need to minimize the approximation error (the difference between the desired and the truncated frequency responses). The magnitude of the frequency response of the “truncated filter”: Where L and U are points at which the pulse response was truncated. Therefore, the objective is to find a finite-duration impulse response sequence, whose DTFT would approximate the desired frequency response. (11.13.1) We need to minimize the least-square integral error of approximation.

14 ELEN 5346/4304 DSP and Filter Design Fall 2008 14 1. Least-square error minimization In particular: Apparently, to minimize  R (LS error), we select h t,n = h d,n for n = L…U. Moreover, GLP requires symmetry of filter coefficients, therefore L = -U. The best finite length approximation of the ideal infinite length impulse response in the LS error sense is obtained by truncation. To make the resulting FIR causal, we need to shift it by  L radians. (11.14.1) (11.14.2)

15 ELEN 5346/4304 DSP and Filter Design Fall 2008 15 1. Least-square error minimization Relating the point of truncation to the FIR filter order: L = (M – 1)/2 Note: filter length M (number of filter coefficients) can be both even or odd. (11.15.1) Non-causalCausal

16 ELEN 5346/4304 DSP and Filter Design Fall 2008 16 2. Windowing effects We can view the truncation of the infinite impulse response of an ideal filter as windowing. In frequency domain, this operation is equivalent to convolution of a frequency response of the window function with the frequency response of an ideal filter. from the Modulation theorem: (11.16.1) (11.16.2) Gibbs phenomenon (comes from truncated Fourier series) Ripples of equal magnitude in PB and SB Transition band – another window artifact W R :

17 ELEN 5346/4304 DSP and Filter Design Fall 2008 17 2. Windowing effects: window types As discussed previously, different window functions can be used… Window MLW (4  /M) PSL (dB) TB (2  /M) Max SB ripple (dB) Rectangular  0.9 -130.9-21 Hanning  2 -313.1-44 Hamming  2 -413.3-53 Blackman  3 -575.5-74 Window propertiesFilter properties Fixed windows:

18 ELEN 5346/4304 DSP and Filter Design Fall 2008 18 2. Windowing effects: window types Rectangular: Hanning: Hamming: Blackman: (11.18.1) (11.18.2) (11.18.3) (11.18.4)

19 ELEN 5346/4304 DSP and Filter Design Fall 2008 19 2. Windowing effects: window types Kaiser window: (11.19.1) Where: (11.19.2) Normally, 15-20 terms in the summation are sufficient. Note: if  = 0, W n K = W n R. Adjustable windows:

20 ELEN 5346/4304 DSP and Filter Design Fall 2008 20 2. Windowing effects: window types  TB (2  /M) Max SB ripple (dB) 21.5-29 32.0-37 42.6-45 53.2-54 74.5-72 85.1-81 Properties: Kaiser window is the most frequently used for the FIR filter design. Hanning Hamming Blackman

21 ELEN 5346/4304 DSP and Filter Design Fall 2008 21 2. Windowing: experimental design For the given transition band: Stop-band attenuation: Order estimate: Adjustable parameter: (11.21.1) (11.21.2) (11.21.3) (11.21.4) M controls transition band,  changes ripples. Note: in practice, ripples in SB and PB are approximately equal. If this does not hold, need to select minimum of  s,  p.

22 ELEN 5346/4304 DSP and Filter Design Fall 2008 22 2. Windowing: experimental design Example 11.1: design an FIR LPF using a Kaiser window for the following specs: The transition band: Order: Parameter: We select M = 24,  = 4. The filter is given by (11.15.1) with the cutoff frequency: The resulting filter is a type II FIR which is ok for LPF. The transfer function:

23 ELEN 5346/4304 DSP and Filter Design Fall 2008 23 3. Frequency sampling The desired frequency response can be specified by its frequency samples at equally spaced (discrete) frequencies: Where (11.23.1) (11.23.2)  = 0: (11.23.3) (11.23.4) 2  /M  /M  = 0.5:

24 ELEN 5346/4304 DSP and Filter Design Fall 2008 24 3. Frequency sampling The sampled frequency response will be: Evaluating IDFT: Therefore, we can compute the filter coefficients from the specified M frequency samples. (11.24.1) (11.24.2) Since h n is real: Since h n is symmetric, we only need to specify either (M+1)/2 (M is odd) or M/2 (M is even) frequency samples to determine the pulse response. (11.24.3)

25 ELEN 5346/4304 DSP and Filter Design Fall 2008 25 3. Frequency sampling We can rewrite the FIR filter frequency response (11.7.4) as: Sampled at the frequencies the response becomes: (11.25.1) (11.25.2) (11.25.3)

26 ELEN 5346/4304 DSP and Filter Design Fall 2008 26 3. Frequency sampling Here: For simplicity, we specify the following set of real frequency samples: Therefore: (11.26.1) (11.26.2) (11.26.3)

27 ELEN 5346/4304 DSP and Filter Design Fall 2008 27 3. Frequency sampling Case 1: (11.27.1) (11.27.2)

28 ELEN 5346/4304 DSP and Filter Design Fall 2008 28 3. Frequency sampling Since h n is real: Since H r is real: (11.28.1) (11.28.2) (11.28.3) (11.28.4)

29 ELEN 5346/4304 DSP and Filter Design Fall 2008 29 3. Frequency sampling Therefore: (11.29.1) The number of coefficients (frequency samples) to be specified: - forced zero at z = -1 (11.29.2) Since the unit-pulse response is already evaluated, we can estimate the corresponding frequency response as its zero-padded DFT: and check whether the specifications are satisfied.

30 ELEN 5346/4304 DSP and Filter Design Fall 2008 30 3. Frequency sampling Case 2: (11.30.1) (11.30.2) (11.30.3) The desired frequency samples:

31 ELEN 5346/4304 DSP and Filter Design Fall 2008 31 3. Frequency sampling Case 3: (11.31.1) (11.31.2) The desired frequency samples: (11.31.3)

32 ELEN 5346/4304 DSP and Filter Design Fall 2008 32 3. Frequency sampling Case 4: (11.32.1) The desired frequency samples: (11.32.2) (11.32.3)

33 ELEN 5346/4304 DSP and Filter Design Fall 2008 33 3. Frequency sampling We specify the desired response in the SB and the PB only… The stopband attenuation in this case (only SB and PB samples are given) is approximately -20 dB. Alternatively, we can add transition sample(s) and make the frequency response smoother. The stopband attenuation would be: for one TB sample: approximately -40 dB. for two TB sample: approximately -60 dB. for three TB sample: approximately -80 dB.

34 ELEN 5346/4304 DSP and Filter Design Fall 2008 34 3. Frequency sampling The transition band sample(s) “optimized” experimentally are: # of TB samplesSample(s) value(s)SB attenuation, dB T1 0.3789795 – if  = 0 0.3570496 – if  = 0.5 ~ 40 T2[0.1065 0.5886]~ 60 T3[0.025779 0.251635 0.723071] [0.030957 0.27557 0.744348] Note: only one of them is correct. ~ 80 T4[0.006061 0.09324 0.4082 0.82097]~ 100 Effects of adding TB sample(s) are increased SB attenuation and wider TB. These samples must be optimized for the situation. Selection of the offset  can help too. Note: we can specify any desired frequency response at the samples but not in between! Ultimately, we can view all frequency samples as the TB samples, which leads to an optimal (equiripple) design.

35 ELEN 5346/4304 DSP and Filter Design Fall 2008 35 4. Optimal equiripple design We are interested in a LP filter satisfying the following requirements: Considering four FIR types: Type 1: symmetric pulse response, odd M. The real-valued frequency response: (11.35.1) (11.35.2) (11.35.3) (11.35.4)

36 ELEN 5346/4304 DSP and Filter Design Fall 2008 36 4. Optimal equiripple design Type 2: symmetric pulse response, even M. The real-valued frequency response: (11.36.1) (11.36.2) (11.36.3) Or: Where: (11.36.4) (11.36.5)

37 ELEN 5346/4304 DSP and Filter Design Fall 2008 37 4. Optimal equiripple design Type 3: antisymmetric pulse response, odd M. The real-valued frequency response: (11.37.1) (11.37.2) (11.37.3) Or: Where: (11.37.4) (11.37.5)

38 ELEN 5346/4304 DSP and Filter Design Fall 2008 38 4. Optimal equiripple design Type 4: antisymmetric pulse response, even M. The real-valued frequency response: (11.38.1) (11.38.2) (11.38.3) Or: Where: (11.38.4) (11.38.5)

39 ELEN 5346/4304 DSP and Filter Design Fall 2008 39 4. Optimal equiripple design Therefore, we can express the frequency response for all FIR types as: Where: Filter typeQ(e j  )P(e j  ) 1: M odd1 2: M even 3: M odd 4: M even (11.39.1) (11.39.2)

40 ELEN 5346/4304 DSP and Filter Design Fall 2008 40 4. Optimal equiripple design The desired frequency response: We can compute and compare it to. Adjusting P(  ) and selecting filter type, we can obtain the desired frequency characteristic. We introduce the weighting function on the approximation error: If  s <  p – bigger error in the passband is allowed. (11.40.1) (11.40.2)

41 ELEN 5346/4304 DSP and Filter Design Fall 2008 41 4. Optimal equiripple design The weighted approximation error: (11.41.1) Where the modified weighting function and the modified desired frequency response are: (11.41.2) (11.41.3)

42 ELEN 5346/4304 DSP and Filter Design Fall 2008 42 4. Optimal equiripple design For the given error function E(e j  ), the Chebyshev (mini-max) approximation problem is to determine the filter parameters  k that minimize the maximum absolute error over the frequency bands of interest: (11.42.1) Usually, the frequency bands of interest are specified as: (11.42.2) a disjoint union of the passband and the stopband: 0 -  p and  s -  (for a LPF). That is we “ignore” the transition band. More precisely speaking, error over the TB will not be optimized. The solution of this problem can be found via the alternation theorem.

43 ELEN 5346/4304 DSP and Filter Design Fall 2008 43 4. Optimal equiripple design The alternation theorem A necessary and sufficient conditions for to be unique and best approximation to in S is that the error function E(e j  ) exhibit at least L + 2 extremal frequencies in S. That is, there must exist at least L + 2 frequencies {  i }, such that: I.e., error alternates in sign between two successive extremal frequencies. (11.43.1) (11.43.2) (11.43.3)

44 ELEN 5346/4304 DSP and Filter Design Fall 2008 44 4. Optimal equiripple design: Example Example 11.2: design a LPF. Since both the desired frequency response H dr and the weighting function W are piecewise constants: Consequently, the frequencies {  i } that correspond to the peaks of the error function E(e j  ) also correspond to the peaks of H r (e j  ), i.e., where the frequency response meets the specified error tolerance. Since H r (e j  ) is a polynomial of degree L: (11.44.1) (11.44.2) H r (e j  ) has at most L-1 local minima and maxima and, therefore, at most L+1 extremal frequencies (bandages) since we add  = 0 and  = . Furthermore, the band-edge frequencies  p and  s are also extrema of the error function. Therefore, E(e j  ) has at most L+3 extremal frequencies.

45 ELEN 5346/4304 DSP and Filter Design Fall 2008 45 4. Optimal equiripple design: Example However, from the alternation theorem, there are at least L+2 extremal frequencies in E(e j  ). Thus the error function for the LPF design will have either L+2 or L+3 (extra ripple filters) extremal frequencies. At the specified extremal frequencies  n : Here  represents the maximum value of the error function E(e j  ). alternations or alternatively: (11.45.1) (11.45.2) (11.45.3)

46 ELEN 5346/4304 DSP and Filter Design Fall 2008 46 4. Optimal equiripple design: Example We can consider the {  k } and  as the unknown (to be determined) design parameters for the given extremal frequencies. Therefore: (11.46.1) Note: initially, both the design parameters and the extremal frequencies are unknown. The above system can be solved by the iterative algorithm (Remez exchange algorithm): 1)Guess the set of L + 1 extremal frequencies; 2)Solve for {  k } and  ; 3)Determine the error function as in (11.39.1); 4)Determine the new set of L + 1 extremal frequencies and go to 2)… Keep running until E(e j  )   - convergence.

47 ELEN 5346/4304 DSP and Filter Design Fall 2008 47 4. Optimal equiripple design Alternatively, we can compute  analytically [Rabiner ‘75]: where: (11.47.1) (11.47.2) Therefore, the initial guess of the L + 2 extremal frequencies allows us to compute the maximum value of the error . Thus: (11.47.3)

48 ELEN 5346/4304 DSP and Filter Design Fall 2008 48 4. Optimal equiripple design Since we know that the polynomial at the points x n = cos  n has the values: the Lagrange interpolation formula can be used, which leads to Here: (11.48.1) (11.48.2) (11.48.3) (11.48.4) (11.48.5)

49 ELEN 5346/4304 DSP and Filter Design Fall 2008 49 4. Optimal equiripple design Having the solution for P, we can compute the error function: on a dense set of frequency points. Usually, 16M frequency points are sufficient. If the error exceeds the estimated tolerance , we select a new set of frequencies corresponding to the L+2 largest peaks of error function and the procedure starts from (11.45.1). New set of critical frequencies will lead to increased . As a result, the algorithm produces the optimal solution with equal ripples in the PB and the SB for the given M. The order of the filter can be estimated as: (11.49.1) (11.49.2)

50 ELEN 5346/4304 DSP and Filter Design Fall 2008 50 Summary Historically, the window-based algorithm was the first proposed method for FIR design. Its major disadvantage is the lack of precise control of the critical frequencies, such as  s and  p. These values, in general, depend on the type of the window and the filter length M. The frequency sampling method is attractive since it specifies an arbitrary frequency response at the uniformly spaced frequencies and the transition band is a multiple of 2  /M. However, no control for the response in between the samples. The Chebyshev approximation method provides a total control of the filter specifications and may lead to an equiripple design. This way, the approximation error is spread evenly across the PB and SB, which leads to an optimal filter. This method is usually preferred.

51 ELEN 5346/4304 DSP and Filter Design Fall 2008 51 Remarks and conclusions Since orders of FIR filters can be quite high, these filters can introduce a considerable group delay, which is approximately M/2. The following Matlab functions are handy for FIR design: fir1 – FIR filter design using the windowing method fir2 – FIR filter design via the frequency sampling method firpm – Parks-McClellan optimal equiripple FIR design firpmord - Parks-McClellan optimal equiripple FIR order estimator

52 ELEN 5346/4304 DSP and Filter Design Fall 2008 52 Appendix: the ideal transfer functions LPF: HPF: BPF: BSF: (11.52.1) (11.52.2) (11.52.3) (11.52.4)


Download ppt "ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact:"

Similar presentations


Ads by Google