Professional Documents
Culture Documents
Fir Filter Design: The Window Design Method
Fir Filter Design: The Window Design Method
is retiring! Community-created content will remain viewable for two years, and then be moved to Internet Archive. Learn more
(https://openstax.org/blog/saying-goodbye-cnx)
Books
The design of a FIR filter starts with its specifications in either discrete-time domain or DTFT frequency domain, or both. In the time domain, the
design objective is the impulse response. In the frequency domain, the requirement is on various parameters of the magnitude response, shown
in Fig.5.8 for a lowpass filter. Important parameters are band edge frequencies ωp and ωs , passband
[0, ωp ] , transition band Δω = ωs − ωp , stopband , cutoff frequency ωc = (ωp + ωc )/2 , passband ripple (or deviation) δp and stopband ripple δs .
The two ripples are usually assumed equal . Notice that for ideal (desired) filter, the passband frequency magnitude is normalized to 1 and the
stopband to 0 , and the frequency response of the designed filter oscillates between the high amplitude of 1 or the low amplitude of 0.
Figure illustrates the specifications of bandpass filter. Here there are two sets of edge frequencies, lower and upper. The rising bandwith Δ ωl and
the falling bandwidth Δ ωu are usually assumed equal.
Even the initial requirement is imposed on magnitude response but we must design the filter having linear phase or generalized linear phase.
From the filter specifications, the first step is to choose between FIR and IIR filters based on their advantages and disadvantages. This chapter
only concerns FIR filters. The next step is to select the proper linear phase FIR filters (section 5.2.3). A rather complete procedure for the design
of FIR filters are as follows.
Specifications of the filter
Choosing an appropriate linear phase filter type (section 5.2.3)
Choosing the mothod of design such as window, optimal, frequency sampling…
Calculation the filter coefficients (impulse response)
Finding suitable structure
Analysis of the finite wordlength effects (chapter 7)
Implementation of the filter in hardware and/or software (chapter 7).Fig.5.9: Bandpass filter specifications
Figure 2. Bandpass filter specifications
Fixed windows
The impulse response of ideal filters is infinite duration (IIR). We cannot evaluate the corresponding frequency response and, especially,
implement the filter by hardware and/or software. Thus we must truncate the impulse response at both ends with respect to the central. Even we
truncate the impulse response when it is small enough, but such a sudden cutoff will cause some undesired effects. The window method will
reduce them.
In the time domain, windowing means that the we multiply the desired (usually ideal) infinite duration impulse response hd (n ) by a
finite duration window (or window function) w (n ) to get a soft truncation. The resulted impulse response h (n ) of the designed filter is the
product
h (n ) = hd (n )w (n ) , 0 ≤ n ≤ M
Here we assume that all desired impulse responses and windows are causal, from n = 0 to n = M , i.e. window length is M + 1 samples (time
indices). Many authors start the design with hd (n ) and w (n ) bi-sided (noncausal), i.e. defined in the interval then shift to the right M /2 indices to
make them causal.
Multiplying in time domain corresponds to convolution in frequency domain. Thus the frequency response of the designed filter (corresponding to
the windowed impulse response h (n ) ) is
H (ω ) = Hd (ω ) ∗ W (ω ) = 1 ∫ π−π Hd (ω ' )W (ω − ω ' )dω '
2π
In the window design method , we first evaluate the desired filter impulse response hd (n ) from the given desired frequency response Hd (ω ) , and
then apply an appropriate window . Thus the method should be called the Fourier – window method.
Retangular window
Actually, the sudden truncation mentioned earlier is the simplest window called rectangular window, defined as (Figure)
w (n ) = 1 , 0 ≤ n ≤ M
0 , otherwise
This is the same as Equation (3.54) when replacing M by 2N . Also, instead of the above expression we can use the sum of cosines (Equations
(3.46), (3.53)). W (ω ) has includes a phase factor showing the time shift of a two-sided symmetric window to a causal window. The magnitude
and phase responses are, respectively,
Figure 4. Normalized frequency response of rectangular window for M = 30 and 50
| sin ω (M + 1)/2 |
|W (ω )| = || | , ω ≠ 0
|
| sin ω /2 |
M + 1 , ω = 0
M
Φ (ω ) = − ω +β
2
where β is 0 or π as discussed in previous section. Thus the window is linear phase. Fig.3.27 illustrates the variation of the amplitude of
∣ W (ω ) ∣ (remember to replace 2N by M ). It is maximum and equals to M + 1 at ω = 0 . The zero-crossing points are multiples of 2π/(M + 1)
. The response consists of a main lobe and many sidelobes. As M gets larger the main-lobe gets smaller, and there are more sidelobes, also
narrower but the amplitude of the first sidelobe remains the same (Fig.5.11). As M → ∞ , W (ω ) tends to be an unit sample δ (ω ) .
Figure 5. Magnitude response of designed lowpass filter when using rectangular window with M = 44
The oscillatory ∣ W (ω ) ∣ when convolved with the ideal lowpass response Hd (ω ) will result in a response H (ω ) having a non-zero transition
width and ripples is both the passband and stopband. Fig.5.12 shows the designed lowpass filter when using rectangular window having M = 44
to abruptly truncate the impulse response of an ideal lowpass filter with cutoff frequency ωc = π /2 . Fig.5.13 shows the magnitude in linear scale
for two case of filter order, M = 10 and M = 18.
In order that H (ω ) approaches Hd (ω ) the rectangular window must be of infinite duration, i.e. we must take into account the whole impulse
response without truncation. In frequency domain this means W (ω ) is an unit sample δ (ω ) as said. We can reason in the reverse direction:
Since H (ω ) = Hd (ω ) ∗ δ (ω ) = Hd (ω ) then δ (ω ) must be a unit sample and the windows must be of infinite duration. When we simulate H (ω )
on a computer using Maltlab sofware, or else, with M in the hundreds we will still see the non-zero transition width and ripples due to the Gibbs
phenomenon (section 3.1.4). An infinitely long windows is not practical, so the idea is to look for finite duration windows which perform better
than the rectangular.
Actually in examples 5.2.1 and 5.2.2 the truncation of the impulse responses of the ideal filters meant the rectangular window had been applied.
Figure 6. Magnitude response of designed filter for M = 10 and M = 18
Other windows
The Gibbs phenomenon can be reduced considerably by the use of a softer (less abrupt) truncation, i.e. by tapering the rectangular smootly to
zero at both ends. Unfortunately, the reduction in amplitude of sidelobes of H (ω ) is accompanied by a widening of its mainlobe. For comparision,
the window responses W (ω ) are usually plotted in dB scale.
Several smooth window functions have been proposed and used. It might come to our mind that the first applicant would be the triangular
window, also called Bartlett window , depicted in Fig.5.14. From the figure we can write the window function ( table 5.1). Table 5.1 lists
common fixed windows and Fig.5.15 plots their functions. Fig.5.16 plots the dB magnitude for and Fig.5.17 for M = 50.The first sidelobe is at
-25dB compared to the -13dB of the corresponding (same length) rectangular window. However the mainlobe width is about twice as large.
Figure 8. Common window plotted as function of continuous time n (whereas actual windows are function of discrete index n)
The sidelobe of the triangular window is still high because the tapering is still rather coarse. For smoother tapering, cosinusoid is incorporated
into the window function. This observation has led to the three well known windows: Hanning (or von Hann), Hamming, and Blackman, all defined
in the interval 0 ≤ n ≤ M , otherwise zero (table 5.1). We can check that the functions are normalized (peak value of 1 at n = M /2 ) and zero at
both ends except the rectangular and the Hamming (0.08 instead of 0). Besides, there are many other less-used fixed windows.
Notice that all windows mentioned, from rectangular to Blackman, are simple functions easily evaluated, and their frequency responses
concentrate around ω = 0 (the mainlobe) as expected. Also notice that all the windows mentioned are symmetric about the mid-point
n = M /2 , this when combined with the symmetry or antisymmetry of the filter’s impulse response will make the corresponding designed filter
linear phase or generalized linear phase.
Figure 9. dB magnitude frequency response of fixed windows for M = 20 (a) Bartlett, (b) Hanning, (c) Hamming, (d) Blackman
Figure 10. dB magnitude frequency response of various windows for M = 50 (a) Bartlett, (b) Hanning, (c) Hamming, (d) Blackman
Table 5.2 lists various features of common windows for comparison. The passband ripple and the stopband ripple δs and the stopband ripple δs ,
are taken equal (the smaller of the two):
A = − 20log 10[min (δp , δs )]
Fig.5.16, Fig.5.17 and Table 5.2 show that no window is the best in all aspects but there is a tradeoff of features, and the choice of an
appropriate window depending on our requirement. For smallest mainlobe width it’s the rectangular window, for best sidelobe attenuation it’s the
Blackman. In between, the Hamming is a good choice. The Bartlett is the transition from the rectangular to the other windows. See section 5.3.3
for design examples.
M /2
w (n ) = , 0≤n ≤M
I0(β )
where I0(x ) is the modified zeroth-order Bessel function, computed by a power series expansion:
∞ ⎡ x (2)k ⎤2 2 2 2 2 4
I0(x ) = 1 + ∑ ⎢ ⎥ = 1 + x + 12 ⋅ x ⋅ x + 12 ⋅ x ⋅ x + ⋅
k = 1⎣ k ! ⎦ 4 2 4 4 z 4 16
The upper limit of the summation does not need to be too large, say about 20 at the most.
Figure 11. (a) Kaiser window for β = 0, 3 and 6 and M = 20, (b) Magnitude response corresponding to the windows in (a), (c) magnitude response for
β = 6 and M = 10, 20,
For β = 0 both the numerator and denominator are 1 and the Kaiser window becomes the rectangular window, and for β = 5.44 it is near to the
Hamming window. The parameter β is so chosen that the magnitude response of the filter lies in the allowed region (see Fig.5.1). Fig.5.18 shows
the Kaiser for various values of β and M . Notice that the Kaiser is also symmetric. It has minimum stopband attenuation from 50dB (for
β = 4.54 ) to 90dB (for β = 8.96 ), so we can choose a Kaiser window to have maximum stopband atternuation equal to the Blackman window
(74, Table 5.2) or higher.
For ideal filters (Fig.5.1 and Fig.5.2) the Kaiser window has equal ripple δ in both the passband and stopband. For real filters the ripples are
slightly different . In design we take the common ripple as δ = min(δp , δs ) of the desired values δp , δs . As said earlier, actually δ is usually
specified in term of dBs: A = −20log10δ , for example δ = 0.01 then A = 40dB , δ = 0.001 then A = 60dB . Since δ is a fraction of 1 then A is
always ponsitive.
Kaiser has developed empirical formulae and guide for the application of the window. Following is design steps for lowpass filters (similarly for
other frequency selective filters).
2/Evaluate the minimum ripple A = −20log10[min(δp , δs )] , the cutoff frequency ωc = (ωp + ωs )/2 , the transition width △ ω = ωs − ωp
6/ Compute the impulse response hd (n ) of the desired filter which is linear phase
8/ Find the frequency response H (ω ) = I D T F T [h (n )] to check with specifications. For bandpass filter the two transition bandwidths are usually
equal, if not we take the smaller one.
Design examples
Design a linear phase lowpass filter using the Hamming window to meet the specifications
Cutoff frequency 2.5 kHz
Transition width 1.65 kHz
Stopband attenuation >50dB
Sampling frequency 10kHz
Solution
The relation between the analog linear frequency F samples/sec (or Hz) and the digital angular frequency ω radians/sample is (Equation 1.40)
is
F
ω = 2π
fs
Δω = 6.6π ⇒ M=
6.6π = 20
M 0.33π
Now we compute the causal impulse response hLP(n ) of ideal lowpass filter (Equation (5.32)) for 0 ≤ n ≤ 20 . Notice that for M even and h (n )
symmetric we have linear phase FIR-1 (Fig.5.4a). The result is plotted in Fig.5.19a.
w (n ) = 0.54 − 0.46cos 2π n , 0 ≤ n ≤ M = 20
M
We can evaluale w(n) and hLP (n ) separately as above then take the product, or evaluate the product directly . The result is plotted in Fig.5.19c.
We then take the inverse transform of h (n ) to get the frequency response H (ω ) :
∞ M
H (ω ) = ∑ h (n )e − jωn = ∑ h (n )e − jωn , M = 20
n= − ∞ n =0
We need ro extract a low frequency signal having bandwidth 200Hz and center frequency 300Hz from a blackground noise. Design a
bandpass filter having transition width 100Hz, passband ripple 40dB, stopband ripple 60dB. The sampling frequency is 1200Hz.
Solution
The passband of the signal is from 300 – 200/2 to 300 + 200/2, i.e. from 200Hz to 400Hz. We are to design a bandpass FIR filter to meet the
specifications
Passband: 200Hz
Transition width: 100Hz
Figure 12. Example(linear phase lowpass filter with ωc = 0.5π , Δ ω = 0.33π ) using the Hamming window
Figure 13. Example(linear phase bandpass filter using Blackman window
From Table 5.2 see that only the Blackman window can satisfy the stopband ripple (so can the Kaiser window, see next subsection). Since the
passband and stopband attenuations are different, we take the smaller one in the design, i.e. A = 60dB. The transition width and the filter order
are, respectively,
100 π
Δω = 2π =
1200 6
M = 11.1π = 66.6 ≈ 67
π /6
where
400 2π
ωu = 2π =
1200 3
200 π
ωl = 2π =
1200 3
Since M is odd we have linear phase type 2 (FIR-2) . The designed impulse response is
h (n ) = hBP(n )w (n )
We then take the inverse transform of h(n) to get or the frequency response of the designed filter (Fig.5.20).
Design a highpass FIR filter using Kaiser window to meet the specifications :
Cutoff frequency 2,5 kHz
Transition width 0.5 kHz
Passband ripple 0.001
Stopband attenuation 40dB
Sampling frequency 10kHz
Solution
First let’s derive the expression of the impule response of ideal highpass filter (Fig.5.1b) with generalized linear phase (Fig.5.4) (Fig.5.1b) with
generalized linear phase (Fig.5.4). The frequency response of the causal highpass filter in the interval ω = [0, π ] is
HH P (ω ) = 0, 0 ≤ ω ≤ ωc
M
−j ω
e 2 , ω <ω ≤π
c
or related to the frequency response of the lowpass filter HLP(ω ) (Equation (5.32)) as
M
−j ω
HHP(ω ) = e 2 − HLP(ω )
Taking the inverse DTFT of either above expression we will get the impulse response of the ideal highpass filter
sin π (n − M /2) sin ωc (n − M /2)
h H P ()n = − , n ≠ 0
π (n − M /2) π (n − M /2)
ω
1 − c , n = 0
π
Notice that we cannot just shift the result of the two-sided symmetric impulse response Equation (5.10a) to get the above causal result (but must
replace δ (n ) by sinπn /πn before shifting).
1 − ( n − 36 ) }
5.65 2
I0{
36
W (n ) =
I0(5.65)
The impulse response of the FIR-1 highpass filter hH P (n ) is computed for 0 ≤ n ≤ 66 , and the designed impulse response is
h (n ) = hHP(n )w (n )
As usual, the frequency response is the inverse DTFT of above impulse response.. Using Matlab we can simulate all the responses. ■
This error varies with frequency and is a complex quantity , the same as the frequency response. We are interested in the error amplitude, so we
take the square
| ε (ω ) | 2 = Re 2ε (ω ) + Im 2ε (ω ) = ε (ω )ε * (ω )
The problem is to find H (ω ) so that the mean square error H (ω ) is smallest (i.e. least mean square - LMS). Because the frequency response
H (ω ) can be expressed in term of the designed filter impulse response h(n) , we thus look for the filter impulse response for LMS error. To this
end we take the derivative d ε̄ /d h (n ) and equate it to zero to find the root of h(n) for the minimum
ε̄
. After some mathematics (not presented here) , we will get the impulse response
h (n ) = 1 ∫ π− π Hd (ω )e jωn d ω = hd (n )
2π
This result means that when we start the design by evaluating the impulse response from the given (desired) filter frequency response then we
will get the LMS error (i.e. no other design method can give a smaller mean square error) .
In LMS error we emphasized the large errors ( at local frequencies). This criterion is not always adopted , other criterion may be more privileged,
such as the transition width must be as narrow as possible, or the error must be distributed evenly in both the passband and the stopband…
Digital differentiator
In digital signal processing , sometimes we need to take the differentiation or integration of a signal . For example the differentiation (derivation)
of displacement is speed, and the differentiation of speed is acceleration. It is interesting that the former can just be realized by a FIR filter or by
an IIR filter, whereas the latter by an IIR filter. In this section we will discuss digital differentiators (Fig.5.2) designed by linear phase FIR-3 and
FIR-4 associated with windowing. Other FIR design method , such as the optimal method discussed in the subsequent section , can also be used.
In an analog differentiator the output signal y(t) is related to the input signal x(t) by
d x (t )
y (t ) =
dt
For a LTI (LSI) digital system having frequency response (i.e.DTFT) H (ω ) , an input x (n ) = e jnω will give the output H (ω )e jωn (section 3.7.3):
y (n ) = H (ω )e jωn
This is the frequency response of ideal digital differentiator. The response is purely imaginary, the magnitude response | H (ω ) | is proportional to
the frequency and the phase response Φ (ω ) is π /2 , independent of frequency (Fig.5.2) . Thus differentiators are generalized linear phase
(Equation (5.17) with α = 0 , β = π /2 ). Fig.5.21 shows the variation of | H (ω ) | .
Even looked so simple but the such a differentiator cannot be realized exactly in practice . Thus approximate ciruits are used, the simplest of
which is the first order differentiator which is just the difference
y (n ) = x (n ) − x (n − 1)
whose magnitude is
| | ω
| H (ω ) | = [ (1 − cos ω )2 + sin 2ω ] 1/2 = 2sin
|| || 2
This is plotted in Fig.5.21 . The approximation is surprisingly good especially at low frequency. Notice that for small ,
H (ω ) ≈ (1 − 1) + j ω = j ω (s m a l l ω )
Actually a differentiator is usually designed to use at the low frequency because the high response at high frequency will enhance noise. This
again means that the simple first order differentiator is very good. The linear phase FIR filter implementing the differentiator is of FIR-4 type (
H (ω ) = 0 a t ω = 0 a n d ≠ 0 a t ω = π )
In order to reduce the high response at high frequency, the central differentiator is the candidate :
y (n ) = 0.5x (n ) − 0.5x (n − 2)
having frequency response
The response is also plotted in the same Fig.5.21. Notice also that H (ω ) ≈ 0 at low ω . The linear phase FIR filter implementing the differentiator
is of FIR-3 type ( H (ω ) = 0 at both ω = 0 and ω = π ).
Solution
Taking the inverse DTFT of the known frequency response H (ω ) = − j ω we will get the two-sided impulse response.
1 π
hD IF (n ) = ∫ − π Hd (ω )e jωn d ω
2π
1 ∫ π H (ω )cos ω n d ω + j 1 ∫ π H (ω )sin ωn d ω
=
2π − π 2π − π d
Figure 15. Example impulse response having M = 20 of ideal differentiator ((a) two-sided (noncausal), (b) causal)
Because Hd (ω ) is an odd function while cosine is even and sine is odd, we only need to take the last term of the above expression:
1 1
hD IF (n ) = j ∫ π− π Hd (ω )sin ω n d ω = − ∫ π0 ω sin ω n d ω
2π π
cos n π
= , n ≠ 0
n
0 , n = 0
or
1
hD IF (n ) = − , n = ± 1, ± 3, ± 5...
n
1 , n = ± 2, ± 4, ± 6...
n
0 , n =0
The last case is obtained by taking the original integral. Fig 5.22a depicts the impulse response which is of FIR-3.
2. We cannot just shift the noncausal result Equation (5.49a) M/2 time indices , i.e. by replacing n by n – M/2 , together the causal impulse
response. Let’s start from the frequency response of a causal linear phase differentiator ( the two-sided response j ω is delayed by M/2 samples):
M
−j ω
H (ω ) = j ω e 2 , − π ≤ω ≤π
When putting M/2 = 0 in above Equation we will get back Equation (5.49a) as expected.
In both impusle response (5.49a) and (5.50) we can notice that hD /F (n ) = − hD /F (M − n ) , thus the differentiator is linear phase type 3 when M is
even (Fig.5.4c) or type 4 when M is odd (Fig.5.4d).
3. Window length of 21 means M + 1 = 21 and the filter order is M = 20. We can use the two-sided impulse response in (a) and shift M/2 = 10
time indices to the future to get the causal response , or use the causal response in (b) . Fig.5.23a is the frequency response of the differentiator
with truncation (equivalent to using rectangular window), Fig.5.23b is the frequency response of the differentiator when using the Hamming
window. The optional method (later section) is a better method to design digital differentiator.
Figure 16. Example (magnitude response of differentiator for M = 20 when (a) using truncation (rectangular window) and (b) using the Hamming window)
Licensing (/license) Terms of Use (/tos) Accessibility Statement (https://openstax.org/accessibility-statement) Contact (/about/contact)
Supported by William & Flora Hewlett Foundation, Bill & Melinda Gates Foundation, Michelson 20MM Foundation, Maxfield Foundation, Open Society Foundations, and
Rice University. Powered by OpenStax CNX.
Advanced Placement® and AP® are trademarks registered and/or owned by the College Board, which was not involved in the production of, and does not endorse, this
site.
(http://creativecommons.org) © 1999-2020, Rice University. Except where otherwise noted, content created on this site is licensed under a
Creative Commons Attribution 4.0 License.