Beruflich Dokumente
Kultur Dokumente
M -1 / 2
a n coswn
n=0
M /2
n=1
H e jw =
w n - e -jw M -1 /2
2
b n cos
where
M
- n
2
b n = 2h
Hence,
H r w =
M /2
n = 1,2,...,
b n cos
n=1
M
2
w n -
2
M /2
b n cos
n=1
n - 0
2
jw
M -1 / 2
n=1
-j 2 w M -1 /2
c n sinwn e
where
M -1
- n
2
c n = 2h
Hence,
H r w =
Note that at
w = 0 and w =
n = 1,2,...,
M -1
2
M -1 / 2
c n sinwn
n=1
we have H r w 0 , regardless of
c n or h n .
M /2
n=1
H e jw =
where
w M -1 /2
2
j
1
d n sin w n - e
2
M
- n
2
d n = 2h
and
H r w =
M /2
d n sin
n = 1,2,...,
n=1
M
2
w n -
2
6 5 2 1 1 4]
d) h n [ 4 1 1 2 5 6
6 5 2 1 1 4]
c) h n [4 1 1 2 5 0 5 2 1 1 4]
Determine the Type of the Linear-Phase FIR filters. Find the amplitude response H r w and
locations of the zeros of H z . Also plot the impulse response, amplitude response,
coefficients, and the zero locations.
WINDOW DESIGN TECHNIQUES
Summary of commonly used window function characteristics.
Window
Transition
Min. Stopband
Width w Exact
Name
Approximate
Attenuation
Values
4
1.8
Rectangular
21 dB
M
M
8
6.1
Bartlett
25 dB
M
M
8
6.2
Hanning
44 dB
M
M
8
6.6
Hamming
53 dB
M
M
12
11
Blackman
74 dB
M
M
MATLAB provides several routines to implement window functions discussed above table.
Using these routines, we can use MATLAB to design FIR filters based on the window
technique, which also requires an ideal lowpass impulse response hd n as shown below.
function hd=ideal_lp(wc,M);
% Ideal LowPass filter computation
% -------------------------------% [hd] = ideal_lp(wc,M);
% hd = ideal impulse response between 0 to M-1
% wc = cutoff frequency in radians
% M = length of the ideal filter
%
alpha = (M-1)/2;
n = [0:1:(M-1)];
m = n - alpha +eps;
% add smallest number to avoi divided by zero
hd = sin(wc*m)./(pi*m);
To display the frequency domain plots of digital filters, MATLAB provides the freqz routine.
Using this routing, we can developed a modified version, called freqz_m, which returns the
magnitude response in absolute as well as dB scale, the phase response, and the group delay
response as shown below.
function [db,mag,pha,grd,w] = freqz_m(b,a)
% Modified version of freqz subroutine
% -----------------------------------% [db,mag,pha,grd,w] = freqz_m(b,a)
% db = relative magnitude in dB computed over 0 to pi radians
% mag = absolute magnitude computed over 0 to pi radians
% pha = Phase response in radians over 0 to pi radians
% grd = Group delay over 0 to pi radians
%
w = 501 frequency samples between 0 to pi radians
%
b = numerator polynomial of H(z)
(for FIR: b=h)
%
a = denominator polynomial of H(z)
(for FIR: a=[1])
%
[H,w] = freqz(b,a,1000,'whole') ;
H = (H(1:1:501))';
w = (w(1:1:501))';
mag = abs(H);
db = 20*log10((mag+eps)/max(mag));
pha = angle(H);
grd = grpdelay(b,a,w);
Assignment 3
3. Design a digital FIR lowpass filter with the following specifications:
wp = 0.2 R p = 0.25dB
ws = 0.3
As = 50dB
Choose an appropriate window function from above Table. Determine the impulse response
and provide a plot of the frequency response of the designed filter.
Example 1: Let us design the following digital bandpass filter.
lower stopband edge :
w1s = 0.2,
As = 60dB
R p = 1dB
w2p = 0.65,
R p = 1dB
As = 60dB
0.35
0.35
0.65
0.8
1
w/pi
Decibels
60
% Solution of Example 1
ws1 = 0.2*pi;
wp1 = 0.35*pi;
wp2 = 0.65*pi; ws2 = 0.8*pi;
As = 60;
tr_width = min((wp1-ws1),(ws2-wp2));
M = ceil(11*pi/tr_width) +1;
n = [0:1:M-1];
wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
w_bla = (blackman(M))';
h = hd.*w_bla;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w =2*pi/1000;
Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w))
As = -round(max(db(ws2/delta_w+1:1:501)))
% Plots
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([0 M-1 -0.4 0.5]); xlabel('n');
ylabel('hd(n)')
subplot(2,2,2); stem(n,w_bla); title('Blackman Window')
axis([0 M-1 0 1.1]); xlabel('n');
ylabel('w(n)')
subplot(2,2,3); stem(n,h); title('Actual Impulse Response')
axis([0 M-1 -0.4 0.5]); xlabel('n');
ylabel('h(n)')
Blackman Window
1
0.4
0.8
w(n)
hd(n)
0.2
0
-0.2
-0.4
20
40
60
n
Actual Impulse Response
20
40
60
n
Magnitude Response in db
0.5
frequency in pi units
0
Decibels
0.2
h(n)
0.4
0.2
0.4
0
-0.2
-0.4
0.6
20
40
n
-50
-100
-150
60
Assignment 4
1. The frequency response of an ideal bandstop filter is given by
1,
0 wp3
H e = 0, 3 w 2 3
1, 2 3 p w
using a Kaiser window, design a bandstop filter of length 45 with stopband attenuation of 60
dB.
Example 2: The frequency response of an ideal digital differentiator is given by
jw, 0 p w
-jw, - p w p 0
H d e jw =
using a Hamming window of length 21, design a digital FIR differentiator. Plot the time- and
the frequency-domain responses.
Soln: Note that M is an even number, then M - 1 /2 is an integer and hd n will be
zero for all n. hence M must be an odd number, and this will be a Type-3 linear phase FIR
filter.
% Solution of Example 2
M = 21; alpha = (M-1)/2;
n = 0:1:M-1;
hd = (cos(pi*(n-alpha)))./(n-alpha);
w_ham = (hamming(M))';
h = hd.*w_ham;
[Hr,w,P,L]=Hr_Type3(h);
hd(alpha+1) = 0;
Plots
subplots(1,1,1);
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n');
ylabel('hd(n)')
title('Amplitude Response');grid;
ylabel('slope in pi units');
Hamming Window
1
0.8
w(n)
hd(n)
0.5
0
0.4
-0.5
0.2
-1
0
10
15
20
n
Actual Impulse Response
slope in pi units
0.5
0
-0.5
-1
0
10
n
15
20
h(n)
0.6
10
15
n
Amplitude Response
20
0.8
0.6
0.4
0.2
0
0.5
frequency in pi units