Download - Digital Filter Design - uCoz
Digital Filter Design
Chapters 9 and 10Chapters 9 and 10Appendix A and Appendix B
Dr. Iyad Jafar
Outline
I t d tiIntroduction
C Id l Filt TCommon Ideal Filter Types
Selecting FilterT peSelecting Filter Type
Digital IIR Filter DesignDigital IIR Filter Design
Digital FIR Filter DesignDigital FIR Filter Design
2
IntroductionWhat is filtering?
Remove unwanted frequency content in the signal
For LTI systems this can be done using convolution inFor LTI systems, this can be done using convolution inthe with the impulse response of the filter h[n] in thetime domain or multiplication in the frequency domaintime domain or multiplication in the frequency domainwith the frequency response
Filter h[n]
3 x[n] y[n]
IntroductionDigital filter design is the process of identifying theimpulse h[n] response or the transfer function H(z) of aimpulse h[n] response or the transfer function H(z) of asystem that is capable of passing certain frequencycontent of an input signal x[n] and blocking others withcontent of an input signal x[n] and blocking others withthe following considerations
H(z) is realizableH(z) is realizable H(z) is causal H( ) h f fH(z) meets the frequency response specifications H(z) meets the phase response specificationsComplexity of H(z)Is H(z) an IIR or FIR system? y
4
Common Ideal Filter Types The simplest way to design filters is to consider thefrequency response in the ideal casefrequency response in the ideal caseFrequency response of an ideal digital lowpass filter
H( jω)Passband
1
H(ejω)
Stopband
ωω ω π-π -ωc ωc
Cutoff frequency
5
Common Ideal Filter Types Frequency response of an ideal digital highpass filter
1
|H(ejω)|
ωωπ-π -ωc ωc
Frequency response of an ideal digital band-pass filter
1
|H(ejω)|
Frequency response of an ideal digital band pass filter
1
6ω
π-π ωc1 ωc2-ωc1 -ωc2
Common Ideal Filter Types Frequency response of an ideal digital band-reject filter
| ( jω)|
1
|H(ejω)|
ωωω π-π ωc1
These filter are easy to specify !
ωc2-ωc1-ωc2
These filter are easy to specify ! They have unity magnitude in the passband and zero in h b d d h h h ( l f i !)the stopband, and they have zero phase (real functions!)
7Problems?!!!
Common Ideal Filter Types Example 1 – the impulse response of an ideal lowpass filter
0 050.05
0.8
1
0
h[n]
0.4
0.6
H(e
j)
-200 -100 0 100 200-0.05
n-4 -2 0 2 40
0.2
The impulse response is Non causal not absolutely summable and doubly infinite??
n
Non causal, not absolutely summable, and doubly infinite?? Not realizable or stable!?
Solution8
SolutionMagnitude Approximation and ignore the phase!
Magnitude Approximation of Digital Filters
Magnitude approximation g ppincludes
The magnitude responseg pspecifications in the stop and pass bands are given with acceptable
ltolerance
The transition between the pass and stop bands spans a range of frequencies
9
frequencies
Magnitude Approximation of Digital Filters
10
Magnitude Approximation of Digital Filters
Alternatively, magnitude specifications may by given iny, g p y y gnormalized form where the maximum magnitude in thepassband is assumed to be unityp y
11
Magnitude Approximation of Digital Filters
12
Magnitude Approximation of Digital Filters
2Example 2
13
Selection of Filter TypeThe desired filter could be IIR or FIR!For IIR filters, the transfer function should be a real rational ,function of z-1
In this case, H(z) should be stable with lowest order N to reduceIn this case, H(z) should be stable with lowest order N to reduce computational complexityFor FIR filters, the transfer function is a polynomial in z-1 with , p yreal coefficients
For reduced complexity, N should be the smallest
14
p y
Selection of Filter TypeComparison between FIR and IIR
15
Digital IIR Filter DesignGiven the digital filter specifications (δp, δs, ωc, N, FT….), we want to find
that approximates the magnitude response, stable, with lowest order N.
The most common approach is to convert the digital filterf l l f d hspecifications into analog lowpass specifications to determine the
transfer function H(s) of the analog lowpass filter. Then, theobtained H(s) is converted into the digital filter transfer functionobtained H(s) is converted into the digital filter transfer functionH(z).Why this approach?Why this approach?
Analog approximation techniques are highly advanced They result in closed-form solution
16
yMany applications require the digital simulation of analog filters
Digital IIR Filter Design
Digital Filter Convert to Analog Filter
S ifi i i
Spectral Transformation into an Analog Lowpass g ta te
SpecificationsSpecifications Using
Bilinear Transformation
to a a og owpassFilter Prototype (If
needed)
Design the analog Convert H(s) into G(z)
U i Bili
Spectral Transformation to the Required Analog g g
Lowpass Filter H(s)Using Bilinear
Transformation
q gFilter
(If needed)
• We need to know how to • Design lowpass analog filtersDesign lowpass analog filters• Perform spectral transformation between different types of
analog filters
17
g• Perform bilinear transformation
Analog Filter SpecificationsTypical magnitude response of an analog lowpass filter
18
Analog Filter SpecificationsMagnitude specifications can be given in normalized form
19
Analog Lowpass Filter PrototypesButterworth Approximation
20
Analog Lowpass Filter PrototypesButterworth Approximation
21
Analog Lowpass Filter PrototypesButterworth Approximation
22
Analog Lowpass Filter PrototypesButterworth Approximation
E ample 3Example 3
23
Analog Lowpass Filter PrototypesButterworth ApproximationExample 3 – continuedExample 3 continued
In Matlab this can be obtained usingIn Matlab, this can be obtained using
[N,Wc] = buttord(1000,5000,1,40,'s')N = 4
24
N = 4Wc = 1581 Hz
Analog Lowpass Filter PrototypesButterworth Approximation
25
Analog Lowpass Filter PrototypesButterworth ApproximationExample 4 - Determine the transfer function H(s) of aExample 4 Determine the transfer function H(s) of a analog butterworth lowpass filter of order 2 and
2 1000 rad / secSolution
c 2 1000 rad / sec
1 2N 2 Two roots and ⇒j (2 2 1)/4
1 2 1000 e 1000 j1000
j (2 4 1)/42 2 1000 e 1000 j1000
2( 2 1000)( )a( 2 1000)H (s)
(s 1000 j1000)(s 1000 j1000)62 10
26 a 2 6
2 10H (s)s 2000s 2 10
Analog Lowpass Filter PrototypesButterworth ApproximationExample 4 – continuedExample 4 continuedIn Matlab (N = 2, )
% compute the numerator and denumerator of H (s)c 2 1000 rad / sec
% compute the numerator and denumerator of HLP(s)>> [num,den] = butter(2,sqrt(2)*1000,'s') ; % determine the transfer function% determine the transfer function>> tf(num,den)
2e006
% plot the magnitude of the frequency response
--------------------s^2 + 2000 s + 2e006
% plot the magnitude of the frequency response >> W = 0: 0.1 : 6000 ; >> H = freqs(num, den, W);
27
eqs( u , de , );>> plot(W,20*log10(abs(H));
Analog Lowpass Filter PrototypesButterworth ApproximationExample 4 – continuedExample 4 continuedIn Matlab
0
-5
0
15
-10
| (dB
)
-20
-15
|H(
)|
-25
280 1000 2000 3000 4000 5000 6000
-30
(rad/sec)
Analog Lowpass Filter PrototypesOther Approximations
29
Design of Other Analog FiltersHow about highpass, bandpass, band-stop filter? Do we need to specify magnitude approximations for these filters?Given the analog lowpass filter prototypes, can we design
h f l ?other filters? We consider frequency or spectral transformations! (Appendi B)(Appendix B)Basically,
The filter specifications are mapped into a lowpass filterThe filter specifications are mapped into a lowpass filter specifications. The lowpass filter is designed p gThe inverse spectral transformation is applied to obtain the desired filter
30
We consider here the design of analog highpass filter as an example. (refer to Appendix B for other filters).
Design of Other Analog Filters
31
Design of Analog Highpass Filter
32
Design of Analog Highpass FilterExample 5. Design an analog highpass filter such that
Stopband edge frequency of 2 Krad/sec with minimum attenuation of 5 dBPassband edge frequency 4 Krad/sec with maximum attenuation of 1 dBdB
Solution p pˆ
ˆ
p s sˆ* Let 1 rad/sec, then maps to 2 rad/sec for
lowpass filter
c* Now, we compute N and for the lowpass filter as we did in Example 3. This cgives N 2 and 1.6493 rad / sec* The transfer function is obtained as in Example 4 to be
2.72H ( )33
LP.7
s ^ 2 2.332 H (
s)
.s
2 72
Design of Analog Highpass FilterExample 5. Continued
LP D ˆ* Now, we transform H (s) into H (s) by substitutingˆ 4000p p 4000 s
ˆ ˆs s* This gives the desired transfer function of the analog This gives the desired transfer function of the analog highpass filter
02 12 25
D 2 6
2.97ˆ ˆs 1.108 10 sˆH (s 10ˆ3430 s 5.882 1
)s 0
34
Design of Analog Highpass FilterExample 5. ContinuedIn Matlab
% Direct approach [N,Wc] = buttord(4000,2000,1,5,'s')[numHP denHP] butter(N Wc 'high' 's');
% Step-by-step approach wp_HP = 4000 ; ws_HP = 2000 ; wp_LP = 1 ;
LP 1 * HP / HP [numHP,denHP] = butter(N,Wc,'high','s');tf(numHP,denHP)W = 0:0.1:6000 ; hHP = freqs(numHP denHP W);
ws_LP = 1 * wp_HP / ws_HP ;[N,Wc] = buttord(wp_LP,ws_LP,1,5,'s');[numLP,denLP] = butter(N,Wc,'s');[numHP denHP] = lp2hp(numLP denLP 4000); hHP = freqs(numHP,denHP,W);
plot(W,20*log10(abs(hHP)),'linewidth',2)axis([0 max(W) -20 0])xlabel('\Omega' 'fontweight' 'b' 'fontsize' 14)
[numHP,denHP] = lp2hp(numLP,denLP,4000);tf(numHP,denHP)W = 0:0.1:6000 ; H HP = freqs(numHP denHP W); xlabel( \Omega , fontweight , b , fontsize ,14)
ylabel('|H_D(\Omega)| (dB)','fontweight','b','fontsize',14)set(gca,'fontsize',14,'fontweight','b')
H_HP = freqs(numHP,denHP,W);plot(W,20*log10(abs(H_HP)),'linewidth',2)axis([0 max(W) -20 0])xlabel('\Omega','fontweight','b','fontsize',14) set(gca, fontsize ,14, fontweight , b )
grid onxlabel( \Omega , fontweight , b , fontsize ,14)ylabel('|H_D(\Omega)| (dB)','fontweight','b','fontsize',14)set(gca,'fontsize',14,'fontweight','b')
35
(g , , , g , )grid on
Design of Analog Highpass FilterExample 5. Continued
00
-5
B)
-10
HD
()|
(d
-15
|H
0 1000 2000 3000 4000 5000 6000-20
36
0 1000 2000 3000 4000 5000 6000 (rad/sec)
Bilinear Transformation
37
Bilinear Transformation
38
Bilinear Transformation
3.1416
0
39 -10 -5 0 5 10-3.1416
Bilinear Transformation
40
Bilinear TransformationExample 6. Design a digital lowpass IIR filter with thefollowing specificationsωp = 0.2π rad/sample with maximum passband ripple of 0.5dB
0 6 d/ l ith i i t b d tt ti fωs = 0.6π rad/sample with minimum stopband attenuation of15 dB
SolutionSolution
(1) Prewrap frequencies to obtain the analog lowpass filter specs
p p
(1) Prewrap frequencies to obtain the analog lowpass filter specstan( / 2) tan(0.2 / 2) 0.3249 rad/sec
tan( / 2) tan(0 6 / 2) 1 3764 rad/secs stan( / 2) tan(0.6 / 2) 1.3764 rad/sec
41
Bilinear TransformationExample 6. Continued
c
2
(2) Compute N and of the lowpass filter
1⎛ ⎞ 210 2
120log 0.5 0.12201
1
⎛ ⎞⇒⎜ ⎟
⎝ ⎠⎛ ⎞ 2
10
2 2
120log 15 A 31.6228A
l ((A 1) / ) 1/ k1
⎛ ⎞ ⇒⎜ ⎟⎝ ⎠
⎡ ⎤ ⎡ ⎤⎛ ⎞2 210 1
1010 s p
log ((A 1) / ) 1/ k1N = log 22 log ( / ) 1/ k⎡ ⎤ ⎡ ⎤⎛ ⎞⎢ ⎥ ⎜ ⎟⎢ ⎥⎝ ⎠⎢ ⎥⎢ ⎥⎢ ⎥
2a s 2N 2
s c
1 1H ( j )1 ( / ) A
⇒ c 0.5804 rad/sec
42
Bilinear TransformationExample 6. Continued
(3) Find H (s)a
N 2c
a N
(3) Find H (s)
0.5804H (s)(s 0 4104 + 0 4104i)(s 0 4104 0 4104i)
kk 1
(s 0.4104 + 0.4104i)(s 0.4104 - 0.4104i)(s p )
0 3396a 2
0.3396H (s)s 0.8202s 0.3369
(4) Find H(z)
1
1
1 2
1 za 1 2s
(4) Find H(z)0.1561 0.3122 z 0.1561z X(z)H(z) H (s)
1 0 6147z 0 2393z Y(z)11 z 1 0.6147z 0.2393z Y(z)
(5) The system as a difference equationy[n] 0 6147y[n 1] 0 2393y[n 2]
43
y[n] 0.6147y[n 1] 0.2393y[n 2] 0.561x[n] 0.3122 x[n 1] 0.1561x[n 2]
Bilinear TransformationExample 6. Continued
(6) Test the stability of the system Examine the locations ( ) y yof the poles. Since all poles are inside the unit circle, then we can define a stable and causal system
1
0.5
Par
t
0 2
Imag
inar
y
-0.5
I
44 -1 -0.5 0 0.5 1
-1
Real Part
Design of Analog Highpass FilterExample 6. ContinuedIn Matlab
% Direct approach [[N,wc] = buttord(0.2,0.6,0.5,15,'z')[numD denD] butter(N wc 'z')
% Step-by-step approachWp = tan(0.2*pi/2);Ws = tan(0 6*pi/2); [numD,denD] = butter(N,wc,'z')
w = 0:0.001:pi; h = freqz(numD,denD,w);figure
Ws = tan(0.6 pi/2);[N,Wc] = buttord(Wp,Ws,0.5,15,'s')[numA,denA] = butter(N,Wc,'s')[numD denD] = bilinear(numA denA 0 5) figure
zplane(numD,denD)figureplot(w 20*log10(abs(h)) 'linewidth' 2)
[numD,denD] bilinear(numA,denA,0.5)w = 0:0.001:pi; h = freqz(numD,denD,w);figure plot(w,20 log10(abs(h)), linewidth ,2)
axis([0 max(w)+1 -20 .1])xlabel('\omega','fontweight','b','fontsize',14)ylabel('|H(z)| (dB)','fontweight','b','fontsize',14)
figureZplane(numD,denD)figureplot(w,20*log10(abs(h)),'linewidth',2) ylabel( |H(z)| (dB) , fontweight , b , fontsize ,14)
set(gca,'fontsize',14,'fontweight','b')grid on
p ( , g ( ( )), , )axis([0 max(w)+1 -20 .1])xlabel('\omega','fontweight','b','fontsize',14)ylabel('|H(z)| (dB)','fontweight','b','fontsize',14)
45
set(gca,'fontsize',14,'fontweight','b')grid on
Design of Analog Highpass FilterExample 6. Continued
00
-5
B)
-10
H(e
j)|
(d
-15
|H
0 0 2 0 4 0 6 0 8 1-20
46
0 0.2 0.4 0.6 0.8 1 (/ )
Digital FIR Filter DesignFor FIR filters, the FIR transfer function is apolynomial in z-1 with real coefficientspolynomial in z with real coefficients
For reduced complexity N should be the smallestFor reduced complexity, N should be the smallestThere are many techniques for the design ofdigital FIR filters
Windowed Fourier seriesFrequency samplingComputer-based
47
p
Digital FIR Filter Design
48
Digital FIR Filter Design
49
Digital FIR Filter Design
50
Digital FIR Filter Design
51
Digital FIR Filter Design
52
Digital FIR Filter Design
0.8
1
0.8
1
0.4
0.6
Hd(e
j)
0.4
0.6
h d[n]
-4 -2 0 2 40
0.2
-100 -50 0 50 100
0
0.2
100 50 0 50 100n
11
Truncation2M+1 samples
0.6
0.8
1
]0.6
0.8
1
n]
Delay by M samples
0.2
0.4
h t[n]
0.2
0.4
h t[n
53 -10 -5 0 5 10
0
n0 5 10 15 20
0
n
Digital FIR Filter DesignImpulse response of typical filters
0 8
1
0.6
0.8
(ej
)
0.4
Hd(
-3 14 -wc 0 wc 3 140
0.2
3.14 wc 0 wc 3.14
54
Digital FIR Filter DesignImpulse response of typical filters
0 8
1
0.6
0.8
d(ej
)
0 2
0.4
Hd
-3.14 -wc 0 wc 3.140
0.2
55
Digital FIR Filter DesignImpulse response of typical filters
0.8
1
0.6
Hd(e
j)
0.2
0.4
H
-3.14-wc2 -wc1 0 wc1 wc2 3.140
56
Digital FIR Filter DesignImpulse response of typical filters
0 8
1
0.6
0.8
(ej
)
0.4
Hd(
-3 14-wc2 -wc1 0 wc1 wc2 3 140
0.2
3.14 wc2 wc1 0 wc1 wc2 3.14
57
Digital FIR Filter DesignHow to perform truncation?
Truncation of the target impulse response ht[n] is representedTruncation of the target impulse response ht[n] is representedby multiplying the desired impulse response hd[n] with awindow function w[n]
The simplest window function is the rectangular window
0.8
1
0.4
0.6
wR
[n]
-M 0 M0
0.2
58 Any problems?
-M 0 Mn
Digital FIR Filter DesignRecall that multiplication in time is equivalent to convolution in frequencyq y
Thus, Ht(ejω) is obtained by periodic convolution between Hd(ejω) and ψ(ejω)
1
0.8
1
0.6
0.8
Hd(e
j)
0.4
0.6
0.8
WR
(ej
)
0.2
0.4
0 2
0
0.2
W
59
-4 -2 0 2 40
-50 0 50-0.2
Digital FIR Filter Design
0.8
0.6
0 2
0.4
Ht(e
j)
0
0.2
-15 -10 -5 0 5 10 15-0.2
60
Digital FIR Filter Design
61
Digital FIR Filter Design
62
Digital FIR Filter Design
63
Digital FIR Filter Design
64
Digital FIR Filter DesignEstimating the filter order
Kaiser’s Formula
10 p s20 log ( ) 13N
14 6( ) / 2
Bellanger’s Formula
s p14.6( ) / 2
g
10 p s2 log (10 )N 1p
s p
N 13( ) / 2
65
Digital FIR Filter DesignExample 7. Design a digital lowpass FIR filter withthe following specificationsthe following specifications
δp = 0.1 , δs = 0.1, Fp = 1 KHz , Fs = 4KHz F 10KHFT = 10KHz
Solutionωp = 2π * 1000 / 10000 = 0.2 πωs = 2π * 4000 / 10000 = 0.8 π
1020log ( 0.01) 13N 1.59 214 6(0 8 0 2 ) / 2
⎡ ⎤⎢ ⎥
Thus, the minimum length of the filter is L = N+1 = 3 Let ω = (ω + ω )/2 = 0 5 π
14.6(0.8 0.2 ) / 2
66
Let ωc = (ωs + ωp)/2 = 0.5 π
Digital FIR Filter DesignExample 7. ContinuedF L 3 2M+1 3 M 1 Th t t d filtFor L = 3, 2M+1 = 3, so M = 1. The truncated filter starts from n = -1. E l i h [ ] f 1 0 1Evaluating hLP[n] , for n = -1, 0, 1
gives hLP[n] = {0.3183 0.5000 0.3183}
Delaying by M = 1 h [n] = {0 3183 0 5000 0 3183}
67
hLP[n] = {0.3183 0.5000 0.3183}
Digital FIR Filter DesignExample 7. Continued 1.2
1.4
N=2
wc = 0 5*pi ; 0.6
0.8
1
|Ht(e
j)|
wc = 0.5 pi ;N = 2 ; n = -floor((N+1)/2):floor((N+1)/2);
i ( * ) / i /0.2
0.4
y = sin(wc*n) ./pi./n;y(find(isnan(y))) = wc/pi;[h,w] = freqz(y);
0 5
1
N=2
0 0.2 0.4 0.6 0.8 10
figureplot(w/pi,abs(h));figure -0.5
0
0.5
j)g
plot(w/pi,unwrap(angle(h)))
2
-1.5
-1
(e
68 0 0.2 0.4 0.6 0.8 1-2.5
-2
Digital FIR Filter DesignExample 7. Continued
Eff t f filt dEffect of filter order1.4
N=2
1
1.2
N=2N=8N=20N=50
0.8
1
(ej
)|
0.4
0.6|Ht(
0
0.2
690 0.2 0.4 0.6 0.8 1
0
Digital FIR Filter DesignExample 7. Continued
Eff t f t ti ith H i i dEffect of truncation with Hamming window1.4
N=2
1
1.2
N=2N=8N=20N=50
0.8
1
(ej
)|
0.4
0.6|Ht(
0
0.2
700 0.2 0.4 0.6 0.8 1
0
Digital FIR Filter DesignMatlab functions
k i dkaiserordfir1fir2hamming hannbalckmankaiserfdatoolfdatool
71