Ce105 - Digital Signal Processing ASSIGNMENT 5: FIR Filter Design

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1

CE105 DIGITAL SIGNAL PROCESSING


ASSIGNMENT 5: FIR Filter Design

Guide: Students are expected to submit MATLAB code and report the results in form of
either MS Word or PDF format. All is zipped in a single file as [StudentID].zip.
Send email to instructors with title [CE105.E12-AS1] [StudentID].
For example, the student with ID 12345 should send the file named 12345.zip and the
email title should be [CE105.E12-AS1] 12345
1.1 Solution:
Transition band:
2 / 2 .1850/ 8000 0.4625
p p s
F F e t t t = = =

2 / 2 .2150/ 8000 0.5375
s stop s
F F e t t t = = =
| | 0.075
p s
e e e t A = =
Base on Table in Slide 32 Lecture 7, selecting the rectangular window will result in a
passband ripple of 0.75dB and a stopband attenuation 21dB. Thus, this window selection
would satisfy the design requirement for the passband ripple of 1dB and stopband
attenuation of 20dB.
Next, we determine the length of the filter as
1.8
24 L
L
t
e A = =
The cutoff frequency is determined by:
0.5
2
p s
c
e e
e t
+
= =
1.2 Solution:
Based on the specifications, the Hann window will do the job, since it has a passband
ripple of 0.055dB and a stopband attenuation of 44dB. Then
2

( )
2
| | 2500 1500 0.25
8000
p s
t
e e e t A = = =
6.2
25 L
t
e
= =
A

Hence, we choose 25 filter coefficients using the Hann window method. The cutoff
frequency is 0.5t .
Matlab Program:
function B=firwd(N, Ftype, WnL, WnH, Wtype)
%B=firwd(N,Ftype,WnL,WnH,Wtype)
% FIR filter design using the window function method.
% Input parameters:
% N: the number of the FIR filter taps.
% Note: It must be an odd number.
% Ftype: the filter type
%1. Lowpass filter;
%2. Highpass filter;
%3. Bandpass filter;
%4. Band reject filter;
% WnL: lower cutoff frequency in radians. Set WnL=0 for the
highpass filter.
% WnH: upper cutoff frequency in radians. Set WnH=0 for the
lowpass filter.
% Wtypw: window function type
%1. Rectangular window;
%2. Triangular window;
%3. Hanning window;
%4. Hamming window;
%5. Blackman window;
% Output:
% B: FIR filter coefficients.

M=(N-1)/2;
hH = sin(WnH*[-M:1:-1])./([-M:1:-1]*pi);
hH(M+1)=WnH/pi;
hH(M+2:1:N)=hH(M:-1:1);
hL=sin (WnL*[-M:1:-1])./([-M:1:-1]*pi);
hL(M+1)=WnL/pi;
hL(M+2:1:N)=hL(M:-1:1);
if Ftype==1
h(1:N)=hL(1:N);
end
if Ftype==2
h(1:N)=-hH(1:N);
h(M+1)=1+h(M+1);
3

end
if Ftype==3
h(1:N)=hH(1:N)-hL(1:N);
end

if Ftype==4
h(1:N)=hL(1:N)-hH(1:N);
h(M+1)=1+h(M+1);
end

% window functions;
if Wtype==1
w(1:N)=ones(1,N);
end

if Wtype==2
w=1-abs([-M:1:M])/M;
end

if Wtype==3
w = 0.5 + 0.5*cos([-M:1:M]*pi/M);
end

if Wtype==4
w = 0.54 + 0.46*cos([-M:1:M]*pi/M);
end

if Wtype==5
w = 0.42 + 0.5*cos([-M:1:M]*pi/M) + 0.08*cos(2*[-
M:1:M]*pi/M);
end
B = h.*w

Program P1.2
% MATLAB program to create Figure in P1.2
%
N=25; Ftype=2; WnL=0; WnH=0.5*pi; Wtype=3;fs=8000;
Bhan=firwd(N,Ftype,WnL,WnH,Wtype);
freqz(Bhan,1,512,fs);
axis([0 fs/2 -120 10]);

4


1.3 Solution:
( )
1 1 1
2
| | 1600 500 0.275
8000
p s
t
e e e t A = = =
( )
2 2 2
2
| | 3500 2300 0.3
8000
p s
t
e e e t A = = =
Based on the specifications, the Hamming window will do the job.
1
2
24
6.6
22
L
L L
t
e
=
A =


Choosing 25 L = filter coefficients using the Hamming window method:
( )
1 1
1
1600 500
2
. 0.2625
2 8000 2
p s
c
e e
t
e t
+ +
= = =
( )
2 2
2
3500 2300
2
. 0.725
2 8000 2
p s
c
e e
t
e t
+ +
= = =
0 500 1000 1500 2000 2500 3000 3500 4000
-1500
-1000
-500
0
500
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 500 1000 1500 2000 2500 3000 3500 4000
-100
-50
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
5


Program
% MATLAB program to create Figure in P1.3
%
N=25;Ftype=3;WnL=0.2625*pi;WnH=0.725*pi;Wtype=4;fs=8000;
Bham=firwd(N,Ftype,WnL,WnH,Wtype);
freqz(Bham,1,512,fs);
axis([0 fs/2 -130 10]);

1.4 Solution:
The normalized transition widths:
1
1500
2 0.375
8000
e t t A = = , and
2
1300
2 0.325
8000
e t t A = =
The filter lengths are determined using the Blackman window as:
1
2
29.33
11
33.8
L
L L
t
e
=
A =


0 500 1000 1500 2000 2500 3000 3500 4000
-2000
-1000
0
1000
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 500 1000 1500 2000 2500 3000 3500 4000
-100
-50
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
6

We choose an odd number 35 L = . The normalized lower and upper cutoff frequencies are
calculated as:
2 .1250
0.3125
8000
cL
t
e t = =
2 .2850
0.7125
8000
cH
t
e t = =



Program P1.4
% MATLAB program to create Figure in P1.4
%
N=35;Ftype=4;WnL=0.3125*pi;WnH=0.7125*pi;Wtype=5;fs=8000;
Bblack=firwd(N,Ftype,WnL,WnH,Wtype);
freqz(Bblack,1,512,fs);
axis([0 fs/2 -120 10]);


0 500 1000 1500 2000 2500 3000 3500 4000
-3000
-2000
-1000
0
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 500 1000 1500 2000 2500 3000 3500 4000
-100
-50
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
7

Example:
a) Design a 3-tap (L=3) FIR lowpass with cutoff frequency of 800Hz and
sampling rate of 8000Hz using Hamming window function.
b) Determine the transfer function and difference equation of the designed FIR
system.
c) Compute and plot the magnitude frequency response for 0, / 4, / 2, 3 / 4 e t t t =
and t radians.

You might also like