Professional Documents
Culture Documents
FIR Design
FIR Design
Gao Xinbo
School of E.E., Xidian Univ.
xbgao@ieee.org
http://see.xidian.edu.cn/teach/matlabdsp/
Introduction
In digital signal processing, there are two important types of syst
ems:
Digital filters: perform signal filtering in the time domain
Spectrum analyzers: provide signal representation in the frequency doma
in
In this and next chapter we will study several basic design algori
thms for both FIR and IIR filters.
These designs are mostly of the frequency selective type
Multiband lowpass, highpass, bandpass and bandstop filters
Introduction
In FIR filter design we will also consider systems like
differentiators or Hilbert transformers.
It is not frequency selective filters
Nevertheless follow the design techniques being considered.
We first begin with some preliminary issues related to design
philosophy and design specifications. These issues are
applicable to both FIR and IIR filter designs.
We will study FIR filter design algorithms in the rest of this
chapter.
Preliminaries
The design of a digital filter is carried out in three steps:
Specifications: they are determined by the applications
Approximations: once the specification are defined, we use
various concepts and mathematics that we studied so far to
come up with a filter description that approximates the given
set of specifications. (in detail)
Implementation: The product of the above step is a filter
description in the form of either a difference equation, or a
system function H(z), or an impulse response h(n). From this
description we implement the filter in hardware or through
software on a computer.
Specifications
Specifications are required in the frequency-domain in
terms of the desired magnitude and phase response of t
he filter. Generally a linear phase response in the passb
and is desirable.
In the case of FIR filters, It is possible to have exact linear p
hase.
In the case of IIR filters, a linear phase in the passband is not
achievable.
Hence we will consider magnitude-only specifications.
Magnitude Specifications
Absolute specifications
Provide a set of requirements on the magnitude response func
tion |H(ejw)|.
Generally used for FIR filters.
Relative specifications
Provide requirements in decibels (dB), given by
| H (e jw ) |
dB scale 20 log10 jw
0
| H (e ) |max
Passband ripple
Transition band
Stopband ripple
Absolute Specifications
Band [0,wp] is called the passband, and delta1 is the tol
erance (or ripple) that we are willing to accept in the id
eal passband response.
Band [ws,pi] is called the stopband, and delta2 is the co
rresponding tolerance (or ripple)
Band [wp, ws] is called the transition band, and there ar
e no restriction on the magnitude response in this band.
Relative (DB) Specifications
0
Rp
As
Relations between specifications
1 1
R p 20 log10 0 for passband
1 1
2
As 20 log10 0 for stopband
1 1
n 0 n 0
Which has (M-1) poles at the origin (trivial poles) and
M-1 zeros located anywhere in the z-plane. The
frequency response function is
M 1
H (e ) jw
h ( n ) e jwn
, w
n 0
Impulse Response h(n)
We impose a linear-phase constraint
H (e jw ) w, w
Where alpha is a constant phase delay. Then we
know from Ch6 that h(n) must be symmetric, that is
M 1
h(n) h( M 1 n), 0 n M 1, with
2
Hence h(n) is symmetric about alpha, which is the index
of symmetry. There are two possible types of symmetry:
A second type of linear-phase FIR filter
The phase response satisfy the condition
H (e jw ) w, w
Which is a straight line but not through the origin. In this
case alpha is not a constant phase delay, but
dH (e jw )
dw
Is constant, which is the group delay. Therefore alpha is a
constant group delay. In this case, as a group, frequencies
are delayed at a constant rate.
A second type of linear-phase FIR filter
For this type of linear phase one can show that
M 1
h(n) h( M 1 n), 0 n M 1, with ,
2 2
This means that the impulse response h(n) is antisymm
etric. The index of symmetry is still alpha=(M-1)/2.
Once again we have two possible types, one for M odd
and one for M even.
Figure P230
Frequency Response H(ejw)
When the case of symmetry and anti-symmetry are combined wi
th odd and even M, we obtain four types of linear phase FIR filt
ers. Frequency response functions for each of these types have s
ome peculiar expressions and shapes. To study these response,
we write H(ejw) as
j ( w ) M 1
H ( e ) H r (e )e
jw jw
; ,
2 2
Hr(ejw) is an amplitude response function and not a magnitude respon
se function.
The phase response associated with the magnitude response is a disco
ntinuous function, while that associated with the amplitude response i
s a continuous linear function.
Type-1 Linear-phase FIR filter:
Symmetrical impulse response, M odd
In this case, beta=0, alpha=(M-1)/2 is an integer, and h(n)=h(M-1-
n), 0<=n<=M-1. Then
( M 1) / 2 jw( M 1) / 2
H (e ) a(n) cos wn e
jw
n 0
M 1
a(0) h : the middle sample
2
M 1 M 3
a(n) 2h n , 1 n
2 2
( M 1) / 2
H r ( w) a(n) cos wn
n 0
Type-2 Linear-phase FIR filter:
Symmetrical impulse response, M even
In this case, beta=0, h(n)=h(M-1-n), 0<=n<=M-1, but alpha=(M-
1)/2 is not an integer, and then
M / 2 1 jw( M 1) / 2
H (e ) b(n) cos w n e
jw
n 1 2
M M
b(n) 2h n , n 1,2, ,
2 2
M /2
1
H r ( w) b(n) cosw n
n 1 2
Note that Hr(pi)=0, hence we cannot use this type for highpas
s or bandstop filters.
Type-3 Linear-phase FIR filter: Antisym
metric impulse response, M odd
In this case, beta=pi/2, alpha=(M-1)/2 is an integer, and h(n)=-h(M-
1-n), 0<=n<=M-1. Then
( M 1) / 2 j 2 M21 w
H (e ) c(n) sin wn e
jw
n0
M 1 M 1
c(n) 2h n , n 1,2, ,
2 2
( M 1) / 2
H r ( w) c(n) sin wn
n 0
n 1 2
M M
d (n) 2h n , n 1,2,,
2 2
M /2
1
H r ( w) d (n) sin w n
n 1 2
Hr(0)=0 and exp(jpi/2)=j. Hence this type of filter is also suit
able for designing digital Hilbert transforms and differentiators
.
Matlab Implementation
Hr-type 1
Hr-type 2
Hr-type 3
Hr-type 4
Zeros quadruplet for linear-phase filters
For real sequence, zeros are in conjudgates;
For symmetry sequence, zeros are in mirror;
Substitute q=z –1, the polynomial coefficients for q a
re in reverse order of polynomial of z.
Since coefficients h(n) are symmetry, reverse in ord
er do not change the coefficients vector.
If zk is a root of the polynomial, thus pk=zk-1 is also
a root.
Mirror zeros for symmetry coef..
If zk satisfy polynomial:
h0+h1zk-1+ h2zk-2 +..+ hM-2zk-M+2 + hM-1zk-M+1=0
where hM-1=h0 , hM-2 =h1,…
Then rk = zk –1 satisfy the same equation
h0+h1rk+ h2rk2 + …+ h1rkM-2 + h0rkM-1
= h0zkM-1 + h1zkM-2 + … + h2zk2+ h1zk + h0 =
= zkM-1(h0+ h1zk-1 + …+ h1zk-M+2 + h0zk –M+1) =0
1.5
1/Conj(Z1
1 )
0.5
Imaginary Part
Z1
0
-0.5
Conj(Z1)
-1
1/z1
-1.5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
Real Part
Examples
Examples7.4
Examples7.5
Examples7.6
Examples7.7
Impulse Response Type-1 Amplitude Response
20
10
15
5 10
5
h(n)
Hr
0 0
-5
-5
-10
-15
0 2 4 6 8 10 0 0.2 0.4 0.6 0.8 1
n frequency in pi units
1
5
0.5
a(n)
虚轴
0
0
-0.5
-5 -1
-1.5
0 2 4 6 8 10 -1 0 1
n 实轴
Windows Design Techniques
Basic idea: choose a proper ideal frequency-selective filter (whi
ch always has a noncausal, infinite-duration impulse response) a
nd then truncate (or window) its impulse response to obtain a lin
ear-phase and causal FIR filter.
Appropriate windowing function
Appropriate ideal filter
An ideal LPF of bandwidth wc<pi is given by
1 e jw
, | w | wc
H d (e )
jw
0 wc | w |
2
1
H d (e )e dw
jw jwn sin[ wc ( n )]
(n )
Note that hd(n) is symmetric with respect to alpha, a fact
useful for linear-phase FIR filter.
To obtain a causal and linear-phase FIR filter h(n) of leng
th M, we must have
hd (n) 0 n M 1 M 1
h( n) , and
0 elsewhere 2
Figure 7.9
Observations:
The amplitude response Wr(w) has the first zero at w=w1=2pi/
M. Hence the width of the main lobe is 2w1=4pi/M. Therefore t
he approximate transition bandwidth is 4pi/M.
The magnitude of the first side lobe (the peak side lobe magnitu
de) is approximately at w=3pi/M and is given by |Wr(3pi/M)| =
2M/(3pi), for M>>1. Comparing this with the main lobe amplitu
de, which is equal to M, the peak side lobe magnitude is 2/(3pi)
=21.11%=13dB of the main lobe amplitude.
Observations
The accumulated amplitude response has the first side l
obe magnitude at 21dB. This results in the minimum st
opband attenuation of 21dB irrespective of the window
length M.
Using the minimum stopband attenuation, the transitio
n bandwidth can be accurately computed. This comput
ed exact transition bandwidth is ws-wp = 1.8pi/M, whi
ch is about half the approximate bandwidth of 4pi/M.
Two main problems
The minimum stopband attenuation of 21dB is i
nsufficient in practical applications.
The rectangular windowing being a direct trunc
ation of the infinite length hd(n), it suffers from
the Gibbs phenomenon.
Bartlett Window
Bartlett suggested a more gradual transition in
the form of a triangular window
2n M 1
M 1 , 0n
2
2n M 1
w(n) 2 , n M 1
M 1 2
0, otherwise
Figure 7.11
Hanning Window
This is a raised cosine window function.
2n
0.51 cos , 0 n M 1
w(n) M 1
0, otherwise
Hamming Window:
2n
0.54 0.46 cos , 0 n M 1
w(n) M 1
0, otherwise
Blackman Window
2n 4n
0.42 0.5 cos 0. 08 cos , 0 n M 1
w(n) M 1 M 1
0, otherwise
Kaiser Window:
2 n
2
I 0 1 1
M 1
w(n) , 0 n M 1
I 0[ ]
jwM
1 e M 1
H (k )
H (e jw )
M
1 e jwe j 2k / M
k 0
j 2k / M H (0), k 0
H ( k ) H (e ) *
H ( M k ) k 1,2, M 1
2k jH ( k )
H (k ) H r e
M
2k H r (0), k 0
H (k ) H r
M
2 ( M k )
r M , k 1,2, , M 1
H
Phase for Type 1 & 2
Phase for Type 3 & 4
M 1 2k M 1
2 M , k 0,,
2
H (k )
M 1 2 ( M k ) , k M 1 1,, M 1
2 M 2
M 1 2k M 1
2 2 M , k 0, ,
2
H (k )
M 1 2 ( M k ) , k M 1 1,, M 1
2 2 M 2
Frequency Sampling Design Techniques
Basic Idea:
Given the ideal lowpass filter Hd(ejw), choose the filter l
ength M and then sample Hd(ejw) at M equispaced frequ
encies between 0 and 2pi. The actual response is the int
erpolation of the samples is given by
M 1
1 z M M 1
H (k )
H ( z) h( n) z n
M
1 z 1e j 2k / M
n 0 k 0
h(n) IDFT [ H (k )]
From Fig.7.25, we observe the following
The approximation error—that is difference between
the ideal and the actual response—is zero at the
sampled frequencies.
The approximation error at all other frequencies
depends on the shape of the ideal response; that is, the
sharper the ideal response, the larger the
approximation error.
The error is larger near the band edge and smaller
within the band.
Two Design Approaches
Naïve design method: Use the basic idea literally and p
rovide no constraints on the approximation error, that i
s, we accept whatever error we get from the design.
-10
-20
-30
-40
-50
-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Filters that have this property are called equiripple filter becaus
e the approximation error is uniformly distributed in both the pa
ssband and the stopband.
This results in low-order filter.
Development of the Minimax Problem
The frequency response of the four cases of linear-
phase FIR filters can be written in the form
j j M21 w
H (e ) e e
jw
H r ( w)
Where the values fro beta and the expressions for Hr(w) are given in
Table 7.2 (P.278)
Using simple trigonometric identities, each expression for Hr(w) above
can be written as a product of a fixed function of w (Q(w)) and a
function that is a sum of cosines (P(w)).
L
H r ( w) Q( w) P ( w), P ( w) (n) cos wn
n 0
E ( w) W ( w)[ H dr ( w) Q( w) P( w)]
H dr ( w)
W ( w)Q( w) P( w), w S
Q( w)
The common
form of E(w) E ( w) Wˆ ( w)[ Hˆ dr ( w) P( w)]
Problem Statement
Determine the set of coefficients a(n) or b~(n) or c~(n) or d~(n)
[or equivalently a(n) or b(n) or c(n) or d(n)] to minimize the max
imum absolute value of E(w) over the passband and stopband.
w0 w1 wL 1 S
Parks-McClellan Algorithm
It was solved by Remez.
1. Estimate the filter length order M by (7.48)
2. Guess extrema frequencies wi (i= 1:L+2)
3. Find an Lth polynomial that fits these points
4. Determine new wi’s by interpolation of the polynomial
5. Iteration from beginning
6. Determing a(i) and Emax by min(max(E(w)))
ˆ 20 log ws w p
M 10 1 2
, f
14.6f 2
Equiripple design function remez
General: [h]=remez(N,f,n,weights,ftype)
When weight=1 everywhere, And ftype is not H
ilbert filter or differentiator
[h]=remez(N,f,m)
h is the filter coefficients with length M=N+1
N denotes the order of the filter
f -- an array denotes band edges in units of π.
m -- desired magnitude response at each f
Remez equiripple design examples
Example 7.23: LP filter Design
compare with window design (ex7.8)
and freq.sampl. design (ex7.14,7.15,7.16)
Example 7.24: BP filter Design
compare with window (ex7.10) design
and freq.sampl. (ex7.17) design
Example 7.25: HP filter Design
Example 7.26: “Staircase” filter Design
Other Examples of equiripple
Ex7.27: digital differentiator design using reme
z function
Ex7.28: digital Hilbert Transformer design usin
g remez function
Readings and exercises
Readings: for Dec.3 to Dec.5(2 classes)
Text book: pp224~291
Chinese text book: pp.195~216,220~222
Exercises :
1. Complete the program of example 2, p7.2
2. p7.3, p7.5, p7.7, 7.14, P7.19