Linear-phase FIR filters
Finite-duration impulse response (FIR) filter (Order=M-1, Length=M)
•
The impulse response
•
b , 0 n M 1
h( n ) n
else
0,
The system function
1
H ( z ) b0 b1 z bM 1 z
•
1 M
M 1
bn z n
n 0
The difference equation (Linear convolution)
M 1
y ( n ) b0 x ( n ) b1 x ( n 1) bM 1 x ( n M 1) bk x ( n k )
k 0
•
The frequency response (DTFT)
M 1
H ( ) H ( z ) z e j bn e jn
n 0
Linear-phase FIR filters
Linear-phase FIR filter (Order=M-1, Length=M)
•
H ( ) ,
•
= 0, /2.
•
Four types
is a constant
Linear-phase FIR filters
Type-1 linear-phase FIR filter (Symmetrical, M odd)
•
= 0.
= (M-1)/2 (integer)
•
Symmetric about (the index of symmetry)
h(n ) h( M 1 n ),
•
H ( ) H r ( )e j
H r ( ) h(
M 3
2
M 1
M 1
) 2h(n ) cos[(
n )]
2
2
n 0
0 n M 1
Linear-phase FIR filters
Type-2 linear-phase FIR filter (Symmetrical, M even)
•
= 0.
= (M-1)/2 (non-integer)
h(n ) h( M 1 n ),
•
H ( ) H r ( )e j
M / 2 1
H r ( ) 2h(n ) cos[ (
n 0
M 1
n )]
2
0 n M 1
Linear-phase FIR filters
Type-3 linear-phase FIR filter (Antisymmetrical, M odd)
•
= /2.
= (M-1)/2 (integer)
h( n ) h( M 1 n ),
h(( M 1) / 2) 0
•
H ( ) H r ( )e j
M 3
2
H r ( ) 2h( n ) sin[ (
n 0
M 1
n )]
2
0 n M 1
Linear-phase FIR filters
Type-4 linear-phase FIR filter (Antisymmetrical, M even)
•
= /2.
= (M-1)/2 (non-integer)
h( n ) h( M 1 n ),
•
H ( ) H r ( )e j
M / 2 1
H r ( ) 2h(n ) sin[ (
n 0
M 1
n )]
2
0 n M 1
Design Specs (LPF)
• Band [0,p]: pass band
• Band [s, ]: stop band
• Band [p, s]: transition band
• 1: Absolute ripple in pass
band
• 2: Absolute ripple in stop
band
FIR LPF filter specifications: (a) Absolute (b) Relative
• Rp: Relative ripple in pass
band (in dB)
• As: Relative ripple in stop
band (in dB)
Design Specs (LPF)
dB scale 20 log 10
H ( )
H ( ) max
R p 20 log 10
1 1
1 1
As 20 log 10
2
1 1
0
Window Design Techniques
Ideal LPF c= /4-shifted
Ideal LPF c= /4
0.25
0.25
0.2
0.2
0.15
0.15
Shifting
0.1
0.1
0.05
0.05
0
0
-0.05
-0.05
-0.1
-30
-20
-10
0
10
20
-0.1
-30
30
-20
-10
LPF by W indow Design Technique
0.25
0.2
0.15
0.1
0.05
0
-0.05
-0.1
-30
-20
-10
0
10
20
30
0
10
20
30
Window Design Techniques
General Design Procedures:
H IDEAL () : Ideal frequency response (given)
• Step 1
H d ( ) H IDEAL ( )e j
M 1
2
• Step 2
1
hd (n ) IDTFT [ H d ( )]
H d ( )e j n d
2
• Step 3
h(n) hd (n) w(n),
0 n M-1
Window function
• symmetric about over 0 n M-1
• 0 otherwise
Window Design Techniques
Rectangular Window
1, 0 n M 1
w( n )
otherwise
0,
• Exact transition width = s - p = 1.8/M
• Min. stopband attenuation = 21dB
• MATLAB function: w=boxcar (M)
Window Design Techniques
Bartlett Window
2n
M 1
,
0
n
M 1
2
2n
M 1
w( n ) 2
,
n M 1
M 1
2
0, otherwise
• Exact transition width = s - p = 6.1/M
• Min. stopband attenuation = 25dB
• MATLAB function: w=bartlett (M)
Window Design Techniques
Hann Window
2π n
0.5[1 cos(
)], 0 n M 1
w( n )
M-1
0,
otherwise
• Exact transition width = s - p = 6.2/M
• Min. stopband attenuation = 44dB
• MATLAB function: w=hann (M)
Window Design Techniques
Hamming Window
Hamming Window: M=45
1
0.9
0.8
2π n
0.54 0.46 cos(
)], 0 n M 1
w( n )
M-1
0,
otherwise
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
• Exact transition width = s - p = 6.6/M
• Min. stopband attenuation = 53dB
• MATLAB function: w=hamming (M)
0
5
10
15
20
25
30
35
40
45
Window Design Techniques
Blackman W indow: M=45
1
Blackman Window
0.9
0.8
0.7
2π n
4π n
0.42 0.5 cos(
) 0.08 cos(
)], 0 n M 1
w(n )
M-1
M-1
0,
otherwise
0.6
0.5
0.4
0.3
0.2
0.1
0
• Exact transition width = s - p = 11/M
• Min. stopband attenuation = 74dB
• MATLAB function: w=blackman (M)
0
5
10
15
20
25
30
35
40
45
Window Design Techniques
LPF Design
1,
c
H LPF ( )
0, c
j
e
,
c
H d ( )
c
0,
1
hd ( n ) IDTFT [ H d ( )]
H d ( )e jn d
2
sin[ c (n )]
1 c j ( n )
e
d
2 c
(n )
function hd=ideal_lp(wc,M)
%hd: ideal LPF impulse response between 0 and M-1
%wc: cut-off frequencies in radians
%M: length of the filter
alpha=(M-1)/2;
n=[0:M-1];
m=n-alpha;
fc=wc/pi;
hd=fc*sinc(fc*m);
Window Design Techniques
LPF Design
Example: p=0.2
s=0.3
As=50 dB
%Example 1 in FIR filter design
wp=0.2*pi; ws=0.3*pi; tr_width=ws-wp;
M=ceil(6.6*pi/tr_width)+1;
n=[0:M-1];
wc=(ws+wp)/2; %ideal cutoff frequency
hd=ideal_lp(wc,M);
w_hamming=(hamming(M))';
h=hd.*w_hamming;
figure(1);stem(n,h); title('h(n)')
figure(2);freqz(h,[1])
Window Design Techniques
LPF: h(n)
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05
0
10
20
30
40
50
60
70
Window Design Techniques
LPF
Magnitude (dB)
50
0
-50
-100
-150
0
0.2
0.4
0.6
0.8
Normalized Frequency ( rad/sample)
1
0
0.2
0.4
0.6
0.8
Normalized Frequency ( rad/sample)
1
Phase (degrees)
0
-500
-1000
-1500
-2000
Window Design Techniques
BPS example:
1s=0.2, 1p=0.35, 2p=0.65, 2s=0.8
As=60 dB
Two transition band widths must be the same!
Window Design Techniques
%Example 2 in FIR filter design
% BPS design
wp1=0.35*pi; ws1=0.2*pi;
wp2=0.65*pi; ws2=0.8*pi;
%only one transition bandwidth allowed in window design
tr_width=min(wp1-ws1,ws2-wp2);
M=ceil(11*pi/tr_width)+1;
n=[0:M-1];
wc1=(ws1+wp1)/2; %ideal cutoff frequency 1
wc2=(ws2+wp2)/2; %ideal cutoff frequency 2
hd=ideal_lp(wc2,M)-ideal_lp(wc1,M);
w_blackman=(blackman(M))';
h=hd.*w_blackman;
figure(1);stem(n,h); title('h(n)')
figure(2);freqz(h,[1])
Window Design Techniques
BPS: h(n)
0.5
0.4
0.3
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
0
10
20
30
40
50
60
70
80
Window Design Techniques
BPS
Magnitude (dB)
50
0
-50
-100
-150
0
0.2
0.4
0.6
0.8
Normalized Frequency ( rad/sample)
1
0
0.2
0.4
0.6
0.8
Normalized Frequency ( rad/sample)
1
Phase (degrees)
2000
0
-2000
-4000
-6000
Window Design Techniques
Example: Digital differentiator
%Example 2 in FIR filter design
% Digital differentiator design
M=21;alpha=(M-1)/2;n=0:M-1;
hd=(cos(pi*(n-alpha)))./(n-alpha);hd(alpha+1)=0;
w_ham=(hamming(M))';
h=hd.*w_ham;
[H,W]=freqz(h,[1]);
plot(W/pi,abs(H));
title('Digital differentiator: |H(\omega)|')
Window Design Techniques
Digital differentiator: h(n)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
5
10
15
20
Window Design Techniques
Digital differentiator: |H()|
3
2.5
2
1.5
1
0.5
0
0
0.2
0.4
0.6
0.8
1
Window Design Techniques
>> t=linspace(-2,2,1000);
>> xt=sin(2*pi*t);yt=conv(xt,h);
>> subplot(2,1,1);plot(xt);title('x(t)=sin(2\pit)')
>> subplot(2,1,2);plot(yt(22:end));title('y(t)=Dx(t)')
x(t)=sin(2t)
1
0.5
0
-0.5
-1
0
200
400
600
800
1000
600
800
1000
y(t)=Dx(t)
0.04
0.02
0
-0.02
-0.04
0
200
400