Experiment Lab Report 6

You might also like

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

United International University

Dept. of Electrical & Electronic Engineering (EEE)

Fall 2022
DIGITAL SIGNAL PROCESSING
LABORATORY EEE 3310
Lab Report – 6

Submitted to:
Dr. Khawza Iftekhar Uddin Ahmed

Submitted by:
GROUP 1

Name ID

Joyanta Debnath 021 182 032

Ranjan Kumer Sarker 021 191 027

Shakib Hasan 021 201 054

Mushfiqul Hoque 021 201 103

Date of Performance: 17th December 2022


Date of Submission: 31th December 2022
Lab Report - 6
Filter Design using MATLAB

Introduction: From this experiment we learned how to use digital filter using MATLAB and
we also saw different types of linear phase FIR filter. Furthermore, we also saw how to
implement these using MATLAB as well as we saw magnitude and phase response.

In Lab Evaluation:

Code:
%beta = 0.1102*(As - 8.7)
M = 45; As = 60; n=[0:1:M-1];
beta = 0.1102*(As - 8.7)
w_kai = (kaiser(M,beta))';
wc1 = pi/3; wc2 = 2*pi/3;
hd = ideal_lp(wc1,M) + ideal_lp(pi,M) - ideal_lp(wc2,M);
h = hd.* w_kai;
[db,mag,pha,grd,w] = freqz_m(h,(1));
subplot(2,2,1);
stem(n,hd); title('Ideal Impulse Response')
axis([-1 M -0.2 0.8]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2);
stem(n,w_kai);title('Kaiser Window')
axis([-1 M 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3);
stem(n,h);title('Actual Impulse Response')
axis([-1 M -0.2 0.8]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4);
plot(w/pi,db); axis([0 1 -80 10]);title('Magnitude
Response in dB');grid;
xlabel('frequency in pi units'); ylabel('Decibels')

Page 2 of 8
Homework:

Code:

M = 21; alpha = (M-1)/2; n = 0:M-1;


hd = (cos(pi*(n-alpha)))./(n-alpha); hd(alpha+1)=0;
w_ham = (hamming(M))';
h = hd .* w_ham; [Hr,w,P,L] =Hr_Type3(h);
subplot(2,2,1); stem(n,hd); title('Ideal
ImpulseResponse');
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
ImpulseResponse');
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)');

Page 3 of 8
subplot(2,2,4);plot(w/pi,Hr/pi); title('Amplitude
Response');grid;
xlabel('frequency in pi units'); ylabel('slope in
piunits'); axis([0 1 0 1]);

Code:
n=[0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
w_han = (hann(M))';
h = hd .* w_han;
[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)));

Page 4 of 8
subplot(2,2,1); stem(n,hd); title('Ideal
ImpulseResponse');
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('hd(n)');
subplot(2,2,2); stem(n,w_han);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);
title('Magnitude Response in dB');grid;
xlabel('frequency in pi units'); ylabel('Decibels');
axis([0 1 -150 10]);

Code:

Page 5 of 8
ws = 0.4*pi;wp = 0.6*pi;Rp = 0.004;As = 50;
tr_width = abs(wp-ws);
M = ceil(11*pi/tr_width); M = 2*floor(M/2)+1;
n = 0:M-1; w_blk = (blackman(M))';
wc = (ws+wp)/2;
hd = ideal_lp(pi,M)-ideal_lp(wc,M); h = hd .* w_blk;
[db,mag,pha,grd,w] = freqz_m(h,1); delta_w = pi/500;
Rpd = -min(db(ceil(wp/delta_w)+1:floor(pi/delta_w)+1));
Asd = floor(-max(db(1:(ws/delta_w)+1)));
Hf_1
=figure('Units','inches','position',[1,1,5,3],'color',[0,
0,0],'paperunits','inches','paperposition',[0,0,5,3]);
set(Hf_1,'NumberTitle','off','Name','P7.12');
plot(w(301:501)/pi,db(301:501),'linewidth',1);
title('Zoomed Magnitude Response in dB');
axis([0.6,1,-0.005,0.001]); xlabel('\omega/\pi');
ylabel('Decibels');
set(gca,'XTick',[0.6;1]);
set(gca,'XTickLabel',['0.6';' 1 '],'fontsize',8);
set(gca,'YTick',[-0.004;0]); set(gca,'YTickLabel',['-
0.004';' 0 ']);grid;

Page 6 of 8
CODE:

wp1 = 0.25*pi;ws1 = 0.35*pi;ws2 = 0.65*pi;wp2


=0.75*pi;delta1 = .025;
delta2 = 0.005;
tr_width = abs(min((wp1-ws1),(ws2-wp2)));
M = ceil((As*7.95)/(2.285*tr_width)+1)+1;
M = 2*floor(M/2)+1;
n = [0:1:M-1]; beta = 0.1102*(As-8.7); w_kai
=(kaiser(M,beta))';
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
hd = ideal_lp(pi,M)+ideal_lp(wc1,M)-ideal_lp(wc2,M);
h = hd .* w_kai;
[db,mag,pha,grd,w] = freqz_m(h,1); delta_w = pi/500;
Asd = floor(-
max(db(ceil(ws1/delta_w)+1:floor(ws2/delta_w)+1)));
Rpd = -min(db(1:floor(wp1/delta_w)+1));
figure
subplot(221);
Hs_1= stem(n,hd,'filled'); title('Ideal Impulse
Response');
subplot(222);
Hs_2 = stem(n,w_kai,'filled'); title('Kaiser Window');
subplot(223);
Hs_3 = stem(n,h,'filled'); title('Actual Impulse
Response');
subplot(224);
plot(w/pi,db,'linewidth',1); title('Magnitude Response in
dB');
figure
plot(w/pi,mag,'linewidth',1); title('Amplitude
Response');

Page 7 of 8
Statement: I Have contributed and given my full support in completing this report.

Page 8 of 8

You might also like