You are on page 1of 44

10.

Design of FIR filters

The filter design problem

FIR filters with linear phase

Design of FIR filters by windowing

10-1
10. Design of FIR filters

The filter design problem

FIR filters with linear phase

Design of FIR filters by windowing

10-2
The filter design problem

filter design: finding a practically realizable filter whose frequency response


best approximates the desired magnitude and phase responses
within specified tolerances

PM
k=0 bk z −k
IIR filters: H(z) = P N
(rational transfer function)
1+ k=1 ak z −k
PM
FIR filters: H(z) = k=0 bk z −k (polynomial transfer function)

the design of FIR filters requires finding a polynomial approximating function


the design of IIR filters requires finding a rational approximating function
10-3
Five stages of the filter design problem

1. specification: specify the desired frequency response function characteristics


to address the needs of a specific application

2. approximation: approximate the desired specifications (frequency response)


by a polynomial or rational frequency response function (with minimum
computational complexity)

3. quantization: quantize filter coefficients to the required number of bits for


a given processor

4. verification: verify the performance by simulation or testing with real data

5. implementation: develop structure of the filter in hardware or software

10-4
Filter specifications

ideal frequency-selective filter:


either pass or eliminate a region of the input spectrum perfectly
have abrupt transitions between passbands and stopbands

practical filters differ from ideal filters in three respects:


the passband responses are not perfectly flat
the stopband responses cannot completely reject (eliminate) bands of
frequencies
the transition between passband and stop band regions
takes place over a finite transition band

10-5
Absolute specifications: example for a lowpass filter

passband: 1 − δp ≤ |H(ejω )| ≤ 1 + δp , 0 ≤ ω ≤ ωp

stopband: |H(ejω )| ≤ δs , ωs ≤ ω ≤ π
10-6
Relative specifications: example for a lowpass filter

− passband ripple:
 
1+δ
Ap , 20 log10 1−δpp > 0(≈ 0)

stopband ripple:
 
− 1+δp
As , 20 log10 δs
> 0( 1)

1 − δp
passband: ≤ |H(ejω )| ≤ 1, 0 ≤ ω ≤ ωp
1 + δp
δs
stopband: |H(ejω )| ≤ , ωs ≤ ω ≤ π
1 + δp
10-7
Relative specifications: example for a lowpass filter

− passband ripple:
 
1+δ
Ap , 20 log10 1−δpp > 0(≈ 0)

stopband ripple:
 
− 1+δp
As , 20 log10 δs
> 0( 1)

passband: −Ap ≤ 20 log10 (|H(ejω )|) ≤ 0, 0 ≤ ω ≤ ωp

stopband: 20 log10 (|H(ejω )|) ≤ −As , ωs ≤ ω ≤ π


10-8
Filter approximation

consider an ideal filter with hd [n] and Hd (ejω )

we want to find a practical filter H(ejω ) which approximates


the desired filter Hd (ejω ) according to design specifications

a practical filter should be causal and stable (⇒ Paley-Wiener theorem)


a practical filter should have a finite-order rational transfer function
PM
k=0 bk z −k
H(z) = P N
1+ k=1 ak z −k

10-9
Paley–Wiener theorem

if h[n] has finite energy and h[n] = 0 for n < 0, then


Z π

ln H(e ) dω < ∞ (∗)

−π


conversely, if H(ejω ) is square integrable and the integral (∗) is finite, then
we can obtain a phase response ∠H(ejω ) so that the filter H(ejω ) is causal;
the solution ∠H(ejω ) is unique if H(z) is minimum phase

consequence: stability and causality requirements have crucial implications


on the characteristics of H(ejω )

10-10
Implications of the Paley–Wiener theorem

the frequency response of a stable and causal system cannot be zero


over any finite band of frequencies because (the integral becomes infinite)
hence, any stable ideal frequency-selective filter must be noncausal


given the magnitude response H(ejω ) of a causal and stable system,
we cannot assign its phase response ∠H(ejω ) arbitrarily

1. impose constraints on the phase response, e.g. ∠H(ejω ) = −αω, and


obtain a filter whose magnitude response satisfies the design specifications

2. obtain a filter whose magnitude response satisfies the design specifications


irrespective of the resulting phase

10-11
Optimality criteria for filter design

we want to find a rational transfer function H(z) such that



the magnitude response H(ejω ) or the phase response ∠H(ejω )
approximate the shape of some ideal filter response

the coefficients of H(z) obtained depend on the criterion


used to determine what is considered an optimum approximation

we consider the following three criteria:


minimum mean-squared-error approximation
minimax approximation (aka best uniform, aka Chebyshev)
maximally-flat approximation

10-12
Mean-Squared-Error (MSE) approximation

we want to minimize the mean-square error


 Z 2 1/2
1 jω jω
E2 , Hd (e ) − H(e ) dω

2π B

where B is the frequency interval of interest


(usually, union of all passbands and stopbands)

if some frequencies are more important than others,


we could use a weighting function Wf (ejω ) ≥ 0 to weight the error

10-13
Minimax approximation

motivations: the MSE measures the average error in the interval B;


a small MSE does not preclude the possibility of large
errors at individual frequencies ;
in some applications, it is very important that
the error be small at all frequencies of the interval B

we want to minimize the maximum absolute deviation



E∞ , max Hd (ejω ) − H(ejω )

ω∈B

10-14
Maximally-flat approximation
(truncated Taylor series expansions)
2 2
we want A(ω) , H(ejω ) very close to Ad (ω) , Hd (ejω ) at ω = ω0
(1) (2)
Ad (ω0 ) A (ω0 )
Ad (ω) = Ad (ω0 ) + (ω − ω0 ) + d (ω − ω0 )2 + · · ·
1! 2!
A(1) (ω0 ) A(2) (ω0 )
A(ω) = A(ω0 ) + (ω − ω0 ) + (ω − ω0 )2 + · · ·
1! 2!

the approximation will be very good at ω = ω0 if A(ω0 ) = Ad (ω0 ) and


if as many derivatives as possible are equal

10-15
Maximally-flat approximation
(truncated Taylor series expansions)

if two functions and their first (m − 1) slopes are equal at ω = ω0 , then


(m)
Ad (ω0 ) − A(m) (ω0 )
E(ω) , Ad (ω) − A(ω) = (ω − ω0 )m + · · ·
m!

if all possible derivatives are equal,


the error function is completely flat at ω = ω0

if m is finite,
the approximation is optimum according to the maximally flat criterion

10-16
10. Design of FIR filters

The filter design problem

FIR filters with linear phase

Design of FIR filters by windowing

10-17
Ideal lowpass filter with linear phase


e−jαω , if |ω| < ωc
frequency response: Hlp (ejω ) =
0, if ωc < |ω| ≤ π


sin ωc (n − α) sin Ωc (t − αT )
= hclp (t) t=nT

impulse response: hlp [n] = =
π(n − α) π(t − αT ) t=nT

[with cutoff frequency Ωc = ωc /T ]

the signal hclp (t) is symmetric about t = αT for any value of α

is the sequence hlp [n] = hclp (nT ) also symmetric? not for every value of α

10-18
Ideal lowpass filter with linear phase

1. α is an integer:
hlp [n] is symmetric about n = α

2. 2α is an integer:
hlp [n] is symmetric about the middle
between α − 1/2 and α + 1/2

3. 2α is not an integer:
there is no symmetry at all
(because of misalignment between
CT impulse response and sampling grid)
10-19
Causal FIR filters with linear phase

consider a causal FIR filter of order M


M
X M
X
y[n] = h[k]x[n − k] ⇒ H(ejω ) = h[n]e−jωk
k=0 n=0

four types of interest:

even symmetry odd symmetry


(h[n] = h[M − n]) (h[n] = −h[M − n])

M even type I type III

M odd type II type IV

10-20
Magnitude response vs amplitude response

frequency response of a linear-phase FIR filter can be written in two ways:

jω jω
H(ejω ) = |H(ejω )|ej∠H(e )
= A(ejω )ejΨ(e )

where

|H(ejω )|: magnitude response (real and even, only nonnegative)


∠H(ejω ): wrapped (broken) phase response (piecewise linear)

A(ejω ): amplitude response (real and even, both positive and negative)
Ψ(ejω ): unwrapped (unbroken) phase response (truly linear)

10-21
Illustration on linear-phase FIR filters

10-22
Type-I FIR linear-phase filters
even symmetry h[n] = h[M − n] with even order M

H(ejω ) = h[0] + h[1]e−jω + h[2]e−j2ω + h[3]e−j3ω + h[4]e−j4ω

= e−j2ω h[0]ej2ω + h[1]ejω + h[2] + h[3]e−jω + h[4]e−j2ω




= e−j2ω (2h[0] cos 2ω + 2h[1] cos ω + h[2])

= e−j2ω (a[2] cos 2ω + a[1] cos ω + a[0])

in general, we have  
M/2
X
H(ejω ) =  a[k] cos ωk e−jωM/2 , A(ejω )e−jωM/2 ,
k=0
where A(ejω ) is a real, even, and periodic with coefficients given by

a[0] = h[M/2], a[k] = 2h[(M/2) − k], k = 1, 2, . . . , M/2


10-23
Type-II FIR linear-phase filters
even symmetry h[n] = h[M − n] with odd order M

H(ejω ) = h[0] + h[1]e−jω + h[2]e−j2ω + h[3]e−j3ω + h[4]e−j4ω + h[5]e−j5ω

= h[0] + h[1]e−jω + h[2]e−j2ω + h[2]e−j3ω + h[1]e−j4ω + h[0]e−j5ω

= (2h[2] cos(ω/2) + 2h[1] cos(3ω/2) + 2h[0] cos(5ω/2)) e−j(5/2)ω

= (b[1] cos(ω/2) + b[2] cos(3ω/2) + b[3] cos(5ω/2)) e−j(5/2)ω

in general, wehave 
(M +1)/2   
X 1  e−jωM/2 , A(ejω )e−jωM/2 ,
H(ejω ) =  b[k] cos ω k −
2
k=1
where A(ejω ) is a real, even, and periodic with coefficients given by

b[k] = 2h[(M + 1)/2 − k], k = 1, 2, . . . , (M + 1)/2


10-24
Type-II FIR linear-phase filters
even symmetry h[n] = h[M − n] with odd order M

using the identity 2 cos α cos β = cos(α + β) − cos(α − β), we have


−1)/2
 ω  (MX
A(ejω ) = cos b̃[k] cos ωk,
2
k=0
| {z }
≡ type-I
  
1

2 
 b̃[1] + 2b̃[0] if k = 1
 
where b[k] = 21 b̃[k] + b̃[k − 1] if 2 ≤ k ≤ (M − 1)/2


1

2
b̃[(M − 1)/2] if k = (M + 1)/2

at ω = π: A(ejω ) = 0, independent of b̃[k] or h[k]


⇒ cannot be satisfactorily approximated with a type-II filter
10-25
Type-III FIR linear-phase filters
odd symmetry h[n] = −h[M − n] with even order M

in general, we have
 
M/2
X
H(ejω ) =  c[k] sin ωk je−jωM/2 , jA(ejω )e−jωM/2 ,
k=1


where A(e ) is a real, odd, and periodic with coefficients given by

c[k] = 2h[M/2 − k], k = 1, 2, . . . , M/2

10-26
Type-III FIR linear-phase filters
odd symmetry h[n] = −h[M − n] with even order M

using the identity 2 sin α cos β = sin(α + β) + sin(α − β), we have


M/2
X
A(ejω ) = sin ω c̃[k] cos ωk,
k=0
| {z }
≡ type-I

1
 2 (2c̃[0] − c̃[1]) if k = 1



where c[k] = 21 (c̃[k − 1] − c̃[k]) if 2 ≤ k ≤ (M − 1)/2


 1 c̃[(M/2) − 1]

if k = M/2
2

at ω = 0 and ω = π: A(ejω ) = 0, independent of c̃[k] or h[k]


the frequency response is imaginary
⇒ type-III filter are most suitable for the design of differentiators
10-27
Type-IV FIR linear-phase filters
odd symmetry h[n] = −h[M − n] with odd order M

in general, we have
 
(M +1)/2   
X 1  −jωM/2
H(ejω ) =  d[k] sin ω k − je , jA(ejω )e−jωM/2
2
k=1


where A(e ) is a real, odd, and periodic with coefficients given by

d[k] = 2h[(M + 1)/2 − k], k = 1, 2, . . . , (M + 1)/2

10-28
Type-IV FIR linear-phase filters
odd symmetry h[n] = −h[M − n] with odd order M

using the identity 2 sin α cos β = sin(α + β) + sin(α − β), we have


−1)/2
 ω  (MX
A(ejω ) = sin ˜ cos ωk
d[k]
2
k=0
| {z }
≡ type-I
  
 1
2 ˜ − d[1]
d[0] ˜ if k = 1
2 

 
where ˜ − 1] − d[k]
d[k] = 21 d[k ˜ if 2 ≤ k ≤ (M − 1)/2


˜
1
d[(M − 1)/2] if k = (M + 1)/2

2

˜ or h[k]
at ω = 0: A(ejω ) = 0, independent of d[k]
the frequency response is imaginary
⇒ type-IV filter are most suitable for the design of differentiators
10-29
Amplitude response function of FIR filters with linear phase
[a[k], b[k], c[k], d[k] better suited for MSE approximation]

10-30
Unified representation

the function A(ejω ) can be expressed as the product of two terms

A(ejω ) = Q(ejω )P (ejω ),

where

Q(ejω ): fixed function of ω dependent on the type of the filter

P (ejω ): sum of cosines dependent on the filter coefficients

this representation unifies the design of the four types of FIR filter
with linear phase using the minimax criterion
10-31
Unified representation
˜ better suited for minimax approximation]
[ã[k], b̃[k], c̃[k], d[k]

10-32
10. Design of FIR filters

The filter design problem

FIR filters with linear phase

Design of FIR filters by windowing

10-33
Design of FIR filters by windowing

an easy way to obtain an FIR filter is


to truncate the impulse response of an IIR filter

⇒ the filter is optimum in the mean square error sense


but has unacceptable size ripples

an alternative way to obtain an FIR filter is


to apply a window to the impulse response of an IIR filter

⇒ the filter has reduced size ripples (to a desired level)


but is no longer optimum in the mean square error sense

10-34
Direct truncation of an ideal impulse response


X
ideal IIR: Hd (ejω ) = hd [n]e−jωn
n=−∞

actual FIR: h[n], 0 ≤ n ≤ M, approximates hd [n] by minimizing the MSE


Z π
1
2
2 = jω jω
Hd (e ) − H(e ) dω

2π −π
M
X −1
X ∞
X
= (hd [n] − h[n])2 + h2d [n] + h2d [n]
n=0 n=−∞ n=M +1

the optimal solution is given by



hd [n] if 0 ≤ n ≤ M
h[n] =
0 otherwise

10-35
Effect of windowing in the frequency domain


1, if 0 ≤ n ≤ M
impulse response: h[n] = hd [n]w[n], with w[n] =
0, otherwise
Z π
1
frequency response: H(ejω ) = Hd (ejθ )W (ej(ω−θ) )dθ
2π −π

the approximation frequency response H(ejω ) is the periodic convolution of


the desired ideal frequency response with the Fourier transform of the window
M
X 1 − e−jω(M +1) sin(ω(M + 1)/2) −jωM/2
W (ejω ) = e−jωn = = e
n=0
1 − e−jω sin(ω/2)

10-36
Effect of windowing in the frequency domain

(
1, if |ω| ≤ ωc
Ad (ejω ) ,
0, if ωc < |ω| ≤ π

sin(ω(M + 1)/2)
AW (ejω ) ,
sin(ω/2)

10-37
Effect of windowing in the frequency domain

the convolution smears the ideal response


the main lobe produces the transition band
the side lobes produce passband and stopband ripples
with the same maximum size
10-38
Smoothing the frequency response using fixed windows

using nonrectangular windows to obtain a less abrupt truncation reduces


the height of the ripples at the expense of a wider transition band

windows are always symmetric, that is,



w[M − n], if 0 ≤ n ≤ M ,
w[n] =
0, otherwise

the windowed impulse response h[n] = w[n]hd [n] has the same symmetry
with the ideal impulse response hd [n]

windowing a FIR filter with linear phase does not change its type
10-39
Smoothing the frequency response using fixed windows

10-40
Comparison of fixed (attenuation) windows

ripple does not depend on cutoff frequency ωc or filter order M


transition band ∆ω is proportional to 1/M
10-41
FIR filter design using fixed windows

1. set δ = min{δp , δs } because the window method inherently gives δp = δs


2. find the cutoff frequency of the underlying LPF: ωc = (ωp + ωs )/2
3. determine the design parameters A = −20 log10 δ and ∆ω = ωs − ωp
4. select a window function that gives the smallest stopband attenuation
that is more than or equal to As ; determine the window length of
L = M + 1 that satisfies the exact transition width ∆ω
sin(ωc (n−M/2))
5. determine the impulse response of the ideal LPF by hd [n] = π(n−M/2)

6. compute the impulse response h[n] = hd [n]w[n] using the chosen window
7. check whether the design filter satisfies the predicted specifications; if not,
increase the order M and go back to 5.

10-42
Example

design a lowpass linear-phase FIR filter to satisfy:

ωp = 0.25π, ωs = 0.35π, Ap = 0.1 dB, As = 50 dB

1. δp = 0.0058 and δs = 0.0032; hence, δ = 0.0032


2. ωc = (ωp + ωs )/2 = 0.3π
3. ∆ω = ωs − ωp = 0.1π
6.6π
4. we select the Hamming window (53 dB); ∆ω ≈ L
= 0.1π ⇒ L = 66;
we choose L = 67 or M = 66 to obtain a type-I filter which gives α = 33
5. now, we can obtain h[n] = hd [n]w[n]
10-43
Example

10-44

You might also like