Lecture 11: LTI FIR Filter Design: Instructor: Dr. Gleb V. Tcheslavski Contact: Office Hours: Class Web Site
Lecture 11: LTI FIR Filter Design: Instructor: Dr. Gleb V. Tcheslavski Contact: Office Hours: Class Web Site
Lecture 11: LTI FIR Filter Design: Instructor: Dr. Gleb V. Tcheslavski Contact: Office Hours: Class Web Site
Fall 2008
Preliminary considerations
M 1
H ( z ) hk z k
FIR filter:
(11.2.1)
k 0
transfer function
unit-pulse response
M 1
M 1
H ( z ) hk z k
k
b
z
k
k 0
k 0
a0
;a0 1
(11.2.2)
H ( z ) h0 h1 z 1 h2 z 2 ... hM 2 z ( M 2) hM 1 z ( M 1)
z
M 1
h
M 1
M 3
2
h z
k 0
M 1
k
2
Fall 2008
M 1
M 1
2
hk z
M 1
k
2
(11.2.3)
Preliminary considerations
For an FIR filter to have a linear phase:
hk hM* 1 k
(11.3.1)
H ( z) z
M 1
h
M 1
M 1
h
M 1
2
M 3
2
h z
k 0
M 3
2
k 0
M 1
k
2
hk z
M 3
2
h
k 0
M 1
k
2
M 1 k
hM 1 k z
M 1
k
2
M 1
k
2
(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
Preliminary considerations
Since the filter is stable:
H (e j ) e
M 1
j
2
h
M 1
Here
M 1
j
2
M 3
2
k 0
hk e jhk e
M 1
k
2
e jhk e
M 1
k
2
M 3
2
M 1
h 2
h
cos
k
k
2
M21
k 0
1 4 4 4 4 4 4 44 2 4 4 4 4 4 4 4 43
Rc (e j )
(11.4.1)
As a result of symmetry:
He
ELEN 5346/4304 DSP and Filter Design
M 1
2
Fall 2008
Rc e j
(11.4.2)
Preliminary considerations
Therefore:
M 1
if Rc e j 0
2
M 1
if Rc e j 0
2
H e j
(11.5.1)
We can use Rc e
HPF, BPF,
When Rc e
In M is even:
M 2
2
M 1
Rc (e j ) 2 hk cos
k hk
k 0
2
Fall 2008
(11.5.2)
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.:
hk hM* 1 k
It can be shown that
(11.6.1)
M 3
2
M 1
Rs (e j ) 2 hk sin
k hk ;M isodd
k 0
2
(11.6.2)
M 2
2
M 1
Rs (e j ) 2 hk sin
k hk ;M iseven
k 0
2
Therefore:
BTW:
H e j e
M 1
j
2
jRs e j
H jdifferentiator
Fall 2008
(11.6.3)
(11.6.4)
(11.6.5)
(11.6.6)
Preliminary considerations
Thus:
H e j
M 1
j
2 2 if Rs e 0
3 M 1 if R e j 0
s
2
2
(11.7.1)
hk hM* 1 k
(11.7.2)
M 1
H ( z ) hk z k
(11.7.3)
k 0
H e j e
M 1
j
2
j
jRs e differentiators ,Hilberttransformers
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.7.4)
Preliminary considerations
Combining (11.7.2) and (11.7.3), we arrive at:
M 1
H ( z ) hk z
k 0
( M 1)
M 1
h
k 0
*
M 1 k
M 1
m M 1 k hm* z m ( M 1)
m0
M 1
* m
( M 1)
*
*
h
z
z
H
1
z
(11.8.1)
m0
hasazeroatz z0 re
hasa zeroat z
1 1 j
e
*
z0 r
H ( z ) h0 h1 z 1 h2 z 2 h3 z 3 h4 z 4
Has two pairs of reciprocal zeros.
firls(4,[0 0.25],[1 0]);
ELEN 5346/4304 DSP and Filter Design
Fall 2008
Imaginary Part
Example: if M = 5:
0.5
4
0
-0.5
-1
-1
-0.5
0
Real Part
0.5
Preliminary considerations
There are four types of real GLP FIR filters:
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
Fall 2008
10
Preliminary considerations
This is where structural zeros come from
H ( z ) h0 h1 z 1 h2 z 2 h3 z 3 evensymmetry h0 h1 z 1 h1 z 2 h0 z 3
H ( z ) z 1 h0 h1 h1 h0 0
(11.10.1)
H ( z ) h0 h1 z 1 h2 z 2 h3 z 3 odd symmetry h0 h1 z 1 h1 z 2 h0 z 3
H ( z ) z 1 h0 h1 h1 h0 0
(11.10.2)
H ( z ) h0 h1 z 1 h2 z 2 h3 z 3 h4 z 4 odd symmetry h0 h1 z 1 h2 z 2 h1 z 3 h0 z 4
H ( z ) z 1 h0 h1 h2 h1 h0 h2 0 0
H ( z ) z 1 h0 h1 h2 h1 h0 h2 0 0
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.10.3)
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!
Fall 2008
12
H d e j
j n
h
e
d ,n
(11.12.1)
H d e j e j n d
(11.12.2)
DTFT
hd ,n
hLPF ,n
jc n
jc n
2 j sin c n c sin c n
e
e
j n
1e d 2
2 j n
c n
c
(11.12.3)
Fall 2008
13
H t e j ht ,n e j n
n L
Where L and U are points at which the pulse response was truncated.
We need to minimize the least-square integral error of approximation.
Fall 2008
(11.13.1)
14
1
min R
2
R
Ht e
H e
j
ht ,n hd ,n ht ,n hd ,n
2
nL
L 1
hd ,n
(11.14.1)
n U 1
hd ,n
(11.14.2)
Fall 2008
15
hLPFIR ,n
M 1
sin c n
2
c
M 1
c n
2
(11.15.1)
0.2
0.2
0.1
0.1
0
-0.1
-50
Magnitude (dB)
0.3
0
0
n
Non-causal
ELEN 5346/4304 DSP and Filter Design
50
-0.1
20
40
60
Causal
Fall 2008
80
100
Phase (degrees)
0.3
hn
hn
Note: filter length M (number of filter coefficients) can be both even or odd.
0
-50
-100
0
0.2
0.4
0.6
0.8
1
Normalized Frequency ( rad/sample)
0
-2000
-4000
0
0.2
0.4
0.6
0.8
1
Normalized Frequency ( rad/sample)
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.
ht ,n hd ,n wn
(11.16.1)
Ht e
H d e j ( ) W e j d 1.2
W :
R
Gibbs phenomenon
(comes from truncated
Fourier series)
Ripples of equal magnitude in PB and SB
Transition band another window artifact
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.16.2)
|Ht()|
|W()|
|Hd()|
0.8
0.6
0.4
0.2
0
-0.2
-1
-0.5
0.5
17
Fixed windows:
Window
Rectangular
TB (2/M)
Max SB
ripple (dB)
0.9
-13
0.9
-21
Hanning
-31
3.1
-44
Hamming
-41
3.3
-53
Blackman
-57
5.5
-74
Window properties
ELEN 5346/4304 DSP and Filter Design
Fall 2008
Filter properties
18
Hanning:
Hamming:
Blackman:
(11.18.1)
1
2 n
2 2 n
W 1 cos
sin
,n 0,1,...M 1
2
M 1
M 1
(11.18.2)
N
n
2 n
,n 0,1,...M 1
M 1
(11.18.3)
2 n
4 n
W 0.42 0.5cos
0.08cos
,n 0,1,...M 1
(11.18.4)
M 1
M 1
B
n
Fall 2008
19
2
2
n
I0 1
1
M 1
,n 0,1,...M 1
K
Wn
I0
Where:
x 2 m
I 0 ( x) 1
m 1
m !
Fall 2008
(11.19.1)
(11.19.2)
20
TB (2/M)
1.5
-29
2.0
-37
2.6
-45
3.2
-54
4.5
-72
5.1
-81
Hanning
Hamming
Blackman
Kaiser window is the most frequently used for the FIR filter design.
Fall 2008
21
Vf
s p
Stop-band attenuation:
A 20 lg s
Order estimate:
A 7.95
1
14.36 V f
(11.21.1)
(11.21.2)
(11.21.3)
Adjustable parameter:
(11.21.4)
Fall 2008
22
0.1
The transition band: V f
2
2
A 7.95
40 7.95
1
1 23.32
14.36 V f
14.36 0.1
Order:
Parameter:
We select M = 24, = 4. The filter is given by (11.15.1) with the cutoff frequency:
p s
c
0.4
2
sin c n
ht ,n
wn ; L n L
n
Fall 2008
23
3. Frequency sampling
The desired frequency response
M 1
H d e j
DTFT
h
n0
j n
e
d ,n
(11.23.1)
k
Where
2
k
M
M 1
,M odd
2
M 2
0,1,...
,M even
2
0,1,...
/M
/M
2
ELEN 5346/4304 DSP and Filter Design
/M
2
= 0.5:
= 0:
0nooffset
0.5offsetby M
Fall 2008
(11.23.2)
(11.23.3)
(11.23.4)
24
3. Frequency sampling
The sampled frequency response will be:
H d , k H d e j
M 1
hd ,n e
2
( k ) n
M
,k 0,1,...M 1
(11.24.1)
n0
Evaluating IDFT:
1
hn
M
M 1
H
k 0
d , k
2
( k ) n
M
,n 0,1,...M 1
(11.24.2)
H k H *M k
Fall 2008
(11.24.3)
25
3. Frequency sampling
We can rewrite the FIR filter frequency response (11.7.4) as:
He
H r e
j
H
e
e
r
M 1
2
,symmetrichn hM 1 n types
M 1
j
2
2
(11.25.1)
,antisymmetrichn hM 1 n types V
k
k 2
;k 0,1,...M 1
M
(11.25.2)
H k
Hr
k
e
M
Fall 2008
2
M 1
j k
2
2 M
(11.25.3)
26
3. Frequency sampling
0symmetrichn
antisymmetrichn
Here:
(11.26.1)
Gk
2
@ 1 H r
k ;k 0,1,...M 1
M
H k Gk e j k e
Therefore:
0
;
12
2
M 1
j k
2
2 M
0
4differentcases...
Fall 2008
(11.26.2)
(11.26.3)
27
3. Frequency sampling
0symmetrichn
0nooffset :k 2 k M
Case 1:
H k Gk e j k e
M 1
1
hn
M
H e
k 0
2
kn
M
k 1
k 1
G0 Gk e
G0 Gk e
k
M
2 M 1
k
M 2
M 1
M
j
G e
k 0
2
kn
M
k
M
1
M
2
kn
M
GM k e
( M k )
M
2 M
k
M 2
G e
k 0
2
1
k n
M
2
Gk e
2
1
k n
M
2
k 1
k
M
Fall 2008
Gk e
2
kn
M
k
M
(11.27.1)
M 1
Ge
k U 1
k
M
2
kn
M
e e
j
j 2 n
1
e 1;e
j 2 n
1
k n ;n 0,1,...M 1
2
k
M
2
( M k ) n
M
k 1
2
G0 2Gk cos
k 1
M
Gk e j k e
(11.27.2)
28
3. Frequency sampling
2
M
Gk 1 H r
k
Since hn is real:
2
H r
M
H k H M* k
2 M 1
2
jM k
k e
(11.28.1)
(11.28.2)
2
M 1
j M k
* 2
2
Hr
M k e M
M
(11.28.3)
Since Hr is real:
2
Hr
M
H r
2 M 1
jM k 2
2
k e
Hr
M
M
2
2
k H r
M k
M
M
2
H r
M
j
M k
M
k e
2 M
2
2
2
M 1
2
H r
2
M k e j M 1
M
2
k 1 H r
M k e j M k e j k e j 1 k
M
Fall 2008
(11.28.4)
29
3. Frequency sampling
Therefore:
Gk GM k
(11.29.1)
(11.29.2)
- forced zero at z = -1
H e j DFT hn 0
and check whether the specifications are satisfied.
Fall 2008
30
3. Frequency sampling
0symmetrichn
1 2ffset :k 2 (k 0.5) M
Case 2:
2
1
k
Gk 0.5 1 H r
k
2
M
(11.30.1)
2
hn
M
(11.30.2)
2
1
1
k
;n 0,1,...M 1
2
2
M
Gk 0.5 2sin
k 0
M 1
2 ;odd M
U
M 1;evenM
2
Fall 2008
(11.30.3)
31
3. Frequency sampling
1antisymmetrichn
0noffset :k 2 k M
Case 3:
2 k
Gk 0.5 1 H r
k
2
hn
M
M 1
k 1
(11.31.1)
2 k
1
Gk sin
n ;M isodd
2
M
M 2 2
1
2
1
n 1
hn 1 GM 2 2 Gk sin
k n ;M iseven
M
2
k 1
M
Fall 2008
(11.31.2)
(11.31.3)
32
3. Frequency sampling
1antisymmetrichn
Case 4:
0.5ffset :k 2 k 0.5 M
2 k 0.5
Gk 0.5 1 H r
k
2
hn
M
2
1
1
k
;n 0,1,...M 1
2
2
M
Gk 0.5 cos
k 0
M 3
;odd M
2
U
M 1;evenM
2
(11.32.1)
(11.32.2)
(11.32.3)
Fall 2008
33
3. Frequency sampling
1.2
0.4
actual
specified
1
0.8
|H()|
0.6
0.2
1.2
0.1
0.2
0.3
fractional frequency
0.4
0.5
0.6
0.4
0.2
0
0.8
|H()|
actual
specified
0.1
0.2
0.3
fractional frequency
0.4
0.5
34
3. Frequency sampling
The transition band sample(s) optimized experimentally are:
# of TB samples
Sample(s) value(s)
SB attenuation, dB
0.3789795 if = 0
0.3570496 if = 0.5
[0.1065 0.5886]
~ 40
T3
~ 80
T4
~ 100
T1
T2
~ 60
Fall 2008
35
1 p H r e j 1 p ;PB
s H r e
(11.35.1)
;SB
s
hn hM 1 n
(11.35.2)
M 1
M 1
n k
n
2
2
H r e j hM 1 2 hn cos
2
n0
hM 1 ,k 0
a
k 0
cos k
(11.35.3)
ak
M 1
2hM 1 ,k 1, 2,...
k
2
M 1
2
Fall 2008
(11.35.4)
36
(11.36.1)
M
2
M 2
M 1
1
n k
n bk cos k
2
2
2
k 1
H r e j 2 hn cos
n 0
M 1
2
(11.36.3)
b%cos k
(11.36.4)
bk 2hM ,k 1, 2,...
2
H r e j cos
Or:
(11.36.2)
M
1
2
k 0
b%
0 0.5 b1
Where:
% ; k 1, 2,... M 2
b%
b
k
k
k 1
2
b%
2bM
M
2
Fall 2008
(11.36.5)
37
hn hM 1n
(11.37.1)
M 1
M 1
n k
n
2
2
H r e j 2 hn sin
n 0
ck 2hM 1 ,k 1, 2,...
2
M 1
2
M 1
2
c
k 1
sin k
(11.37.2)
(11.37.3)
M 3
2
H r e j sin c%
k cos k
Or:
(11.37.4)
k 0
c%
M 3 c M 1
Where:
%
c%
k 1 ck 1 2ck ;2 k M 5 2
%
c%
0 0.5c2 c1
Fall 2008
(11.37.5)
38
(11.38.1)
M
2
M
M 1
n k
n d k sin k
2
2
k 1
H r e j 2 hn sin
n 0
d k 2hM ,k 1, 2,...
2
H r e j sin
Or:
M
2
(11.38.2)
(11.38.3)
M 2
2
d%cos k
k 0
(11.38.4)
d%
M 3 2d M
Where:
%
d%
k 1 d k 2d k ;2 k M 3 2
d% 0.5d% d
0
Fall 2008
(11.38.5)
39
H r e j Q e j P e j
Where:
Filter type
1:
2:
P e
k 0
cos k
(11.39.2)
Q(ej )
hn hM 1 n M odd
hn hM 1 n M even
cos
2
3: hn hM 1 n M odd
sin
4: hn hM 1 n M even
sin
2
(11.39.1)
Fall 2008
P(ej )
M 1
ak cos k
k 0
M 2
k 0
M 3
k 0
M 2
k 0
b%
k cos k
c%
k cos k
d%
k cos k
40
H dr e
We can compute
1inPB
0inSB
(11.40.1)
We
1inSB
s p inPB
Fall 2008
(11.40.2)
41
E e j W e j H dr e j H r e j W e j H dr e j Q e j P e j
W e
Q e
H dr e j
Q e
P e W e j H dr e j P e j
(11.41.1)
Where the modified weighting function and the modified desired frequency
response are:
W e j W e j Q e j
H dr e j
ELEN 5346/4304 DSP and Filter Design
H dr e j
Q e
Fall 2008
(11.41.2)
(11.41.3)
42
min max E e
over k S
(11.42.1)
S PB U SB
(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
43
k
k 0
unique and best approximation to H e j in S is that the error function
dr
1 2 ... L 2
E e ji E e ji1
E e ji max E e j ,i 1, 2,..., L 2
S
Fall 2008
(11.43.1)
(11.43.2)
(11.43.3)
44
dE e j
d
W e j H dr e j H r e j
d
dH r e j
d
(11.44.1)
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:
Hr e
k 0
cos k k nk cos
k 0
n0
%
k cos
(11.44.2)
k 0
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
45
W e jn H dr e jn P e jn
alternations
1 ;n 0,1,...L 1
n
(11.45.1)
Here represents the maximum value of the error function E(e j).
H dr e jn n 0,1,...L 1
(11.45.2)
e jn n 0,1,...L 1
k cos n k
dr
W e jn
k 0
(11.45.3)
P e jn
or alternatively:
W e jn
n
Fall 2008
46
1
H dr e j1
1 cos 1
cos 21 L
cos L1
1 W e L1
M
M
L
M
L 1
jL1
jL1
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.
ELEN 5346/4304 DSP and Filter Design
Fall 2008
(11.46.1)
47
0 H dr e j0 1 H dr e j1 ... L 1 H dr e jL1
0
1
(1) L 1
...
W e jL1
W e j0 W e j1
L 1
(11.47.1)
L 1
where:
1
k
n 0 cos k cos n
(11.47.2)
nk
P e j k x k , x cos
k 0
Fall 2008
(11.47.3)
48
P e
jn
H e
dr
jn
(1) n
,n 0,1,...L 1
jn
W e
(11.48.1)
P e j
k 0
x x
k
x cos
xk cos k
L
1
k
n 0 xk xn
nk
x xk
k 0
Here:
jk
P
e
k
Fall 2008
(11.48.2)
(11.48.3)
(11.48.4)
(11.48.5)
49
E e j W e j H dr e j P e j
(11.49.1)
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:
20 lg s p 13
14.6 s p
Fall 2008
(11.49.2)
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.
Fall 2008
51
Fall 2008
52
hLP ,n
sin c n
, n
n
(11.52.1)
1 c ,n 0
HPF:
BPF:
sin c n
, n 0
n
hHP ,n
hBP ,n
, n 0
n
n
BSF:
(11.52.3)
c 2 c1
1
,n 0
n
n
hBS ,n
(11.52.2)
Fall 2008
(11.52.4)