Sie sind auf Seite 1von 7

H r w =

M -1 / 2

a n coswn
n=0

where H r w is an amplitude response function and not a magnitude response function.


function [Hr,w,a,L]=Hr_Type1(h);
% Computes Amplitude response Hr(w)of a Type-1 LP FIR filter
% ----------------------------------------------------------% [Hr,w,a,L]=Hr_Type1(h)
% Hr = Amplitude Response
% w = 500 frequencies between [0,pi] over which Hr is computed
% a = Type-1 LP filter coefficients
% L = Order of Hr
% h = Type-1 LP filter impulse response
%
M = length(h);
L= (M-1)/2;
a = [h(L+1) 2*h(L:-1:1)]; % 1x(L+1) row vector
n = [0:1:L]
% (L+1)x1 column vector
w = [0:1:500]'*pi/500;
Hr = cos(w*n)*a';

Type-2 Linear-Phase FIR Filters


Symmetrical impulse response and M even. In this case 0 , M - 1 /2 is not an
integer, and h n = h M - 1- n , 0 n M - 1 . Then we can show that

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

where H r w is an amplitude response function. Note that w = we get


H r w =

M /2

b n cos
n=1

n - 0
2

regardless of b n or h n . Hence we cannot use this type (i.e. symmetrical h n and M


even.) for highpass or bandstop filters.

Type-3 Linear-Phase FIR Filters


Antisymmetric impulse response and M odd. In this case = 2 , M - 1 /2 is an
integer, and h n = -h M - 1- n , 0 n M - 1 , and h M - 1 2 = 0 . Then we can show that
He

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 .

Furthermore, e j 2 = j , which means that jH r w is purely imaginary. Hence this type of


filter is not suitable for designing a lowpass or a highpass filter. However, this behavior is
suitable for approximating ideal Hilbert transformers and differentiators.
function [Hr,w,c,L]=Hr_Type3(h);
% Computes Amplitude response Hr(w) of a Type-3 LP FIR filter
% ----------------------------------------------------------% [Hr,w,c,L]=Hr_Type3(h)
% Hr = Amplitude Response
% w = frequencies between [0,pi] over which Hr is computed
% b = Type-3 LP filter coefficients
% L = Order of Hr
% h = Type-3 LP filter impulse response
%
M = length(h);
L = (M-1)/2;
c = [2*h(L+1:-1:1)];
n = [0:1:L];
w = [0:1:500]'*pi/500;
Hr = sin(w*n)*c';

Type-4 Linear-Phase FIR Filters


Antisymmetric impulse response and M even. This case is similar to Type-2. We have

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

Note that at w = 0 and w = we have H r 0 0 and e j 2 = j . Hence, this type is also


suitable for designing digital Hilbert transformers and differentiators.
Assignments 1 2
1. MATLAB functions for Type-1 and Type-3 is given. Write a MATLAB function to
compute the amplitude response H r w and the location of the zeros of H z for Type-2
and Type-4.
2. Let
a) h n [ 4 1 1 2 5 6 5 2 1 1 4]
b) h n [4 1 1 2 5 6

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.

w = boxcar(n) returns the n-point rectangular window in array w.


w = triang(n) returns the n-point Bartlett (Triangular) window in array w.

w = hanning(n) returns the n-point symmetric Hanning window in a column


vector in array w .
w = hamming(n) returns the n-point symmetric Hamming window in a column
vector in array w.
w = blackman(n) returns the n-point symmetric Blackman window in a column
vector in array w.
w = kaiser(n,beta) returns the beta-valued n-point Kaiser window in array w.

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

lower passband edge : w1p = 0.35

R p = 1dB

upper passband edge :

w2p = 0.65,

upper stopband edge : w2s = 0.8

R p = 1dB
As = 60dB

These quantities are shown in the following figure.


0

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)))

% Actual Passband Ripple


% Min Stopband Attenuation

% 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)')

subplot(2,2,4); plot(w/pi,db); axis([0 1 -150 10]);


title('Magnitude Response in db');grid;
xlabel('frequency in pi units');
ylabel('Decibels')
Ideal Impulse Response

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)')

subplot(2,2,2); stem(n,w_ham); title('Hamming Window')


axis([-1 M 0 1.2]); xlabel('n');
ylabel('w(n)')
subplot(2,2,3); stem(n,h); title('Actual Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n');
ylabel('h(n)')
subplot(2,2,4); plot(w/pi,Hr/pi);
xlabel('frequency in pi units');
axis([0 1 0 1]);

title('Amplitude Response');grid;
ylabel('slope in pi units');

Ideal Impulse Response

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

Das könnte Ihnen auch gefallen