You are on page 1of 12

BO CO LAB DSP2

Tn:

Cao HongQu
NguynnhDng
PhmNgcSn

Problem 7.7
ThitkblcchndidngphngphpcasHanningviccthngskthutnhsau:
wp1=0,3 ; ws1=0,4 ; ws2=0,6 ; wp2=0.7 ; As=40dB , Rp=0.5dB
Vpngxungvpngbincablc.
Bigii:
Code:
clear; close all;
%% Bai7.7 :
% wp1 = 0.3*pi;
% ws1 = 0.4*pi;
% ws2 = 0.6*pi;
% wp2 = 0.7*pi;
% Rp = 0.5; Do gondai thong
% As = 40; suyhaodaichan
% chon M=60 la tot nhat, As =40 Rp=0.18 thoayeucaubaira
wp1 = 0.3*pi;
ws1 = 0.4*pi;
ws2 = 0.6*pi;
wp2 = 0.7*pi;
Rp = 0.5;
As = 40;
%
tr_width = min((ws1-wp1),(wp2-ws2));
M = ceil(6.2*pi/tr_width)+1
n = 0:M-1;
w_han = (hanning(M))';
wc1 = (ws1+wp1)/2;
wc2 = (ws2+wp2)/2;
hd = ideal_lp(pi,M)+ideal_lp(wc1,M)-ideal_lp(wc2,M);
h = hd .* w_han;
[db,mag,pha,grd,w] = freqz_m(h,1);
delta_w = pi/500;
As = floor(-max(db((ws1/delta_w)+1:(ws2/delta_w)+1))),
Rp = -min(db(1:(wp1/delta_w)+1)),
%% Ve dap ungboloc
subplot(2,2,1); stem(n,hd); title('Dap ungxunglytuong')
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_han);title('Cua so Hanning')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Dap ungxungthucte')
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')

Ktqutc: M=63 ; As=43dB ; Rp=0.0884 dB


Thayucuthitk.
th:

Tinhnhgim M = 62; ta cktqu: As=44 dB


Thayucuthitk
th:

; Rp=0.1563 dB

Tinhnhgim M=61; ta c As=42dB ;Rp=0.1176 dB


Thayucuthitk.
th:

Gim M=60, ta cAs= 40dB,


Thayucuthitk.
th:

Rp= 0,1885dB

Gim M= 59, ta cAs=39dB, Rp= 0.1524dB


Khngthamnsuyhaogiichnbirannkhngthayucuthitk
Gim M=58, ta cAs=37dB, Rp=0.2269dB
Khngthamnsuyhaogiichnbirannkhngthayucuthitk
Nhvy: nu ta cgim M thAscnggim, nn ta chnM=60, As= 40dB, vRp= 0.1885dB lttnht.
Thamnkhngbhnsuyhaogiichnchoravbhngn dithngvibcblclbnht M=60.

Problem 7.14
Thitkblcchndi bi 7.7 dngphngphplymutns.Chnbcblcthchhpsaochoc 1 mu
dichuyntip.Sdnggitrtiuchomuny.
Bigii:
Thitksaochocmtmu dichuyntip, nn ta ciukincn:
Suyra: M 40
thamnmtmu dichuyntip, ta cccgitr M thamn: 40, 35, 34, 30, 29, 28,27,
Chn M=40, Dngblc FIR loi 2.
HmHr(w) ctnhl

[ones(1,7),T1,zeros(1,5),T1,ones(1,13),T1,zeros(1,5),T1,ones(1,6)]

Davobng C phlc, ta chngitr T1 gnnht: T1=0.39177246


Code:
% Chapter 7: Bai tap 7.14
%

Freq. Samp. Tech.: Bandstop, Optimum method T1

ws1=0.3pi, wp1=0.4pi, wp2=0.6pi, ws2=0.7pi, Rp=0.5dB, As=40dB

%%
wp1=0.3*pi;
ws1=0.4*pi;
ws2=0.6*pi;
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;

wp2=0.7*pi;

T1=0.39177246
Hrs = [ones(1,7),T1,zeros(1,5),T1,ones(1,13),T1,zeros(1,5),T1,ones(1,6)];
Hdr = [1,1,0,0,1,1]; wdl = [0,0.3,0.4,0.6,0.7,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1);
[Hr,ww,a,L] = Hr_Type2(h);
delta_w = 2*pi/1000;
As = floor(-max(db((ws1/delta_w)+1:1:ws2/delta_w))), % Suyhaodaichan
Rp = -min(db(1:1:wp1/delta_w)), % do gongiai thong
%%
subplot(1,1,1)
subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),'o',wdl,Hdr);
axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1])
set(gca,'YTickMode','manual','YTick',[0,1]); grid
subplot(2,2,2); stem(l,h); axis([-1,M,-0.2,0.7])
title('Impulse Response'); xlabel('n'); ylabel('h(n)');

subplot(2,2,3); plot(ww/pi,Hr,wl(1:20)/pi,Hrs(1:20),'o');
axis([0,1,-0.2,1.8]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1])
set(gca,'YTickMode','manual','YTick',[0,1]); grid
subplot(2,2,4);plot(w/pi,db); axis([0,1,-60,10]); grid
title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0;0.3;0.4;0.6;0.7;1]);
set(gca,'YTickMode','Manual','YTick',[-33;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['33';' 0'])
%

th:

Ktqu:ViM=40, As=34dB, Rp=0.9021dB =>Khngthamnyucuthitk.


iuchnh T1 chocithinthngsAsvRptthn, nhngkhngtng As lnna.
Hm

TinhnhgimM=35, dngblc FIR loi 1.


[ones(1,6),T1,zeros(1,5),T1,ones(1,10),T1,zeros(1,5),T1,ones(1,5)]

Davobng C phlc, chnT1=0.39161377 (gitrvi M=33, BW=6)

Ktqu: As=35dB ; Rp=0.3118dB =>Khngthayucuthitk.


iuchnh T1 cithinthngs As, Rptthn, nhngkhngtngAslnna.
th:

Hm

TinhnhgimM=34, dngblc FIR loi 2.


[ones(1,6),T1,zeros(1,4),T1,ones(1,11),T1,zeros(1,4),T1,ones(1,5)]

Davobng C phlc, chnT1=0.37897949 (gngitrvi M=32, BW=5)


Ktqu: As=34dB, Rp=0,6519dB =>Khngthayucu.
th:

iuchnhgitr T1 ta cgitrAs, vRptthn,


Chnh T1=0.3666, ta c As=36dB, Rp= 0,6573dB (ttnhtvi M=34)
th:

Hm

Tinhnhgim M=30, dngblc FIR loi 2.


[ones(1,5),T1,zeros(1,4),T1,ones(1,9),T1,zeros(1,4),T1,ones(1,4)]

Davobng C phlc, chnT1=0.37897949 (gngitrvi M=32, BW=5)


Ktqu: As=43dB, Rp=2,98dB =>Tha As=43dB
th:

iuchnhgitr T1=0.391 , ta c As=40dB, Rp= 2.9029dB =>thaiukin As


th:

Tngtnhvyviccgitr M=29, 28, 27,..tathy As gimxungvbhn 40dB,


nnkhngthamnyucubi.
Bngtmttccgitr:
M
T1
As
Rp
40
0.39177246
34
0.9021
35
0.39161377
35
0.3118
34
0.3666
36
0.6573
30
0.39
40
2.9029
29
0.37897949
34
1.7865
28
0.38925171
22
1.3471

Vy: ta chn M=30, lttnhtiviyucura.


Nhnxt:
- Phngphplymutnshiuquhn so viphngphpcasHanning, vibcblcgimi 30
nhngvnthamnyucuthitk (Hanning :M=60, As= 40dB, vRp= 0.1885dB)
- suyhaodichncngttthgndithngcngxu so viyucuvngcli, nnkhithitk, ta
chogitr M phhpviyucuttnhtcablc.

You might also like