Professional Documents
Culture Documents
H ( )
n
h[n]e jn
1
H ( ) e
jn
h[n] d for - n
2
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
(t2 - t1 ) + (2 - 1 ) = 0
(t2 - t1 ) = D t = Phase delay
(2 - 1 ) = D = Phase change
D t + D = 0
D D
Dt = - =-
2f
This is the phase change condition for constant
D = - kf phase delay independent of frequency: the phase
change is a linear function of frequency
Linear Phase (Digital Filter)
The output amplitude equals the input
WD n + D = 0 amplitude in the pass-band
t nTs
t
n tf s sample delay n is a constant if t is constant
Ts
n
n k
The condition for n being constant is that
k be a linear function of
dD
Group delay - A constant group delay is a signature of linear
dW 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.4
Zero phase
0.2 change for each
sinusoid
0
-0.2
-0.4
-0.6
-0.8
0 5 10 15 20 25 30 35 40
milliseconds
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.8
0.6
-0.8
-1
0 5 10 15 20 25 30 35 40
milliseconds
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')
4 Term Square Wave with 5ms Phase Delay
0.6
-0.8
0 5 10 15 20 25 30 35 40 D = - .01f
milliseconds
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
Shifted Symmetrical Impluse Response
3
0
impulse response about
-1
the symmetry point
4. Group delay = 2
-2
-3
-1 0 1 2 3 4 5 6
n
Sufficient Condition for Linear
Phase
>> h=[-1,1,2,1,-1];
>> fvtool(h,1)
2.8
(in samples)
2.4
delay(degrees)
2.7 -120 2.2
Magnitude
Phase
1.8 -180 1.8
Group
1.6
0.9 -240
1.4
1.2
0 -300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
Normalized Frequency ( rad/sample)
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)
Magnitude and Phase Responses
Impulse Response of a 7-Point Running Average Filter
0.16 1 100
0.14
0.8 40
0.12
Phase (degrees)
0.1 0.6 -20
Magnitude
h[n]
0.08
0.4 -80
0.06
0.04
0.2 -140
0.02
0 0 -200
-1 0 1 2 3 4 5 6 7 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
n Normalized Frequency ( rad/sample)
The Ideal Low-Pass Filter
H()
- -0 0
Impulse Response of the Ideal LP
Filter
1
jn 1 0 1 0
h[n] H ( ) e d h[0] e j 0 d d
2 2 0 2 0
1 -0 0 1 1
0 (0 ) (20 ) 0
H() = 2 2
0 otherwise
1 0 jn 0
n0
h[n]
2 0
e d
h[n]
1 sin( n) n0
1 jn 0 n
0
e
2 jn 0
sin( x)
1 1 jn0 sinc ( x)
e e jn0 x
n 2 j 1 1
h[n] sin(0 n) 0 n sin c(0 n)
or n n
1 or
h[n] sin(0 n) 0
n h[n] sinc(0 n) - n
Impulse Response of the Ideal LP
Filter
The impulse response of the ideal low pass filter is:
0
h[n] sinc(0 n) - n
0.2 1.2
0.15 1
Magnitude
0.1 0.8
h[n]
0.05 0.6
0 0.4
-0.05 0.2
-0.1 0
0 2 4 6 8 10 12 14 16 18 20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
n Normalized Frequency ( rad/sample)
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)
Magnitude Response
1.4
Higher order = sharper
1.2
transition
1
Magnitude
0.8
0.6
Side-lobe ripple
(Gibbs phenomenon)
0.4
due to abrupt
0.2
truncation of the
impulse response
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
Tapering Windows
Used to taper the abrupt truncation of the
impulse response towards zero
Example: Hamming window
2n
w[n] = .54 + .46 cos
N - 1
hW [n] = w[n]h[n]
Effect of Tapering Windows
>> n=0:20; >> stem(n,w)
>> omega=pi/4; >> title('Hamming Window')
>> h=(omega/pi)*sinc((n-10)*omega/pi); >> figure,stem(n,h,'ko')
>> w=0.54+0.46*cos(2*pi*(n-10)/20); >> hold
% This is the Hamming window. Note that >> stem(n,hw,'bd')
% N-1 = 20 in this case >> title('Comparison of Rectangular and Hamming
>> hw=h.*w; Window Impulse Response')
% Note the use of .* to multiply h and w >> legend('Rectangular','Hamming')
% sample-by-sample >> fvtool(hw,1)
Comparison of Rectangular and Hamming Window Impulse Response
0.25
Rectangular
Hamming
0.2
0.15
0.1
0.05
-0.05
-0.1
0 2 4 6 8 10 12 14 16 18 20
Effect of Tapering Windows
Comparison of Rectangular and Hamming Window Impulse Response
0.25
Magnitude Response
1.4
Rectangular
Hamming
0.2
1.2
0.15
1
0.1
Magnitude
0.8
0.05 0.6
0 0.4
-0.05 0.2
-0.1 0
0 2 4 6 8 10 12 14 16 18 20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
Effect of Tapering Windows
Magnitude Response (dB)
20
-20
-40
Magnitude (dB)
-60
-80
-100
-120
-140
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
The Ideal High Pass Filter
- -0 0
H()
The Ideal High Pass Filter
1
h[n] =
2 -
H (W)e jWn dW
1 - W0 jWn 1 p
=
2 -
e dW+
2 W0
e jWn dW
1 1 jWn - W0 1 1 jWn
= e - + e W
2 jn 2 jn 0
1 1 - jW0n - jn 1 1 jn jW0 n
= e - e + e - e
n 2 j n 2 j
1 1 jW0n 1 1 jn
= - e + e- jW0n + e - e - jn
n 2 j n 2 j
1 1
= sin(n) - sin(W0 n)
n n
W0
h[n] = sinc(n) - sinc(W0 n) - < n<
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)
Magnitude Response (dB)
50 The Blackman tapering
window provides greater
0 suppression of stop-
band side-lobes
Magnitude (dB)
-50
-100
-150
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
Band-Stop and Band-Pass Filters
HBR = HLP + HHP
1
HLP HHP
HLPH - HLPL
HLPL HLPH
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
-20 -20
Magnitude (dB)
-40
Magnitude (dB)
-40
-60
-60
-80
-80
-100
-120 -100
-140 -120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample) Normalized Frequency ( rad/sample)
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]);
-1
-2
0 50 100 150 200 250
-1
-2
0 50 100 150 200 250
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:
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Units of Pi
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
N 1 j 2
k
H [k ] h[n]e
n
N
n 0
k 0,1, 2,...N 1
[H,omega]=selectH_lp(0,M+1) or
[H,omega]=selectH_hp(0,M+1)
Steps in a Sampling Design
Step 4: Create a causal frequency response by
delaying the response by M/2 steps
H_delay=exp(-j*omega*M/2).*H
Step 5: Compute the impulse response of the
delayed frequency response using the inverse
discrete Fourier transform
h=inv_dft_demo(H_delay)
Step 6: Window the impulse response with a
tapering window function; for example:
hw=h.*hamming(length(h))'
Sampling Design Example 1
0.5
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Digital Frequency in Units of Pi
Design Example 1
Impulse Response
Compute the causal frequency response:
>> M=length(x)-1;
>> H=exp(-j*f*M/2).*x;
>> hhp1=inv_dft_demo(H);
>> fvtool(hhp1,1)
Design Example 1
Frequency Response
Magnitude Response
1.4
1.2
1
Magnitude
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
Design Example 1
Compare the sampling design with an ideal window design
>> n=0:24;
>> omega=pi/2;
>> hhp2=sinc(n-12)-(omega/pi)*sinc(omega*(n-12)/pi);
>> [Hhp1,freq]=dtft_demo(hhp1,0,pi,512);
>> [Hhp2,freq]=dtft_demo(hhp2,0,pi,512);
>> plot(freq/pi,abs(Hhp1)); %This plots the magnitude of Hhp1 versus
frequency
>> hold
>> plot(freq/pi,abs(Hhp2),'--k') %This plots the magnitude of Hhp2
versus frequency
>> xlabel('Units of Pi')
>> title('Comparison of Ideal Window and Sampling Method for HP
Design')
>> legend('Sampling Method hhp1','Windowed Method hhp2')
Design Example 1
Comparison of Ideal Window and Sampling Method for HP Design
1.4
Sampling Method hhp1
Windowed Method hhp2
1.2
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Units of Pi
Sampling Design 2
Specifications:
low-pass filter of order 100,
a cut-off frequency 500 Hz
sampling frequency of 3000 Hz
Hamming window.
Sampling Design 2
MATLAB Code
>> n=0:100;
>> fs=3000;
>> fc=500;
>> omega_cutoff=2*pi*fc/fs;
>> [x,f]=selectH_lp(omega_cutoff,length(n)); % Create the response samples
>> M=length(x)-1;
>> H=exp(-j*f*M/2).*x; % Compute the causal filter frequency response
>> h=inv_dft_demo(H); % Compute the impulse response
>> h_hamming=h.*hamming(length(n))'; % Window with a Hamming window
>> subplot(2,1,1),dtft_demof(h,0,1500,512,3000); % Plot the magnitude
response
>> title('Sampling Design - Rectangular Window')
>> subplot(2,1,2),dtft_demof(h_hamming,0,1500,512,3000);
>> title('Sampling Design - Hamming Window')
Sampling Design 2
Results
Sampling Design - Rectangular Window
1.5
0.5
0
0 500 1000 1500
Hz
Sampling Design - Hamming Window
1.5
0.5
0
0 500 1000 1500
Hz
Using FIR2 for Sampling Designs
>> B=fir2(N,F,A)
N = order
F = Frequency break points, in units of
A = Amplitudes corresponding to the break points in F
0 0.3
Sampling Design with FIR2
>> N=100; % Set filter order
>> fs = 3000; % Set sampling frequency
>> fc=500; % Set cutoff frequency
>> F=[0,2*fc/fs,2*fc/fs,1]; % Vector of frequency break
points (omega values in units of pi)
>> A=[1,1,0,0]; % Amplitudes corresponding to F
>> B=fir2(N,F,A); % Compute impulse response
>> dtft_demof(B,0,1500,512,3000);
>> title('Sampling Design Example with MATLAB FIR2')
1.2
0.8
0.6
0.4
0.2
0
0 500 1000 1500
Hz
Optimal Design in MATLAB
The values for order, transition width, and ripple cannot be independently
specified. Specifying two of the parameters forces a particular value for
the third. For a specified ripple and transition width the order is optimal
in a Parks-McClellan design.
A Parks-McClellan Design for a
Low-Pass Filter
Filter specifications:
Order 20 low-pass
Critical frequency /4
Transition width 0.2
By specifying the order and the transition width, the forced
parameter is the pass-band and stop-band ripple
>> f=[0 .15 .35 1]; % This sets the band edges with normalized frequencies
% The transition is between the .15 and .35 values = 0.20
>> a=[1 1 0 0]; % This sets the desired amplitude response in the pass-band and
% stop-band by specifying amplitudes at the band edges.
>> N=20; % This sets the filter order. The filter length will be N + 1.
>> h=firpm(N,f,a);
>> fvtool(h,1)
Parks-McClellan Low Pass
Results
Magnitude Response (dB)
20
-20
Magnitude (dB)
-40
-60
-80
-100
-120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
-20
Magnitude (dB)
-40
-60
-80
-100
-120
0 0.5 1 1.5 2 2.5 3 3.5
Frequency (kHz)