Professional Documents
Culture Documents
= O O < <
}
( ) [ ]
jn
n
H h n e
O
=
O =
Phase Distortion
Phase distortion results from a variable
time delay (phase delay) for different
frequency components of a signal.
If the phase response of a filter is a linear
function of frequency, then the phase
delay is constant for all frequencies and no
phase distortion occurs.
Linear Phase
An input signal (blue sinusoid) processed in the pass-
band of a filter (output red sinusoid) will, in general,
experience a phase change (
1
to
2
) and a time delay (t
1
to t
2
).
Linear Phase (Analog Filter)
1 1 2 2
t t + = +
2 1 2 1
2 1
2 1
0 ( ) ( )
( ) Phase delay
( ) Phase change
t t
t t t
- + - =
- = D =
- = D =
0 t D + D =
2
t
f
D D
D = - = -
D = - kf
This is the phase change condition for constant
phase delay independent of frequency: the phase
change is a linear function of frequency
The output amplitude equals the input
amplitude in the pass-band
Linear Phase (Digital Filter)
sample delay
s
s
s
t nT
t
n tf
T
A = A
A
A = = A =
0 n WD + D =
n
n k
k
u
u
A
A =
O
A =
A = O
n is a constant if t is constant
The condition for n being constant is that
be a linear function of
The output amplitude equals the input
amplitude in the pass-band
Group delay
D
-
W
d
d
A constant group delay is a signature of linear
phase
Constant Phase vs. Linear Phase
>> t=0:.04/1000:.04; % The small increment of t approximates an analog signal
>> f0=50;
>> term1=(2/pi)*sin(2*pi*(f0)*t);
>> term2=(2/(3*pi))*sin(2*pi*(3*f0)*t);
>> term3=(2/(5*pi))*sin(2*pi*(5*f0)*t);
>> term4=(2/(7*pi))*sin(2*pi*(7*f0)*t);
>> s=term1+term2+term3+term4;
>> plot(t*1000,s);title('4 Term Square Wave');xlabel('milliseconds');
0 5 10 15 20 25 30 35 40
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
4 Term Square Wave
milliseconds
Zero phase
change for each
sinusoid
Constant Phase vs. Linear Phase
>> term1=(2/pi)*sin(2*pi*(f0)*t+pi/6);
>> term2=(2/(3*pi))*sin(2*pi*(3*f0)*t+pi/6);
>> term3=(2/(5*pi))*sin(2*pi*(5*f0)*t+pi/6);
>> term4=(2/(7*pi))*sin(2*pi*(7*f0)*t+pi/6);
>> s=term1+term2+term3+term4;
>> plot(t*1000,s);
>> title('4 Term Square Wave with Constant 30 deg Phase');xlabel('milliseconds');
0 5 10 15 20 25 30 35 40
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
4 Term Square Wave with Constant 30 deg Phase
milliseconds
A constant phase
change of +30
degrees for each
sinusoid results in
phase distortion.
Constant Phase vs. Linear Phase
>> term1=(2/pi)*sin(2*pi*(f0)*t-.01*pi*(f0));
>> term2=(2/(3*pi))*sin(2*pi*(3*f0)*t-.01*pi*(3*f0));
>> term3=(2/(5*pi))*sin(2*pi*(5*f0)*t-.01*pi*(5*f0));
>> term4=(2/(7*pi))*sin(2*pi*(7*f0)*t-.01*pi*(7*f0));
>> s=term1+term2+term3+term4;
>> plot(t*1000,s);title('4 Term Square Wave with 5ms Phase Delay');xlabel('milliseconds')
0 5 10 15 20 25 30 35 40
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
4 Term Square Wave with 5ms Phase Delay
milliseconds
005
2 2 2
.
kf k
t
f f
- D
D = - = - = - =
Computed with a constant
phase (time) delay of 5 ms
and linear phase. Linear
phase results in no phase
distortion.
01 . k = -
01 . f D = -
Sufficient Condition for Linear
Phase
If a FIR filter consists of an odd number of
coefficients, M + 1, where M is even, and is
symmetrical about the M/2 term, the filter has a
linear phase response of = (M/2). The
filter will have a group delay of M/2
This is termed a type I filter (odd length and
positive symmetry). Other types have different
permutations of length and symmetry. This type
is the most common and easiest to design.
Sufficient Condition for Linear
Phase
-1 0 1 2 3 4 5 6
-3
-2
-1
0
1
2
3
n
h
[
n
]
Shifted Symmetrical Impluse Response
1. Odd number of impulse
response values
2. Symmetry point: n=2
3. Equal values of the
impulse response about
the symmetry point
4. Group delay = 2
Sufficient Condition for Linear
Phase
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.9
1.8
2.7
3.6
4.5
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude and Phase Responses
-300
-240
-180
-120
-60
0
P
h
a
s
e
(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1
1.2
1.4
1.6
1.8
2
2.2
2.4
2.6
2.8
3
Normalized Frequency (t rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
>> h=[-1,1,2,1,-1];
>> fvtool(h,1)
Sufficient Condition for Linear Phase
The Running Average Filter
>> n=0:6;
>> raf7=(1/7)*ones(1,7);
>> stem(n,raf7)
>> xlabel('n');ylabel('h[n]');
>> title('Impulse Response of a 7-Point Running Average Filter')
>> axis([-1 7 0 .16])
>> fvtool(raf7,1)
-1 0 1 2 3 4 5 6 7
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
n
h
[
n
]
Impulse Response of a 7-Point Running Average Filter
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.2
0.4
0.6
0.8
1
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude and Phase Responses
-200
-140
-80
-20
40
100
P
h
a
s
e
(
d
e
g
r
e
e
s
)
The Ideal Low-Pass Filter
0
-
0
H()
1
-
Impulse Response of the Ideal LP
Filter
0
0
0
0
0 0
0 0
0
1
[ ] ( )
2
1 -
H( ) =
0 otherwise
1
[ ]
2
1
2
1 1
2
1
[ ] sin( )
j n
j n
j n
jn jn
h n H e d
h n e d
e
jn
e e
n j
or
h n n
n
t
t
t
t
t
t
t
O
O
O
O
O
O
O
O O
= O O
O s O s O
= O
=
(
=
= O
}
}
| |
0 0
0 0
0
0
0 0 0
1 1
[0]
2 2
1 1
( ) (2 )
2 2
j
h e d d
t t
t t t
O O
O
O O
= O = O =
O
O O = O =
} }
0
0
0
[ ]
1
sin( ) 0
n
h n
n n
n
t
t
O
=
O =
x
x
x
) sin(
) ( sinc =
( )
0 0 0
0
0
1 1
[ ] sin( ) sin c( )
[ ] sinc( ) -
h n n n n
n n
or
h n n n
t t
t
| |
= O = O O
|
\ .
O
= O < <
Impulse Response of the Ideal LP
Filter
The impulse response of the ideal low pass filter is:
It is easily seen that this impulse response has linear phase
because it has the symmetry property of h[-n] = h[n]
As given, however, this impulse response is not computable: it is
infinite and anti-causal
A finite set of M+1 h[n] values can be delayed by M/2 samples to
create a finite and causal h[n]
Creating the finite and causal impulse response will affect some filter
properties, but not its linear phase response
0
0
[ ] sinc( ) - h n n n
t
O
= O < <
Example:
21 Coefficient LP Filter with
0
= /4
>> n=0:20;
>> omega=pi/4; % This is the cut-off frequency
>> h=(omega/pi)*sinc(omega*(n-10)/pi); % Note the 10 step shift
>> stem(n,h)
>> title('Sample-Shifted LP Impulse Response')
>> xlabel('n')
>> ylabel('h[n]')
>> fvtool(h,1)
0 2 4 6 8 10 12 14 16 18 20
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
Sample-Shifted LP Impulse Response
n
h
[
n
]
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Note the linear phase properties
of the impulse response
Example:
201 Coefficient LP Filter with
0
= /4
>> n=0:200; % This sets the order of the filter where length(n)=201
>> omega=pi/4;
>> h=(omega/pi)*sinc((n-100)*omega/pi); %Note the sample shift of 100 samples
>> fvtool(h,1)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Higher order = sharper
transition
Side-lobe ripple
(Gibbs phenomenon)
due to abrupt
truncation of the
impulse response
Tapering Windows
Used to taper the abrupt truncation of the
impulse response towards zero
Example: Hamming window
2
54 46
1
[ ] . . cos
n
w n
N
= +
-
[ ] [ ] [ ]
W
h n w n h n =
Effect of Tapering Windows
>> n=0:20;
>> omega=pi/4;
>> h=(omega/pi)*sinc((n-10)*omega/pi);
>> w=0.54+0.46*cos(2*pi*(n-10)/20);
% This is the Hamming window. Note that
% N-1 = 20 in this case
>> hw=h.*w;
% Note the use of .* to multiply h and w
% sample-by-sample
>> stem(n,w)
>> title('Hamming Window')
>> figure,stem(n,h,'ko')
>> hold
>> stem(n,hw,'bd')
>> title('Comparison of Rectangular and Hamming
Window Impulse Response')
>> legend('Rectangular','Hamming')
>> fvtool(hw,1)
0 2 4 6 8 10 12 14 16 18 20
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
Comparison of Rectangular and Hamming Window Impulse Response
Rectangular
Hamming
Effect of Tapering Windows
0 2 4 6 8 10 12 14 16 18 20
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
Comparison of Rectangular and Hamming Window Impulse Response
Rectangular
Hamming
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Effect of Tapering Windows
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
-140
-120
-100
-80
-60
-40
-20
0
20
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
The Ideal High Pass Filter
- -
0
0
1
H()
The Ideal High Pass Filter
0
0
0
0
0 0
0 0
1
2
1 1
2 2
1 1 1 1
2 2
1 1 1 1
2 2
1 1 1 1
2 2
[ ] ( )
j n
j n j n
j n j n
j n j n j n j n
j n j n j n j n
h n H e d
e d e d
e e
jn jn
e e e e
n j n j
e e e e
n j n j
p
W
-
- W
W W
- W
- W
W W
- W
- W - W
W - W -
= W W
= W+ W
= +
= - + -
= - + + -
0
1 1
sin( ) sin( )
n n
n n
= - W
0
0
[ ] sinc( ) sinc( )
h n n n n
W
= - W - < <
Design Example:
201 Coefficient HP with
0
= 3/4
>> n=0:200;
>> omega=3*pi/4;
>> h=sinc(n-100)-(omega/pi)*sinc(omega*(n-100)/pi); % Both terms shifted by 100
% samples
>> hw=h.*blackman(201)';
>> fvtool(hw,1)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
-200
-150
-100
-50
0
50
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
The Blackman tapering
window provides greater
suppression of stop-
band side-lobes
Band-Stop and Band-Pass Filters
0
L
H
1
H
BR
= H
LP
+ H
HP
H
LP
H
HP
H
LPL
H
LPH
L
H
0
H
LPH
- H
LPL
1
h
br
= h
LP
+ h
HP
h
bp
= h
LPH
- h
LPL
Band-Stop and Band-Pass
Examples
>> n=0:200;
>> fs=2000;
>> omegaL=2*pi*400/fs;
>> omegaH=2*pi*600/fs;
>> hLPL=(omegaL/pi)*sinc(omegaL*(n-100)/pi).*hamming(201)';
>> hLPH=(omegaH/pi)*sinc(omegaH*(n-100)/pi).*hamming(201)';
>> hHP=(sinc(n-100)-(omegaH/pi)*sinc(omegaH*(n-100)/pi)).*hamming(201)';
>> h_bandpass=hLPH-hLPL;
>> h_bandreject=hLPL+hHP;
>> fvtool(h_bandpass,1)
>> fvtool(h_bandreject,1)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
-140
-120
-100
-80
-60
-40
-20
0
20
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
-120
-100
-80
-60
-40
-20
0
20
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Effect of Group Delay
(Order 200 Filter)
>> m=1:250; % The sinusoid will have a length of 250 samples
>> f=2*pi*100/fs;
>> x=sin(f*m);
>> y=filter(hLPL,1,x); % The filter command executes the filter on the signal x
>> subplot(2,1,1),plot(x),title('Input 100 Hz Sinusoid'),axis([0,250,-2,2]);
>> subplot(2,1,2),plot(y),title('Low-Pass Filter Output'),axis([0,250,-2,2]);
0 50 100 150 200 250
-2
-1
0
1
2
Input 100 Hz Sinusoid
0 50 100 150 200 250
-2
-1
0
1
2
Low-Pass Filter Output
Sampling Method of FIR Design
Basic Theory
The sampling method is based on the principle that the DFT is a
sample of the DTFT
To see this, take the DFT of the frequency response of a filter:
>> n=0:10; % Design a low pass filter by the window method
>> omega=pi/4;
>> h1=(omega/pi)*sinc(omega*(n-5)/pi);
>> dtft_demo(h1,0,2*pi,512); % Display the DTFT of the filter
>> hold
>> [H1,f]=dft_demo(h1); % Take the DFT of the filter
>> stem(f/pi,abs(H1),'k');
>> legend('DTFT of h1','DFT of h1')
>> title('Fourier Transforms of the Impulse Response h1')
>> hold off
DFT and DTFT of a Filter
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Fourier Transforms of the Impulse Response h1
Units of Pi
DTFT of h1
DFT of h1
Sampling Method of FIR Design
Basic Theory
Evenly spaced samples of the frequency response in the frequency
range = 0 to 2 represents the discrete Fourier transform (DFT) of
a finite impulse response of the same length
Therefore, given the frequency response, the impulse response can
be computed from the inverse DFT of the frequency response
1
2
0
[ ] [ ]
0,1, 2,... 1
k
N
j n
N
n
H k h n e
k N
t
=
=
=
1
2
0
1
[ ] [ ]
0,1,... 1
k
N
j n
N
k
h n H k e
N
n N
t
=
=
=