Topic 9: Filter Design: FIR ELEN E4810: Digital Signal Processing 1.

advertisement
ELEN E4810: Digital Signal Processing
Topic 9:
Filter Design: FIR
1. Windowed Impulse Response
2. Window Shapes
3. Design by Iterative Optimization
Dan Ellis
2013-11-20
1
1. FIR Filter Design

FIR filters



no poles (just zeros)
no precedent in analog filter design
Approaches


Dan Ellis
windowing ideal impulse response
iterative (computer-aided) design
2013-11-20
2
Least Integral-Squared Error

Given desired FR Hd(ej!), what is the
best finite ht[n] to approximate it?
best in what sense?

Can try to minimize
Integral Squared Error (ISE) of
frequency responses:
=
1
2
  H d (e )  H t (e )

j
j 2
d
= DTFT{ht[n]}
Dan Ellis
2013-11-20
3
Least Integral-Squared Error


Ideal IR is hd[n] = IDTFT{Hd(ej!)},
(usually infinite-extent)

 hd [n]  ht [n]
By Parseval, ISE  =
2
n=

But: ht[n] only exists for n = -M..M ,
 =
M
hd [ n]  ht [ n]

n =M
minimized by making
ht[n] = hd[n], -M ≤ n ≤ M
Dan Ellis
2013-11-20
2
+
hd [n]

n< M , n> M
2
not altered by ht[n]
4
Least Integral-Squared Error

Thus, minimum mean-squared error
approximation in 2M+1 point FIR is
truncated IDTFT:
ht [n] =

1
2
Hd (ej )ej
n
d
M n
otherwise
0
Make causal by delaying by M points
→ h′t[n] = 0 for n < 0
zero
ht[n]
h't[n]
n
n
–M
Dan Ellis
M
0
2013-11-20
M
2M
5
M
Approximating Ideal Filters

From topic 6,
ideal lowpass
has:
1
0
HLP (e ) =
j
and:
hLP [n] =
sin
−º
n
!c
º
| |< c
c <| |<
h[n]
cn
−!c
!
0.2
0.15
0.1
0.05
0
(doubly infinite)
Dan Ellis
-0.05
-20
-15
2013-11-20
-10
-5
0
5
10
6
15
n
Approximating Ideal Filters
Thus, minimum ISE causal
approximation to an ideal lowpass
sin
ĥLP [n] =
Causal shift
c (n
M)
(n M )
0
0
hLP[n]

n
2M
otherwise
1.2
1
0.8
0.6
0.4
0.2
0
-0.2
0
5
10
15
20
25
2M+1 points
Dan Ellis
2013-11-20
7
n
Gibbs Phenomenon
Truncated ideal filters have Gibbs’ Ears:
Increasing filter length
→ narrower ears
(reduces ISE)
but height the same
Ht(ejW)

1.2
Gibbs ‘ears’
1
(~9% overshoot)
0.8
0.6
0.4
→ not optimal by
minimax criterion
0
-0.2
Dan Ellis
129
point
0.2
0
0.2
2013-11-20
25
point
0.4
0.6
0.8
8
WP
Where Gibbs comes from

Truncation of hd[n] to 2M+1 points is
multiplication by a rectangular window:
ht [n] = hd [n] · wR [n]
wR [n] =

1
0
M n
otherwise
h[n]
0.2
0.15
M
wR[n]
0.1
0.05
0
-0.05
-20
-15
-10
-5
0
5
10
Multiplication in time domain is
convolution in frequency domain:
g[n] · h[n]
Dan Ellis
1
2
G(ej )H(ej(
2013-11-20
)
)d
9
15
n
Where Gibbs comes from

Thus, FR of truncated response
is convolution of ideal FR
and FR of rectangular window (pd.sinc):
P
P
Hd(ej!)
Dan Ellis
W
P
P
DTFT{wR[n]}
periodic sinc...
sin Nx
sin x
2013-11-20
W
P
W
P
Ht(ej!)
convanim.mp4
10
Where Gibbs comes from

Rectangular window:
1
0
wR [n] =


M n
otherwise
WR (e ) =
M
=
Mainlobe width
( / 1/L) determines
transition band
Sidelobe height
determines ripples
WR(ejW)
Mainlobe
pP
2M + 1
Sidelobes
0
≈ invariant
with length
Dan Ellis
M
j n
e
n= M
sin(2M +1) 2
sin 2
j
-P
-0.5P
0
0.5P
“periodic sinc”
2013-11-20
11
P
W
2. Window Shapes for Filters



Windowing (infinite) ideal response
→ FIR filter: ht [n] = hd [n]  w[n]
Rectangular window has best ISE error
Other “tapered windows” vary in:



mainlobe → transition band width
sidelobes → size of ripples near transition
Variety of ‘classic’ windows...
Dan Ellis
2013-11-20
12
Window Shapes for FIR Filters
Rectangular:
w[n] = 1 M  n  M

Hann:
0.5 + 0.5 cos(2 2Mn +1)
 Hamming:
0.54 + 0.46 cos(2 2Mn +1)
 Blackman:
0.42 + 0.5 cos(2 2Mn +1)
+0.08 cos(2 2M2n+1)

Dan Ellis
20
1
big
sidelobes!
15
10
0.5
5
0
-10
-5
0
5
10
n
0
0
8
1
0.4
0.6
0.8
PW
double width
mainlobe
6
4
0.5
0.2
2
0
-10
-5
0
5
10
n
0
0
8
1
4
2
0
-10
-5
0
5
10
n
0
0
8
1
0.6
0.8
PW
0.2
0.4
0.6
0.8
PW
triple width
mainlobe
6
4
0.5
0.4
reduced 1st
sidelobe
6
0.5
0.2
2
0
-10
-5
2013-11-20
0
5
10
n
0
0
0.2
0.4
13
0.6
0.8
PW
Window Shapes for FIR Filters
Comparison on dB scale:
\W(ejW)\ / dB

0
Blackman
Hann
-10
Rectangular
-20
-30
-40
-50
Hamming
-60
-70
-80
Dan Ellis
2º
2M+1
0
0.1
0.2
0.3
0.4
0.5
0.6
2013-11-20
0.7
0.8
0.9
W
P
14
Adjustable Windows
So far, discrete main-sidelobe tradeoffs..
 Kaiser window = parametric, continuous
tradeoff:
I0  1  ( Mn )2
M  n  M
modified zero-order w[n] =
I0 ( )
Bessel function
 Empirically, for min. SB atten. of Æ dB:

(
=
0.11(
0.58(
0
Dan Ellis
8.7)
21)0.4 + 0.08(
21)
)
> 50
21
< 21
2013-11-20
required
order
50
N=
8
2.3
transition
width
15
Windowed Filter Example



Design a 25 point FIR low-pass filter
with a cutoff of 600 Hz (SR = 8 kHz)
No specific transition/ripple req’s
→ compromise: use Hamming window
Convert the frequency to radians/
600 cyc/sec
600  2 = 0.15

=
sample: c 8000
/ 8000 samp/sec
x 2π rad/cyc
= 0.15π rad/samp
H(ej!)
0.15 º
600 Hz
Dan Ellis
º
4 kHz
2013-11-20
!
2º
8 kHz (fs)
16
Windowed Filter Example
Get ideal filter impulse response:
n
 c = 0.15  hd [n] = sin 0.15
n
2. Get window:
Hamming @ N = 25 → M = 12 (N = 2M+1)
 w[n] = 0.54 + 0.46 cos(2 25n ) 12  n  12
3. Apply window:
h[n]
1.
0.15
0.1
h[n] = hd [n]  w[n]
0.05
0
n 0.54 + 0.46 cos 2 n
= sin 0.15
12  n  12
(
n
25 )
-20
Dan Ellis
2013-11-20
-10
0
n
10
17
M
Freq. Resp. (FR) Arithmetic
wouldn’t work if
phases were nonzero!

Ideal LPF has pure-real FR i.e.
µ(!) = 0, H(ej!) = |H(ej!)|
→ Can build piecewise-constant FRs by
combining ideal responses, e.g. HPF:
1
!
+
0
-1
!
=
=
1
−º
Dan Ellis
−!c
±[n]
+
-hLP[n]
!c
º
!
2013-11-20
i.e. H(ej!) = 1
HLP(ej!) = 1
for |!| < !c
hHP[n] = ±[n] - (sin!cn)/ºn
18
3. Iterative FIR Filter Design


Can derive filter coefficients by
iterative optimization:
Filter coefs
h[n]
Goodness of fit
criterion
→ error "
Update filter
to reduce "
Estimate
derivatives
∂"/∂h[n]
Desired
response
H(ej!)
Gradient descent / nonlinear optimiz’n
Dan Ellis
2013-11-20
19
Error Criteria
p
j
j
 =  R W ( )  [D(e )  H (e )] d
error
measurement error
actual
desired
region
weighting response response
exponent:
2 → least sq
∞ → minimax
R
H(ejW)
W1
W(W)
E(W)
Dan Ellis
W2 W3
D(ejW)
W4
W
W
W = W(!)·[D(ej!) – H(ej!)]
2013-11-20
20
Minimax FIR Filters

Iterative design of FIR filters with:



equiripple (minimax criterion)
linear-phase
→ symmetric IR h[n] = (–)h[-n]
(type I
order 2M)
n
M
Recall: Symmetric FIR filters have FR
j
 jM ˜
H e
=e
H ( ) with pure-real H̃
( )
H˜ ( ) = 
M
k=0
a[k ] cos(k )
a[0] = h[M]
a[k] = 2h[M - k]
i.e. combo of cosines of multiples of !
Dan Ellis
2013-11-20
21
Minimax FIR Filters

k=0
Now, cos(k!) can be expressed as a
polynomial in cos(!)k and lower powers


M
˜
H ( ) =  a[k ] cos(k )
e.g. cos(2!) = 2(cos!)2 - 1
Thus, we can find Æs such that
M
H̃(⇥) =
M
a[k]cos(k⇥) =
k=0

Dan Ellis
[k](cos⇥)
k
k=0
Mth order
polynomial in cos!
Æ[k]s easily lead to a[k]s
2013-11-20
22
Minimax FIR Filters
M
k
M order
˜
H ( ) =   [k ](cos  ) polynomial in cos!
k=0
th

An Mth order polynomial has at most
M - 1 maxima and minima:
M
H̃( )
[k](cos )k
cosW
k=0
0.2
5th order 0.1
polynomial 0
in cos! -0.1
0.2
0.1
3
3
2
4
-1
W
0
cosW
2
4
-0.1
-0.2
WP
1
1
-0.2
-0.5
0
0.5
1
W
0
0.2
0.4
0.6
0.8
P
 H˜ ( ) has at most M-1 min/max (ripples)
Dan Ellis
2013-11-20
23
Alternation Theorem
H˜ ( ) is the unique, best, weightedminimax order 2M approx. to D(ej!)


For “extremal” freqs
 0 < 1 < ... <  M <  M +1 over ! subset R

Error magnitude is equal at each extrema:
 ( i ) =  i

Peak error alternates in sign:

H˜ ( ) has at least M+2 “extremal” freqs
Dan Ellis
 ( i ) =  ( i+1 )
2013-11-20
24
Alternation Theorem

Hence, for a frequency response:
D(ejW) desired frq.resp.
1
0.8

If "(!) reaches a peak
error magnitude " at
some set of extremal
frequences !i

And the sign of the peak
error alternates
And we have at least
M+2 of them
Then optimal minimax
H(ejW) response mag.
0.6
0.4
E scaled error
W(W)
0.2
bound
W
0
Wp
0
Wc
P
band-edge extrema
E
E(W)
error 0

-E
W0
W1 W2
W3W4 W5
W6
local min/max extrema

(10th order filter, M = 5)
Dan Ellis
2013-11-20
25
Alternation Theorem


By Alternation Theorem,
M+2 extrema of alternating signs
optimal minimax filter
But H˜ ( ) has at most M-1 extrema
need at least 3 more from band edges

2 bands give 4 band edges
can afford to “miss” only one

Alternation rules out transition band
edges, thus have 1 or 2 outer edges
Dan Ellis
2013-11-20
26
Alternation Theorem

For M = 5 (10th order):



Dan Ellis
8 extrema (M+3,
4 band edges)
- great!
7 extrema (M+2,
3 band edges)
- OK!
6 extrema (M+1,
only 2 transition
band edges)
→ NOT OPTIMAL
2013-11-20
1
~
H1W
0.5
0
0
0.2
0.4
0.6
0.8
P
0.4
0.6
0.8
P
0.4
0.6
0.8
P
W
1
~
H2W
0.5
0
0
0.2
W
1
~
H3W
0.5
0
0
0.2
27
W
Parks-McClellan Algorithm

To recap:




FIR CAD constraints
D(ej!), W(!) → "(!)
Zero-phase FIR
~
H(!) = ßkÆkcosk! → M-1 min/max
Alternation theorem
optimal → ≥ M+2 pk errs, alter’ng sign
Hence, can spot ‘best’ filter when we
see it – but how to find it?
Dan Ellis
2013-11-20
28
Parks-McClellan Algorithm


~
~
Alternation → [H(!)-D(!)]/W(!) must =
±" at M+2 (unknown) frequencies {!i}...
Iteratively update h[n] with
Remez exchange algorithm:





estimate/guess M+2 extremals {!i}
solve for Æ[n], " ( → h[n] )
find actual min/max in "(!) → new {!i}
repeat until |"(!i)| is constant
Converges rapidly!
Dan Ellis
2013-11-20
29
M
Parks-McClellan Algorithm

In Matlab,
band edges ÷ º
filter order (2M)
>> h=firpm(10,
[0 0.4 0.6 1],
[1 1 0 0],
desired magnitude
at band
edges [1 2]); error weights
per band
0.6
0.4
h[n]
~
H(W)
1
1
0.5
0.2
0
0.5
-0.5
0
-0.2
Dan Ellis
-5
0
5
n
0
0
0.5
2013-11-20
W
1
z-plane
-1
-1
0
1
2
30
Download