Lecture 11: LTI FIR filter design

advertisement
1
Lecture 11: LTI FIR filter design
Instructor:
Dr. Gleb V.
Tcheslavski
Contact:
gleb@ee.lamar.edu
Office Hours: Room
2030
Class web site:
http://ee.lamar.edu/gleb/
dsp/index.htm
ELEN 5346/4304
DSP and Filter Design
Fall 2008
2
Preliminary considerations
M 1
H ( z )   hk z  k
FIR filter:
(11.2.1)
k 0
transfer function
unit-pulse response
M 1
BTW, using our
“rational notation”:
M 1
H ( z )   hk z  k 
k 0
k
b
z
k
k 0
a0
;a0  1
(11.2.2)
Here M-1 is the filter order.
M is the number of filter’s coefficients. Assuming that M is odd:
H ( z )  h0  h1 z 1  h2 z 2  ...  hM  2 z  ( M  2)  hM 1 z  ( M 1)
M 3

M 1
M 1
M 1 
M

1
2

k
k

2 
2
2
z
hM 1   hk z
  hk z
 2

M 1
k 0
k


2
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.2.3)
3
Preliminary considerations
For an FIR filter to have a linear phase:
hk  hM* 1k
(11.3.1)
That means an even symmetry of the coefficients.
H ( z)  z
z
M 1

2
M 1

2
M 3
M 3

 M 1  
M

1
2
2

k 
k
h 
 2

2
hk z
  hM 1 k z

M 1
 2

k 0
k 0


M 3

 M 1  
M 1
2 

k  
k
h 
 2
 
2
h
z

h
z


k
M 1 k
 M21 


k 0 
 

(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
4
Preliminary considerations
Since the filter is stable:
H (e j )  e
e
M 1
 j
2
M 1
 j
2
M 3

 M 1  
M 1
2

 j 
k  
j
k
jhk
 jhk
h 
 2
 
2
h
e
e

e
e


k
 M21 


k 0

 

M 3


2
  M 1 

h  2
h
cos


k


h

k
k 
  2

 M21

k 0
 



(11.4.1)
Rc (e j )
Here
Rc (e j ) is a real function of frequency.
As a result of symmetry:
H e
ELEN 5346/4304
DSP and Filter Design
j
e
 j
M 1
2
Fall 2008
Rc  e j 
(11.4.2)
5
Preliminary considerations
 M 1

if Rc  e j   0


2
H  e j   
 M  1    if R  e j   0
c

2
Therefore:
(11.5.1)
Generalized linear phase
  to design ANY amplitude of frequency response: LPF,
We can use Rc e
HPF, BPF,…
j
  changes sign, the phase undergoes an abrupt change of 180
When Rc e
j
0
In M is even:
M 2
2
Rc (e )  2 
j
k 0
ELEN 5346/4304
DSP and Filter Design
  M 1 

hk cos   
 k   hk 

  2

Fall 2008
(11.5.2)
6
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 isodd

k 0
  2

(11.6.2)
M 2
2
  M 1 

Rs (e j )  2  hk sin   
 k   hk ;M iseven

k 0
  2

Therefore:
BTW:
ELEN 5346/4304
H  e j   e
 M 1 
 j 
2 

jRs  e j 
(11.6.3)
(11.6.4)
H     jdifferentiator
(11.6.5)
H      j  sign   Hilberttransformer
(11.6.6)
DSP and Filter Design
Fall 2008
7
Preliminary considerations
Thus:
 M  1

if Rs  e j   0

2
2
H  e j   
 3  M  1 if R  e j   0
s
 2
2
(11.7.1)
Generalized linear phase
Summarizing, a unit-pulse response of a GLP FIR filter must satisfy:
hk  h
*
M 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 

 Rc  e j LPF , HPF , BPF , BSF ,...


j
jR
e

differentiators,Hilberttransformers

 s
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)
8
Preliminary considerations
Combining (11.7.2) and (11.7.3), we arrive at:
M 1
H ( z )   hk z
k
k 0
 z
 ( M 1)
M 1
   h
k 0
*
M 1 k
z
k
M 1
 m  M  1  k     hm* z m( M 1)
m0
M 1
* m
 ( M 1)
*
*
h
z


z
H
1
z


 m
(11.8.1)
m0
hasazeroatz  z0  re
j
hasazeroatz 
1 1 j
 e
*
z0 r
1
Example: if M = 5:
Has two pairs of reciprocal zeros.
firls(4,[0 0.25],[1 0]);
ELEN 5346/4304
DSP and Filter Design
Fall 2008
Imaginary Part
H ( z)  h0  h1z 1  h2 z 2  h3 z 3  h4 z 4
0.5
4
0
-0.5
-1
-1
-0.5
0
Real Part
0.5
1
9
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
indicate “structural zeros”
ELEN 5346/4304
DSP and Filter Design
Fall 2008
10
Preliminary considerations
This is where structural zeros come from…
1. For M = 4, symmetrical pulse response ( Type II FIR):
H ( z)  h0  h1z 1  h2 z 2  h3 z 3  evensymmetry  h0  h1z 1  h1z 2  h0 z 3
H ( z) z 1  h0  h1  h1  h0  0
(11.10.1)
2. For M = 4, antisymmetrical pulse response ( Type IV FIR):
H ( z)  h0  h1z 1  h2 z 2  h3 z 3  oddsymmetry  h0  h1z 1  h1z 2  h0 z 3
H ( z) z 1  h0  h1  h1  h0  0
(11.10.2)
3. For M = 5, antisymmetrical pulse response ( Type III FIR):
H ( z)  h0  h1z 1  h2 z 2  h3 z 3  h4 z 4  oddsymmetry  h0  h1z 1  h2 z 2  h1z 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!
ELEN 5346/4304
DSP and Filter Design
Fall 2008
12
1. Least-square error minimization
The desired magnitude response (something we specify):
H d  e j  
DTFT
 jn
h
e
 d ,n
(11.12.1)
n
Filter coefficients could be found as:
hd ,n
1

2


H d  e j  e jn d
(11.12.2)

Example: Ideal LPF
hLPF ,n
1

2
jc n
 jc n
2 j sin c n  c sin c n 
e

e
j n


 1 e d  2
2 j n

c n
c
c
(11.12.3)
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
13
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).
Therefore, the objective is to find a finite-duration impulse response sequence,
whose DTFT would approximate the desired frequency response.
The magnitude of the frequency response of the “truncated filter”:
H t  e j    ht ,n e jn
U
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.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.13.1)
14
1. Least-square error minimization
In particular:
1
min R 
2
 R 

h
n 
t ,n

 H  e   H  e 
j
j
t

U
d
 hd ,n   ht ,n  hd ,n 
2
2
n L
2
L 1
h
n 
d ,n
2
d

(11.14.1)


n U 1
hd ,n
2
(11.14.2)
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.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
15
1. Least-square error minimization
Relating the point of truncation to the FIR filter order: L = (M – 1)/2
hLPFIR ,n
 
M  1 
sin  c  n 
2  
c



M  1


c  n 
2 

(11.15.1)
0.2
0.1
0
Magnitude (dB)
0.2
0.1
0
-0.1
-50
0
n
Non-causal
ELEN 5346/4304
DSP and Filter Design
50
-0.1
0
20
40
60
n
Causal
Fall 2008
80
100
Phase (degrees)
0.3
n
0.3
h
h
n
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.
ht ,n  hd ,n  wn
(11.16.1)
from the Modulation theorem:
1
Ht  e j  
2



H d  e j (  ) W  e j  d 1.2
W
R:
(11.16.2)
|Ht()|
1
|W()|
|Hd()|
0.8
Gibbs phenomenon
(comes from truncated
Fourier series)
0.6
0.4
0.2
Ripples of equal magnitude in PB and SB
Transition band – another window artifact
0
-0.2
-1
-0.5
0
/
ELEN 5346/4304
DSP and Filter Design
Fall 2008
0.5
1
17
2. Windowing effects: window types
As discussed previously, different window functions can be used…
Fixed windows:
Window
MLW (4/M) PSL (dB)
TB (2/M)
Max SB
ripple (dB)
 0.9
-13
0.9
-21
Hanning
2
-31
3.1
-44
Hamming
2
-41
3.3
-53
Blackman
3
-57
5.5
-74
Rectangular
Window properties
ELEN 5346/4304
DSP and Filter Design
Fall 2008
Filter properties
18
2. Windowing effects: window types
Rectangular:
(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
Hanning:
Hamming:
Blackman:
ELEN 5346/4304
WnR  1,n  0,1,...M 1
 2 n 
WnM  0.54  0.46cos 
,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
DSP and Filter Design
Fall 2008
19
2. Windowing effects: window types
Adjustable windows:
Kaiser window:
2 

2n


I0   1  
 1 

M 1  

 ,n  0,1,...M  1
WnK  
I0   
  x 2
I 0 ( x)  1   
m 1 
 m!

Where:
m



2
Normally, 15-20 terms in the summation are sufficient.
Note: if  = 0, WnK = WnR.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.19.1)
(11.19.2)
20
2. Windowing effects: window types
Properties:

TB (2/M)
Max SB ripple (dB)
2
1.5
-29
3
2.0
-37
4
2.6
-45
5
3.2
-54
7
4.5
-72
8
5.1
-81
Hanning
Hamming
Blackman
Kaiser window is the most frequently used for the FIR filter design.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
21
2. Windowing: experimental design
For the given transition band:
f 
s   p
Stop-band attenuation:
A  20lg  s
Order estimate:
M
Adjustable parameter:
2
A  7.95
1
14.36  f
(11.21.1)
(11.21.2)
(11.21.3)
0.1102  ( A  8.7) A  50dB

  0.5842  ( A  21)0.4  0.07886  ( A  21)21  A  50
0 A  21

(11.21.4)
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
22
2. Windowing: experimental design
Example 11.1: design an FIR LPF using a Kaiser window for the following specs:
p  0.3 ;s  0.5 ; A  40dBminSBattenuation
s   p 0.5  0.3
f 

 0.1
The transition band:
2
2
A  7.95
40  7.95
1 
 1  23.32
14.36  f
14.36  0.1
Order:
M
Parameter:
  0.5842  ( A  21)0.4  0.07886  ( A  21)  3.4
We select M = 24,  = 4. The filter is given by (11.15.1) with the cutoff frequency:
c 
The transfer function:
 p  s
2
 0.4
sin c n
ht ,n 
 wn ; L  n  L
n
The resulting filter is a type II FIR which is ok for LPF.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
23
3. Frequency sampling
The desired frequency response
H d  e j  
M 1
DTFT
h
n 0
 j n
e
d ,n
(11.23.1)
can be specified by its frequency samples at equally spaced (discrete) frequencies:
2
k 
k  
M
Where
 = 0:
 = 0.5:
M 1

0,1,...
,M odd

2
k 
0,1,... M  2 ,M even

2
0nooffset
 
0.5offsetby M
ELEN 5346/4304
DSP and Filter Design
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
 k
  hd ,ne
j
2
( k  ) n
M
,k  0,1,...M  1
(11.24.1)
n 0
Evaluating IDFT:
1
hn 
M
M 1
H
k 0
d , k 
e
j
2
( k  ) n
M
,n  0,1,...M  1
(11.24.2)
Therefore, we can compute the filter coefficients from the specified M
frequency samples.
Since hn is real:
Hk   H *M k 
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.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.24.3)
25
3. Frequency sampling
We can rewrite the FIR filter frequency response (11.7.4) as:
M 1
 j

j
2
H
e
e
,symmetrichn  hM 1 n  types 



r

j
H e   
 M 1  
 j
 H e j e  2  2  ,antisymmetrich  h
n
M 1 n  types  V
 r  
(11.25.1)
Sampled at the frequencies
k  2
k 
;k  0,1,...M  1
M
(11.25.2)
the response becomes:
H k 
ELEN 5346/4304
DSP and Filter Design
 2

 Hr  k     e
M

Fall 2008
  2
 M 1  
j     k  

 2 
 2 M
(11.25.3)
26
3. Frequency sampling
0symmetrichn
 
antisymmetrichn
Here:
(11.26.1)
For simplicity, we specify the following set of real frequency samples:
Gk 
 2
 1 H r   k     ;k  0,1,...M  1
M

k
H k   Gk  e j k e
Therefore:
  2
 M 1  
j     k   

 2 
 2 M
0
0
   ;   4differentcases...
1 2

ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.26.2)
(11.26.3)
27
3. Frequency sampling
  0symmetrichn
  0nooffset :k  2 k M
Case 1:
Hk  Gk e j k e
1
hn 
M
1

M

1
M

1
M
2  M 1 
k

M  2 
ELEN 5346/4304
j
DSP and Filter Design
1

M
M 1
j
k
M
 Gk e j k e
j
2
kn
M
j
2 M
k
M 2
e
j
k
M
 Gk e
j
k
M
(11.27.1)
k
2
k
2
M 1
j
j kn
j
j kn 
1 U
Hke
Gk e e
  Gk e M e M   Gk e M e M 


M  k 0
k 0
k 0
k U 1

k
2
 ( M  k ) 2
U
U
j
j kn
j
j ( M k ) n 

M
M
M
  GM  k e
e M
G0   Gk e e

k

1
k

1


2  1 
2  1 
U
U

j k  n 
 j k  n 

M  2
M  2  j j 2 n
  Gk e
e e   e j  1;e j 2 n  1
G0   Gk e
k 1
k 1


U

 2 
1  
(11.27.2)
G

2
G
cos
k
n


 0  k

  ;n  0,1,...M  1
2  
k 1
M 

M 1
2
kn
M
j
Fall 2008
28
3. Frequency sampling
k
 2
Gk   1 H r 
M
Hk  HM* k
Since hn is real:
 2
H r 
M
2 M 1
2
 jM k
k e


k

(11.28.1)
(11.28.2)
2
  j M M k 
*  2
 Hr  M  k  e
M

M 1
2
(11.28.3)
Since Hr is real:
2 M 1
2
 2   j M k
Hr 
k e
M 
2
 2
 j M M k 
 Hr 
M  k  e
M

M 1
2
2 M
2
 2 
 2
 j 2 j 2
 2
 j  M 1
H r 
k   Hr 
M

k
e
e

H
M

k




r 
e
M 
M

M

k
k
 2 
 2
 j  M  k  j k  j
H r 
k    1  H r 
e e   1
(11.28.4)
M  k  e
M 
M

ELEN 5346/4304
DSP and Filter Design
Fall 2008
29
3. Frequency sampling
Therefore:
Gk  GM k
(11.29.1)
The number of coefficients (frequency samples) to be specified:
 M 1
 2 ;odd M
U 
 M  1;evenM
 2
(11.29.2)
- forced zero at z = -1
Since the unit-pulse response is already evaluated, we can estimate the
corresponding frequency response as its zero-padded DFT:
Hˆ  e j   DFT hn 0
and check whether the specifications are satisfied.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
30
3. Frequency sampling
  0symmetrichn
  1 2ffset :k  2 (k  0.5) M
Case 2:
The desired frequency samples:
Gk 0.5
 2
  1 H r 
M
k
 1
k  2  

(11.30.1)
2 U
 2 
1  1  
hn   Gk 0.5 2sin   k   n    ;n  0,1,...M  1
M  k 0
2 
2  
M 
 M 1
 2 ;odd M
U 
 M  1;evenM
 2
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.30.2)
(11.30.3)
31
3. Frequency sampling
  1antisymmetrichn
  0noffset :k  2 k M
Case 3:
The desired frequency samples:
k
 2 k 
Gk 0.5   1 H r 

 M 
(11.31.1)
2  M 1 2
 2 k 
1  
hn     Gk sin 
 n    ;M isodd
M  k 1
2  
 M 
 M 2 2
1 
 2
n 1
hn   1 GM 2  2  Gk sin 
M
k 1
M
ELEN 5346/4304
DSP and Filter Design
Fall 2008
1  

k  n    ;M iseven
2  

(11.31.2)
(11.31.3)
32
3. Frequency sampling
  1antisymmetrichn
Case 4:
  0.5ffset :k  2  k  0.5 M
The desired frequency samples:
 2  k  0.5 
Gk 0.5   1 H r 

M


2 U
 2 
1  1  
hn   Gk 0.5 cos   k   n    ;n  0,1,...M  1
M  k 0
2 
2  
M 
k
M 3
 2 ;odd M
U 
 M  1;evenM
 2
ELEN 5346/4304
DSP and Filter Design
(11.32.1)
(11.32.2)
(11.32.3)
Fall 2008
33
3. Frequency sampling
1.2
We specify the desired response in the
SB and the PB only…
actual
specified
1
The stopband attenuation in this case
(only SB and PB samples are given) is
approximately -20 dB.
|H()|
0.8
0.6
0.4
0.2
1.2
0
actual
specified
1
0
0.1
0.2
0.3
fractional frequency
0.4
0.5
|H()|
0.8
Alternatively, we can add transition sample(s)
and make the frequency response smoother.
0.6
0.4
0.2
0
0
ELEN 5346/4304
0.1
0.2
0.3
fractional frequency
DSP and Filter Design
0.4
0.5
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.
Fall 2008
34
3. Frequency sampling
The transition band sample(s) “optimized” experimentally are:
# of TB samples
Sample(s) value(s)
SB attenuation, dB
T1
0.3789795 – if  = 0
0.3570496 – if  = 0.5
~ 40
T2
[0.1065 0.5886]
~ 60
T3
[0.025779 0.251635 0.723071]
[0.030957 0.27557 0.744348]
Note: only one of them is correct.
~ 80
T4
[0.006061 0.09324 0.4082 0.82097]
~ 100
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.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
35
4. Optimal equiripple design
We are interested in a LP filter satisfying the following requirements:
1   p  H r  e j   1   p ;PB
 s  H r  e
j
(11.35.1)
   ;SB
s
Considering four FIR types:
Type 1: symmetric pulse response, odd M.
hn  hM 1n
(11.35.2)
The real-valued frequency response:
M 3
2
M 1
2
M 1 
 M 1  
H r  e   hM 1  2  hn cos  
 n   k 
 n    ak cos k
2
 2
 
 k 0
n 0
2
j
hM 1 ,k  0
 2
ak  
M 1
2
h
,

k

1,
2,...
 M 1
2
 2  k
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.35.3)
(11.35.4)
36
4. Optimal equiripple design
hn  hM 1n
Type 2: symmetric pulse response, even M.
(11.36.1)
The real-valued frequency response:
M 2
2
M
2
M 2 
1
 M 1  

H r  e j   2  hn cos  
 n   k 
 n    bk cos   k   (11.36.2)
2
2
 2
 
 k 1

n 0
M 1
2
(11.36.3)
cos  k
(11.36.4)
bk  2hM ,k 1, 2,...
2
k
H r  e j   cos
Or:

M
1
2
b

2
k 0
k
b0  0.5  b1
Where:
bk  2  bk  bk 1 ;k  1, 2,...
bM
2
ELEN 5346/4304
DSP and Filter Design
1
 2bM
2
Fall 2008
M
2
2
(11.36.5)
37
4. Optimal equiripple design
Type 3: antisymmetric pulse response, odd M.
hn  hM 1n
(11.37.1)
The real-valued frequency response:
M 3
2
M 1 
 M 1  
H r  e j   2  hn sin  
 n   k 
 n 
2
 2
 

n 0
ck  2hM 1 ,k1, 2,...
2
k
M 1
2
M 1
2
c
k 1
k
sin k
(11.37.2)
(11.37.3)
M 3
2
H r  e j   sin   ck cos k
Or:
(11.37.4)
k 0
c M 3  c M 1
Where:
2
2
ck 1  ck 1  2ck ;2  k   M  5  2
c0  0.5c2  c1
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.37.5)
38
4. Optimal equiripple design
Type 4: antisymmetric pulse response, even M. hn  hM 1n
(11.38.1)
The real-valued frequency response:
M 2
2
M
2
M
 M 1  

H r  e j   2  hn sin  
 n   k 
 n    d k sin k
2
 2
 
 k 1
n 0
M
2
(11.38.3)
cos  k
(11.38.4)
dk  2hM ,k1, 2,...
2
k
H r  e j   sin
Or:

M 2
2
d

2
k 0
k
(11.38.2)
d M  3  2d M
Where:
2
2
d k 1  d k  2d k ;2  k   M  3 2
d0  0.5d1  d1
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.38.5)
39
4. Optimal equiripple design
Therefore, we can express the frequency response for all FIR types as:
H r  e j   Q  e j  P  e j 
P e
Where:
Filter type
1:
2:
hn  hM 1n M odd
hn  hM 1n M even
3: hn  hM 1n M odd
4: hn  hM 1n M even
ELEN 5346/4304
DSP and Filter Design
j
  
L
k 0
k
(11.39.1)
cos  k
(11.39.2)
Q(ej)
P(ej)
 M 1

1

cos
2
sin 
sin

Fall 2008
2
2
ak cos k
k 0
 M  2

2
k 0
 M 3

k 0
 M  2

k 0
2
bk cos k
ck cos k
2
dk cos  k
40
4. Optimal equiripple design
The desired frequency response:
1inPB
H dr  e   
0inSB
j
We can compute
(11.40.1)
H r  e j  and compare it to H dr  e j  . Adjusting P() and
selecting filter type, we can obtain the desired frequency characteristic.
We introduce the weighting function on the approximation error:
1inSB
W e   
 s  p inPB
j
If s < p – bigger error in the passband is allowed.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.40.2)
41
4. Optimal equiripple design
The weighted approximation error:
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 
 H dr  e j 

j
j
j
ˆ  e j   Hˆ  e j   P  e j 

 W e  Q e  

P
e

W


dr
j


Q
e
  

(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
j

(11.41.2)
(11.41.3)
42
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:
L



j

j

ˆ
ˆ


min max E  e   min  max W  e   H dr  e     k cos  k  
over k   S
 over k  S
k 0



j
(11.42.1)
Usually, the frequency bands of interest are specified as:
S  PB 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
4. Optimal equiripple design
The alternation theorem
 
L
A necessary and sufficient conditions for P e   k cos  k to be
k 0
j
ˆ
unique and best approximation to H  e  in S is that the error function
j
dr
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:
1  2  ...  L2



E e ji   E e ji1



E e ji  max E  e j  ,i  1, 2,..., L  2
S
I.e., error alternates in sign between two successive extremal frequencies.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.43.1)
(11.43.2)
(11.43.3)
44
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:
dE  e j 
d
j
dH
e


d
r
j
j
j



W  e   H dr  e   H r  e   
0
d
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
j
  
L
k 0
L
k
k
L
cos k   k  nk  cos     k  cos  
k 0
n 0
n
k
(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
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:





alternations

n
Wˆ e jn  Hˆ dr e jn  P e jn    1  ;n  0,1,...L  1
(11.45.1)
Here  represents the maximum value of the error function E(e j).


 1 
n


 Hˆ dr e jn n  0,1,...L  1
(11.45.2)
1 

ˆ e jn n  0,1,...L  1
 k cos n k 

H

dr
Wˆ e jn
k 0
(11.45.3)
P e jn 

Wˆ e
jn

or alternatively:
n
L

ELEN 5346/4304
DSP and Filter Design


Fall 2008

46
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:
1 cos 0
cos 20

1 cos 1
cos 21



1 cos L 1 cos 2L 1
cos L0
cos L1
cos LL 1
 
1 Wˆ  e

 1
L 1


  0   Hˆ dr e j0 
   

jL1
1
j

    Hˆ dr  e 1  
   
 (11.46.1)
  


 L 

jL1
jL1
ˆ
ˆ
H
e
W e
     dr  
1 Wˆ e j0
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
47
4. Optimal equiripple design
Alternatively, we can compute  analytically [Rabiner ‘75]:
 0 Hˆ dr  e j    1Hˆ dr  e j   ...   L 1Hˆ dr  e j
0

0

Wˆ e j0
1


1
Wˆ  e j1 
 ... 
L1

(1)  L 1
Wˆ  e jL1 
L 1
(11.47.1)
L 1
where:
1
k  
n 0 cos k  cos n
(11.47.2)
nk
Therefore, the initial guess of the L + 2 extremal frequencies allows us to
compute the maximum value of the error . Thus:
P  e j    k x k ,x  cos 
L
k 0
ELEN 5346/4304
DSP and Filter Design
Fall 2008
(11.47.3)
48
4. Optimal equiripple design
Since we know that the polynomial at the points xn = cos n has the values:

P e
jn
  Hˆ  e 
jn
dr
(1) n 

,n  0,1,...L  1
jn
ˆ
W e


(11.48.1)
the Lagrange interpolation formula can be used, which leads to
L
P  e j  


jk
P
e
  k

k 0
L
    x  x 
k 0
k
x  cos 
xk  cos k
L
1
k  
n  0 xk  xn
Here:
nk
ELEN 5346/4304
DSP and Filter Design
 x  xk  
Fall 2008
(11.48.2)
k
(11.48.3)
(11.48.4)
(11.48.5)
49
4. Optimal equiripple design
Having the solution for P, we can compute the error function:
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:
Mˆ 
ELEN 5346/4304
DSP and Filter Design
20lg  s p  13
14.6 s   p   2 
Fall 2008
1
(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.
ELEN 5346/4304
DSP and Filter Design
Fall 2008
51
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
52
Appendix: the ideal transfer functions
LPF:
HPF:
BPF:
BSF:
ELEN 5346/4304
DSP and Filter Design
hLP ,n
sin c n 

,   n  
n
(11.52.1)
hHP,n
1  c  ,n  0

  sin c n 
, n  0

n

(11.52.2)
hBP ,n
sin c 2 n  sin c1n 


, n  0
n
n
(11.52.3)
hBS ,n
 c 2  c1 
1
,n  0




 sin c1n   sin c 2 n  , n  0

n
 n
(11.52.4)
Fall 2008
Download