Lecture 11 - FIR Filter Design

52
ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: [email protected] Office Hours: Room 2030 Class web site: http://ee.lamar.ed u/gleb/dsp/index.h tm

description

FIR Filter Design

Transcript of Lecture 11 - FIR Filter Design

Lecture 11: LTI FIR filter designFall 2008
Instructor: Dr. Gleb V. Tcheslavski
Fall 2008
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)
Fall 2008
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)!
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.4.1)
(11.4.2)
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.5.1)
(11.5.2)
We can use to design ANY amplitude of frequency response: LPF, HPF, BPF,…
When changes sign, the phase undergoes an abrupt change of 1800
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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)
Fall 2008
(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).
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.8.1)
firls(4,[0 0.25],[1 0]);
ELEN 5346/4304 DSP and Filter Design
Fall 2008
indicate “structural zeros”
Type I: symmetric hn, odd M (number of coefficients) – even order.
Type II: symmetric hn, even M
Type III: antisymmetric hn, odd M
Type IV: antisymmetric hn, even M
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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)
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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!
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.12.1)
Example: Ideal LPF
Not causal, infinite length!
We need to preserve the main features while making the filter causal.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
In particular:
Apparently, to minimize R (LS error), we select ht,n = hd,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)
Fall 2008
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-causal
Causal
Fall 2008
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:
Ripples of equal magnitude in PB and SB
Transition band – another window artifact
W R:
Fall 2008
As discussed previously, different window functions can be used…
Window properties
Filter properties
Fixed windows:
Fall 2008
Rectangular:
Hanning:
Hamming:
Blackman:
(11.18.1)
(11.18.2)
(11.18.3)
(11.18.4)
Fall 2008
Kaiser window:
Note: if = 0, WnK = WnR.
Adjustable windows:
Fall 2008
Properties:
Kaiser window is the most frequently used for the FIR filter design.
Hanning
Hamming
Blackman
Fall 2008
Stop-band attenuation:
Order estimate:
Adjustable parameter:
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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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:
Fall 2008
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)
= 0.5:
Fall 2008
Evaluating IDFT:
Therefore, we can compute the filter coefficients from the specified M frequency samples.
(11.24.1)
(11.24.2)
Since hn is real:
Since hn 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)
Fall 2008
We can rewrite the FIR filter frequency response (11.7.4) as:
Sampled at the frequencies
Fall 2008
Here:
For simplicity, we specify the following set of real frequency samples:
Therefore:
(11.26.1)
(11.26.2)
(11.26.3)
Fall 2008
Fall 2008
Fall 2008
- 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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
Fall 2008
Fall 2008
Fall 2008
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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
The transition band sample(s) “optimized” experimentally are:
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.
# of TB samples
~ 40
T2
~ 60
T3
[0.025779 0.251635 0.723071] [0.030957 0.27557 0.744348] Note: only one of them is correct.
~ 80
T4
Fall 2008
4. Optimal equiripple design
We are interested in a LP filter satisfying the following requirements:
Considering four FIR types:
The real-valued frequency response:
Fall 2008
The real-valued frequency response:
Fall 2008
The real-valued frequency response:
Fall 2008
The real-valued frequency response:
Fall 2008
4. Optimal equiripple design
Therefore, we can express the frequency response for all FIR types as:
Where:
(11.39.1)
(11.39.2)
Fall 2008
If s < p – bigger error in the passband is allowed.
(11.40.1)
(11.40.2)
We can compute and compare it to . Adjusting P() and selecting filter type, we can obtain the desired frequency characteristic.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
Where the modified weighting function and the modified desired frequency response are:
(11.41.2)
(11.41.3)
Fall 2008
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)
(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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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)
Fall 2008
4. Optimal equiripple design: Example
Example 11.2: design a LPF. Since both the desired frequency response Hdr 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 Hr(e j), i.e., where the frequency response meets the specified error tolerance. Since Hr(e j) is a polynomial of degree L:
(11.44.1)
(11.44.2)
Hr(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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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
Fall 2008
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):
Guess the set of L + 1 extremal frequencies;
Solve for {k} and ;
Determine the error function as in (11.39.1);
Determine the new set of L + 1 extremal frequencies and go to 2)…
Keep running until E(e j) - convergence.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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)
Fall 2008
4. Optimal equiripple design
Since we know that the polynomial at the points xn = 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)
Fall 2008
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)
Fall 2008
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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
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
ELEN 5346/4304 DSP and Filter Design
Fall 2008
LPF:
HPF:
BPF:
BSF:
(11.52.1)
(11.52.2)
(11.52.3)
(11.52.4)
1
0