Digital Filters

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Digital Filter Design

[Reading material: Chapter 10]


Big picture
 We’ve discussed different types of filters

 Finite impulse response (FIR)


– Only zeros (no poles)
– Hopefully causal & stable
– Will use windowing techniques to convert ideal (infinitely long, non-
causal) filter to practical

 Infinite impulse response (IIR)


– Uses poles for feedback
– Inspired by analog filter design

3
Finite Impulse Response Filters
[Reading material: Section 10.2]
Symmetric vs. anti-symmetric
 Want FIR with linear phase
 M taps at times n=0, 1, …, M-1

 Symmetric: h(n)=h(M-1-n)
– H(ω)=Hr(ω)e-jω(M-1)/2
– Magnitude Hr(ω) superposition of cosines
𝜔𝜔 𝑀𝑀−1
− , 𝐻𝐻𝑟𝑟 𝜔𝜔 > 0
2
– Phase Θ 𝜔𝜔 = � 𝜔𝜔 𝑀𝑀−1
− + 𝜋𝜋, 𝐻𝐻𝑟𝑟 𝜔𝜔 < 0
2

 Asymmetric: h(n)=-h(M-1-n)
– Magnitude superposition of sines
– M odd  middle tap @ (M-1)/2 contains zero

10
Highpass / lowpass / other?
 Asymmetric  Hr(ω) superposition of sines  Hr(0)=Hr(π)=0
– Bad for lowpass / highpass
– Feasible for bandpass

 Symmetric  Hr(ω) superposition of cosines


– Hr(0), Hr(π) could be nonzero

 Example: averaging filters


– They are symmetric and lowpass

11
FIR Design with Windowing
Key idea
 Start with desired freq response Hd(ω)
 Convert to hd(n)
 Multiply by window w(n)
 Evaluate “quality” of resulting finite-duration h(n)=hd(n)w(n)
– Iterate (use different window) as needed

hd(n) h(n)
Hd(ω) F-1 Evaluate

reconsider
w(n) window

13
Design criteria
 Choice of window involves:
– Symmetric or anti-symmetric?
– Odd or even M?
– Trade-off between large M (many taps  storage, computation, delay)
and closeness to Hd(ω)

hd(n) h(n)
Hd(ω) F-1 Evaluate

reconsider
w(n) window

14
Impact of window structure
 Recall time domain product, h(n)=hd(n)w(n)

 Frequency domain convolution, H(ω)=Hd(ω)*W(ω)


1 +𝜋𝜋
𝐻𝐻 𝜔𝜔 = � 𝐻𝐻𝑑𝑑 𝜈𝜈 𝑊𝑊 𝜔𝜔 − 𝜈𝜈 𝑑𝑑𝜈𝜈
2𝜋𝜋 𝜈𝜈=−𝜋𝜋
 Note: will evaluate W(ω) at freqs outside (-π,+π); fine because
it’s periodic-2π

15
Example
1, 𝑛𝑛 ∈ {0,1, … , 𝑀𝑀 − 1}
 Start w/rectangular window, 𝑤𝑤 𝑛𝑛 = �
0, 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒
– Effect merely to truncate infinitely long hd(n)
– This is simplest possible window
– However…

 Frequency response
𝑀𝑀−1
1 − 𝑒𝑒 −𝑗𝑗𝜔𝜔𝜔𝜔 sin(𝜔𝜔𝜔𝜔/2)
𝑊𝑊 𝜔𝜔 = � 𝑒𝑒 −𝑗𝑗𝜔𝜔𝜔𝜔 = −𝑗𝑗𝜔𝜔
= 𝑒𝑒 −𝑗𝑗𝜔𝜔(𝑀𝑀−1)/2
1 − 𝑒𝑒 sin(𝜔𝜔/2)
𝑛𝑛=0
sin(𝜔𝜔𝜔𝜔/2)
 Magnitude response, 𝑊𝑊 𝜔𝜔 =
sin(𝜔𝜔/2)
sin(𝜔𝜔𝜔𝜔/2)
 Piecewise linear phase depends on sign of
sin(𝜔𝜔/2)

16
Example continued (Matlab)
 Let’s examine rectangular window numerically
M1=31; % shorter window
M2=61; % longer window
w=1e-4:1e-3:pi; % frequencies being evaluated
H1=sin(w*M1/2)./sin(w/2);
H2=sin(w*M2/2)./sin(w/2);
plot(w,log(abs(H1)),w,log(abs(H2))) 6

 Does larger M help?


2

– Main lobe narrower/taller


-2

-4

– Main lobe same area -6

– But side lobes same height


-8

-10

-12
0 0.5 1 1.5 2 2.5 3 3.5

17
Considerations in window selection
 Want narrow main lobe  quick transitions

 Want side lobes much lower  clean transitions (less Gibbs-


style overshoots)

 Want side lobes to decay quickly

18
Some popular windows
1) Rectangular (no window)

2) Bartlett (triangular in time)


– Triangle = convolution of rectangles
• Each rectangle: width=(M+1)/2
• Triangle: width=M
– Squared Dirichlet response
– Lower side lobes (2X in log scale)
– Main lobe 2X width

3) Hamming window
– Same 2X main lobe width
– Lower side lobes (3X in log scale) than rectangular

19
More windows
4) Hann
– Side lobes taper nicely
– But start higher (2X in log scale)
– Same 2X main lobe width

5) Blackman
– Wider main lobe (3X)
– Low side lobes (4X in log scale)

6) Kaiser: parametric family w/optimal trade-off between main


lobe width & side lobe height

20
Design example
𝑒𝑒 −𝑗𝑗𝜔𝜔(𝑀𝑀−1)/2 , 𝜔𝜔 < 𝜔𝜔𝑐𝑐
 Will design ideal LPF, 𝐻𝐻𝑑𝑑 𝜔𝜔 = �
0, 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒
– Exponent term provides delay of (M-1)/2 samples, corresponding to
middle of filter

𝑀𝑀−1
sin(𝜔𝜔𝑐𝑐 𝜋𝜋(𝑛𝑛− )) 𝑀𝑀−1
2
𝑀𝑀−1 , 𝑛𝑛 ≠
2
 Time response, ℎ𝑑𝑑 𝑛𝑛 = 𝜋𝜋(𝑛𝑛−
2
)
𝜔𝜔𝑐𝑐 𝑀𝑀−1
, 𝑛𝑛 =
𝜋𝜋 2

 Traditional rectangular window truncates to range n=0,…, M-1


– Suffers from Gibbs-style overshoots
– Larger M reduces width of overshoot but not amplitude

21
Design example continued
 To reduce oscillations of finite-duration filter, will use window:
1) Hamming: 2X wider main lobe, ≈3X side lobes ( smaller
oscillations)
2) Hann: 2X wider, 2X lower side lobes, taper off better ( clean
stop band)
3) Blackman: 3X wider, 4X lower side lobes

 The “best” solution depends on application


– Example1: want superb rejection of far-away (in freq) low-amplitude
sinusoids in filtering application  Hann
– Example2: want OK rejection of nearby sinuosoids  Hamming
– Example3: want solid rejection of nearish sinusoids  Blackman

22
Infinite Impulse Response Filters
[Reading material: Section 10.3]
Main idea
 Design of analog filters (resistors, capacitors, inductors, …) has
been around for decades
 Common approach to designing infinite impulse response (IIR)
filters involves
– Design analog filter
– Convert to digital

 How to convert from analog to digital?

24
Rationale for filter conversion
 Recall (ECE 301 & 308) Laplace transfer function H(s)
𝐵𝐵(𝑠𝑠) ∑𝑀𝑀𝑘𝑘=0 𝑏𝑏𝑘𝑘 𝑠𝑠
𝑘𝑘
𝐻𝐻 𝑠𝑠 = = 𝑁𝑁
𝐴𝐴(𝑠𝑠) ∑𝑘𝑘=0 𝑎𝑎𝑘𝑘 𝑠𝑠 𝑘𝑘
 Corresponds to differential equation (continuous time)
𝑁𝑁 𝑀𝑀
𝑑𝑑 𝑘𝑘 𝑑𝑑 𝑘𝑘
� 𝑎𝑎𝑘𝑘 𝑘𝑘 𝑦𝑦 𝑡𝑡 = � 𝑏𝑏𝑘𝑘 𝑘𝑘 𝑥𝑥 𝑡𝑡
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
𝑘𝑘=0 𝑘𝑘=0
 Analogous to difference equation

 Stability requires poles on left hand side of s-plane


– Want jΩ-axis of s-plane to map to unit circle
– Want LHS of s-plans to map into unit circle

25
Conversion #1: approximating derivatives
𝑑𝑑𝑑𝑑 𝑑𝑑𝑦𝑦
 Time derivatives and approximated (using calculus)
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑 𝑥𝑥 𝑛𝑛 −𝑥𝑥(𝑛𝑛−1)
 | ≈ (sampling time T)
𝑑𝑑𝑑𝑑 𝑡𝑡=𝑁𝑁𝑁𝑁 𝑇𝑇
1−𝑧𝑧 −1 1−𝑧𝑧 −1
 Can show that s maps to  𝐻𝐻 𝑧𝑧 = 𝐻𝐻(𝑠𝑠 = )
𝑇𝑇 𝑇𝑇

 Good news: this conversion technique “seems reasonable”

 Bad news: jΩ-axis in s-plane mapped to circle of radius 0.5


centered around z=0.5

26
Conversion #2: sampling h(t)
 The analog filter’s impulse response is ha(t)

 Let’s sample, h(n)=ha(t=nT)

 Good news: also “seems reasonable”

 Bad news: aliasing-like artifacts

27
Conversion #3: bilinear transformation
 In study of functions of complex variables, bilinear
transformations map circles to circles
– From jΩ-axis in s-plane (think of jΩ-axis as infinitely big circle)
– To unit circle in z axis

2 1−𝑧𝑧 −1
 Appropriate complex mapping is 𝑠𝑠 =
𝑇𝑇 1+𝑧𝑧 −1
– T is design parameter
Ω𝑇𝑇
– Can be computed using 𝜔𝜔 = 2 tan−1
2
– Analogous to how quickly we move along jΩ-axis

 Good news: LHS of s-axis maps to interior of unit circle in z

28
Example 10.3.4
𝑠𝑠+0.1
 Consider analog filter 𝐻𝐻𝑎𝑎 𝑠𝑠 =
(𝑠𝑠+0.1)2 +16
 This is LPF whose resonance frequency (a.k.a. natural
frequency in ECE 308) is Ωr=160.5=4
 Want to map resonance frequency to ωr=π/2

 We do so by properly selecting T

Ω𝑟𝑟𝑇𝑇
 𝜔𝜔𝑟𝑟 = 2 tan−1
2
𝜋𝜋 4𝑇𝑇
 = 2 tan−1
2 2
𝜋𝜋 4𝑇𝑇 1
 tan =1= = 2𝑇𝑇  𝑇𝑇 =
4 2 2

29
Example 10.3.4 continued
𝑠𝑠+0.1
 Want to convert 𝐻𝐻𝑎𝑎 𝑠𝑠 = to H(z)
(𝑠𝑠+0.1)2 +16
2 1−𝑧𝑧 −1 1−𝑧𝑧 −1
 Recall 𝑠𝑠 = = 4
𝑇𝑇 1+𝑧𝑧 −1 1+𝑧𝑧 −1
1−𝑧𝑧−1
1−𝑧𝑧 −1 4 +0.1
1+𝑧𝑧−1
 Let’s substitute: 𝐻𝐻 𝑧𝑧 = 𝐻𝐻𝑎𝑎 𝑠𝑠 = 4 = 2
1+𝑧𝑧 −1 1−𝑧𝑧−1
4 +0.1 +16
1+𝑧𝑧−1

 Can simplify this and turn into difference equation


– Extra credit challenge: do so on Moodle message board

30

You might also like