You are on page 1of 28

BI 1.

M phng h thng v tn hiu ri rc bng MATLAB

A. Tn hiu v h thng ri rc min n


1.1. Vit chng trnh con to mt dy thc ngu nhin xut pht t n1 n n2 v c gi
tr ca bin theo phn b Gauss vi trung bnh bng 0, phng sai bng 1. Yu cu
chng trnh con c cc tham s u vo v u ra c nhp theo cu lnh vi c php:
[x,n] = randnseq(n1,n2);
function [x,n] = randnseq(n1,n2)
n=n1:n2;
x=randn([1,length(n)]);

1.2. Vit chng trnh to hm nng lng ca mt dy. Yu cu chng trnh con c

cc tham s u vo v u ra c nhp theo cu lnh vi c php:


Ex = energy(x,n);
function Ex = energy(x,n)
s=0;
for i = 1:n
s = s + x(i)^2;
end
Ex=s;

1.3. Cho dy x(n) = {1,2,3,4,5,6,7,6,5,4,3,2,1} . Vit chng trnh con th trn th cc


dy:
a. x1(n) = 2x(n-5) 3x(n+4)
b. x2(n) = x(3-n) x(n)x(n-2)
n=-2:10;
x=[1 2 3 4 5 6 7 6 5 4 3 2 1];
%x1(n) = x(n-5)
%x2(n) = x(n+4)
%x3(n) = x(3-n)
%x4(n) = x(n-2)
%x5(n) = x(n)*x(n-2)
%X1 = 2*x1(n) + 3*x2(n)
%X2 = x(3-n) + x(n)*x(n-2)
%------------------------------[x1 s1] = sigshift(x,n,5);
[x2 s2] = sigshift(x,n,-4);
[X1 N1] = sigadd(2*x1,s1,-3*x2,s2);
%-------------------------------[x3 s3] = sigfold(x,n);
1|Page

[x3 s3] = sigshift(x3,s3,-3);


[x4 s4] = sigshift(x,n,2);
[x5 s5] = sigmult(x,n,x4,s4);
[X2 N2] = sigadd(x3,s3,x5,s5);
%-------X1(n) Fig----------------subplot(211)
stem(N1,X1)
xlabel('n')
ylabel('x1(n)')
%-------X2(n) Fig-----------------subplot(212)
stem(N2,X2)
xlabel('n')
ylabel('x2(n)')

1.4. Cho h thng c m t bi phng trnh sai phn tuyn tnh h s hng nh
sau:
y(n) y(n - 1) + 0.9y(n-2) = x(n)
S dng hm filter ca MATLAB, vit chng trnh thc hin cc cng vic sau:
a. Biu din bng th hm p ng xung n v ca h thng vi -20 n 100
b. Biu din bng th dy p ng ca h thng vi -20 n 100 khi dy u vo
2|Page

l dy nhy n v.
%y(n) - y(n-1) + 0,9*y(n-2) = x(n)
%delta: Day xung don vi
%step: Day nhay don vi
%H - dap ung xung cua he thong
%Y - dap ung ra cua he thong khi dap ung vao la ham nhay don vi
A=[1 -1 0.9];
B=[1];
n1=-20;
n2=100;
n=n1:n2;
delta = impseq(0,-20,100);
step = stepseq(0,-20,100);
H = filter(B,A,delta);
Y = filter(B,A,step);
subplot(211)
stem(n,H)
subplot(212)
stem(n,Y)

3|Page

B. Tn hiu v h thng ri rc min Z, min tn s lin tc , v min tn s ri


rc k
1.5. Cho dy x(n) = 0.5nu(n)
a. Da trn nh ngha ca bin i Z, tm bin i Z ca dy trn
b. Kim chng li kt qu cu a bng hm ztrans
c. T kt qu trn, tm bin i Fourier ca x(n)
Dng MATLAB th hin trn th ph X(ej) ti 501 im ri rc trong khong [0,]
w = [0:1:500]*pi/500;
X = exp(j*w) ./ (exp(j*w)- 0.5*ones(1,501));
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
%
subplot(2,2,1);
plot(w/pi,magX); grid;
title('Magnitude Part'); xlabel('frequency in pi units');
ylabel('Magnitude');
subplot(2,2,3); plot(w/pi,angX); grid;
title('Angle Part'); xlabel('frequency in pi units');
ylabel('Radians');
subplot(2,2,2); plot(w/pi,realX); grid;
title('Real Part'); xlabel('frequency in pi units');
ylabel('Real');
subplot(2,2,4); plot(w/pi,imagX); grid;
title('Imaginary Part'); xlabel('frequency in pi units');
ylabel('Imaginary');

4|Page

1.6. Cho dy x(n) c dng nh sau:


x(n) = {0,0,1,2,3,4,5,0,0,}
y l mt dy s xc nh trong mt khong hu hn t -1 n 3. Da trn cng thc
nh ngha ca bin i Fourier, vit chng trnh tnh v th hin ph ca dy x(n) ti
501 im ri rc trong khong [0,] Cho dy x(n) = rect7(n)
n1 = -2;
n2 = 8;
[x n] = rectseq(7,n1,n2);
k = 0:500; w = (pi/500)*k;
X = x*(exp(-j*pi/500)).^(n'*k);
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
%
subplot(2,2,1); plot(k/500,magX); grid;
title('Magnitude Part'); xlabel('frequency in pi units');
ylabel('Magnitude');
subplot(2,2,3); plot(k/500,angX); grid;
title('Angle Part'); xlabel('frequency in pi units');
ylabel('Radians');
subplot(2,2,2); plot(k/500,realX); grid;
5|Page

title('Real Part'); xlabel('frequency in pi units');


ylabel('Real');
subplot(2,2,4); plot(k/500,imagX); grid;
title('Imaginary Part'); xlabel('frequency in pi units');
ylabel('Imaginary');

1.7. Mt hm min Z c cho vi cng thc sau y:


( )
Hm s X(z) c th vit di dng t s ca hai a thc theo z-1 nh sau:
( )

a. S dng lnh residuez ca MATLAB, tnh cc im cc, thng d ti cc im cc.


b. T kt qu cu trn, vit cng thc khai trin X(z) thnh tng cc phn thc n gin,
t tm bin i Z ngc ca X(z), cho bit x(n) l mt dy nhn qu.
6|Page

c. Kim chng li kt qu cu b bng hm iztrans


% Find the residues, poles and direct terms
b = [0 1]; a = [3 -4 1];
[R,p,K] = residuez(b,a)
% Test
syms z;
f=z/(3*z^2 - 4*z +1)
iztrans(f)

1.8. Cho hm X(z) vi cng thc nh sau:


( )

) (

a. Vit chng trnh tnh cc im cc, thng d ca cc im cc ca hm X(z) trn


(gi : c th dng hm poly ca MATLAB khi phc li a thc mu s t mt
mng cc nghim ca a thc - mng cc im cc ca X(z))
b. T kt qu cu trn, vit cng thc khai trin X(z) thnh tng cc phn thc n gin,
t tm bin i Z ngc ca X(z) trn min z > 0.9 .
syms z;
X = 1/((1-0.9*z^-1)^2*(1-0.9*z^-1))
a=poly([0.9 0.9 0.9])
b=1
[r p k] = residuez(b,a);
%---------iztrans(X)

1.9. Cho h thng nhn qu biu din bi phng trnh sau:


y(n) 0,9y(n-1) = x(n)
a. Tm hm truyn t ca h thng.
Sau thc hin cc cng vic sau:
b. Dng lnh zplane ca MATLAB biu din trn th mt phng Z s phn b cc
im cc v im khng.
c. Tnh v biu din trn th hm p ng tn s H(ei) ca h thng (bao gm p
ng bin - tn s v p ng pha - tn s) ti 200 im ri rc trn ng trn n v.
b = [1 0]; a = [1 -0.9];
% Tim phan bo diem cuc va diem khong
subplot(1,2,1);
7|Page

zplane(b,a);
title('Z plane');
% Tim dap ung tan so bang cach danh gia 200 diem roi rac
% cua H(z) tren duong tron don vi
[H, w] = freqz(b,a,200,'whole');
magH = abs(H(1:101)); phaH= angle(H(1:101));
% Ve dap ung tan so
subplot(2,2,2); plot(w(1:101)/pi,magH); grid;
title('Magnitude Response');
xlabel('frequency in pi units');
ylabel('Magnitude');
subplot(2,2,4); plot(w(1:101)/pi,phaH/pi); grid;
title('Phase Response');
xlabel('frequency in pi units');
ylabel('Phase in pi units');

1.10. To cc hm thc hin vic bin i Fourier ri rc thun (t tn l hm dft) v


Fourier ri rc ngc (t tn l hm idft). Da trn cc hm dft c xy dng trn,
tm bin i Fourier ri rc ca dy c chiu di N=20:

8|Page

( )
L = 5; N = 20;
n = [0:N-1];
xn = [ones(1,L), zeros(1,N-L)];
k = n;
Xk = dft(xn,N);
magXk = abs(Xk);
%
subplot(2,1,1); stem(n,xn);
axis([min(n),max(n)+1,-0.5,1.5]);
title('Sequence x(n)');
xlabel('n'); ylabel('x(n)');
subplot(2,1,2); stem(k,magXk);
axis([min(k),max(k)+1,-0.5,5.5]);
title('DFT of SQ. wave');
xlabel('k'); ylabel('X(k)');

9|Page

BI 2: Thit k b lc s bng MATLAB


A. Thit k b lc c p ng xung chiu di hu hn (b lc s FIR).
2.1. To cc hm th hin ln ca p ng tn s cc b lc FIR loi 1 t dy p
ng xung ca chng v ghi li theo tn tp l Hr_Type1.m:
function [Hr,w,a,L] = Hr_Type1(h)
% Tinh ham do lon cua dap ung tan so Hr(w)
% bo loc FIR loai 1
% --------------------------------------------------% [Hr,w,a,L] = Hr_Type1(h)
% Hr = Do lon
% w = Vector tan so trong khoang [0 pi]
% a = Cac he so cua bo loc FIR loai 1
% L = Bac cua bo loc
% h = Dap ung xung cua bo loc FIR loai 1
%
M = length(h);
L = (M-1)/2;
a = [h(L+1) 2*h(L:-1:1)];
n = [0:1:L];
w = [0:1:500]'*pi/500;
Hr = cos(w*n)*a';

2.2. Vit chng trnh tnh hm ln ca p ng tn s b lc FIR loi 2, FIR loi 3 v


b lc FIR loi 4 vi cc tham s u vo v u ra c nhp theo cc cu lnh:
>> [Hr,w,c,L] = Hr_Type2(h) -> cho b lc FIR loi 2
function [Hr,w,b,L] = Hr_Type2(h)
% Tinh toan do lon cua dap ung tan so Hr(w)
%bo loc FIR loai 2
% ----------------------------------------------------------% [Hr,w,b,L] = Hr_Type2(h)
% Hr = Do lon
% w = vector tan so trong khoang [0:pi]
% b = He so cua bo loc FIR loai 2
% L = Bac cua bo loc FIR loai 2
% h = Dap ung xung cua bo loc FIR loai 2
%
M = length(h);
L = M/2;
b = 2*h(L:-1:1);
n = [1:1:L]; n = n-0.5;
w = [0:1:500]'*pi/500;
Hr = cos(w*n)*b';

>> [Hr,w,c,L] = Hr_Type3(h) -> cho b lc FIR loi 3


function [Hr,w,c,L] = Hr_Type3(h)
10 | P a g e

% Tinh toan do lon cua dap ung tan so Hr(w)


%bo loc FIR loai 3
% ----------------------------------------------------------% [Hr,w,b,L] = Hr_Type3(h)
% Hr = Do lon
% w = vector tan so trong khoang [0:pi]
% c = He so cua bo loc FIR loai 3
% L = Bac cua bo loc FIR loai 3
% h = Dap ung xung cua bo loc FIR loai 3
% ----------------------------------------------------------M = length(h);
L = (M-1)/2;
c = 2*h(L:-1:1);
n = [1:1:L];
w = [0:1:500]'*pi/500;
Hr = sin(w*n)*c';

>> [Hr,w,d,L] = Hr_Type4(h) -> cho b lc FIR loi 4


function [Hr,w,d,L] = Hr_Type4(h)
% Tinh toan do lon cua dap ung tan so Hr(w)
%bo loc FIR loai 4
% ----------------------------------------------------------% [Hr,w,b,L] = Hr_Type4(h)
% Hr = Do lon
% w = vector tan so trong khoang [0:pi]
% d = He so cua bo loc FIR loai 4
% L = Bac cua bo loc FIR loai 4
% h = Dap ung xung cua bo loc FIR loai 4
% ----------------------------------------------------------M = length(h);
L = M/2;
d = 2*h(L:-1:1);
n = [1:1:L];
n = n-1/2;
w = [0:1:500]'*pi/500;
Hr = sin(w*n)*d';

2.3. Cho b lc FIR vi p ng xung nh sau:


h(n) = {-4,1,-1,-2,5,6,5,-1,-2,1,-4}
a. Xc nh loi ca b lc.
Tnh v biu din trn th:
b. Dy p ng xung ca b lc
c. Cc h s ca b lc
11 | P a g e

d. Hm ln ca p ng tn s
e. Phn b im cc v im khng
h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4];
M = length(h); n =0:M-1;
[Hr,w,a,L] = Hr_Type1(h);
a, L
amax = max(a)+1; amin = min(a)-1;
%
subplot(2,2,1); stem(n,h);
axis([-1,2*L+1,amin,amax]);
title('Impulse Response');
xlabel('n'); ylabel('h(n)');
%
subplot(2,2,3); stem(0:L,a);
axis([-1,2*L+1,amin,amax]);
title('a(n) coefficients');
xlabel('n'); ylabel('a(n)');
%
subplot(2,2,2); plot(w/pi,Hr); grid;
title('Type-1 Amplitude Response');
xlabel('frequency in pi units'); ylabel('Hr');
subplot(2,2,4); zplane(h,1);

12 | P a g e

2.4. Cho b lc FIR vi p ng xung nh sau:


h(n) = {-4,1,-1,-2,5,6,-6,-5,1,2,-1,4}
a. Xc nh loi ca b lc.
Vit chng trnh tnh v biu din trn th:
b. Dy p ng xung ca b lc
c. Cc h s ca b lc
d. Hm ln ca p ng tn s
e. Phn b im cc v im khng
h = [-4,1,-1,-2,5,6,-6,-5,1,2,-1,4];
M = length(h); n =0:M-1;
[Hr,w,d,L] = Hr_Type4(h);
d, L
dmax = max(d)+1; dmin = min(d)-1;
%
subplot(2,2,1); stem(n,h);
axis([-1,2*L+1,dmin,dmax]);
title('Impulse Response');
xlabel('n'); ylabel('h(n)');
%
subplot(2,2,3); stem(1:L,d);
axis([-1,2*L+1,dmin,dmax]);
title('d(n) coefficients');
xlabel('n'); ylabel('d(n)');
%
subplot(2,2,2); plot(w/pi,Hr); grid;
title('Type-4 Amplitude Response');
xlabel('frequency in pi units'); ylabel('Hr');
%
subplot(2,2,4); zplane(h,1);

13 | P a g e

2.5. Thit k b lc thng thp theo phng php ca s vi cc tham s u vo nh


sau:
s = 0.2

Rp = 0.25 dB

p = 0.3

As = 50 dB

Tnh v biu din trn th:


a. Dy p ng xung ca b lc l tng
b. Dy hm ca s Hamming
c. Hm ln tuyt i ca p ng tn s
d. Hm ln tng i tnh theo dB ca p ng tn s
14 | P a g e

wp = 0.2*pi; ws =0.3*pi;
tr_width = ws - wp;
M = ceil(6.6*pi/tr_width) + 1
n = [0:1:M-1];
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_ham = (hamming(M))';
h = hd .* w_ham;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1)))
As = -round(max(db(ws/delta_w+1:1:501)))
%plot
subplot(2,2,1); stem(n,hd);
axis([0,M-1,-0.1,0.3]);
title('Ideal Impulse Response');
xlabel('n'); ylabel('hd(n)');
%
subplot(2,2,2); stem(n,w_ham);
axis([0,M-1,0,1.1]);
title('Hamming Window');
xlabel('n'); ylabel('w(n)');
%
subplot(2,2,3); stem(n,h);
axis([0,M-1,-0.1,0.3]);
title('Actual Impulse Response');
xlabel('n'); ylabel('h(n)');
46%
subplot(2,2,4); plot(w/pi,db); grid;
axis([0,1,-100,10]);
title('Magnitude Response in dB');
xlabel('frequency in pi units'); ylabel('Decibels');

15 | P a g e

2.6. Thit k b lc thng thp theo phng php ly mu tn s vi cc tham s u


vo nh sau:
s = 0.2

Rp = 0.25 dB

p = 0.3

As = 50 dB

Gi s rng ta chn p ng xung c chiu di 60 tng ng vi ly 60 mu tn s


trong khong [0,2). Di thng c rng l 0,2 tng ng vi 7 mu nhn gi tr 1.
Gi s tip rng qu trnh ti u ho ch ra nn chn di chuyn tip 2 mu nhn cc gi
tr T1 = 0,5925 v T2 = 0,1099. Vy dy mu cc tn s c cho nh sau:
H(k) = {1,1,1,1,1,1,1,T1,T2,0,0,T2,T1,1,1,1,1,1,1}
Tnh v biu din trn th:
a. Dy cc mu tn s
b. Dy p ng xung ca b lc thc t
c. Hm ln tuyt i ca p ng tn s
16 | P a g e

d. Hm ln tng i tnh theo dB ca p ng tn s


M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1,7),0.5925,0.1099,zeros(1,43),0.1099,0.5925,ones(1,6)];
% Day dap ung tan so mau ly tuong
Hdr = [1,1,0,0]; wdl = [0,0.2,0.3,1];
% Dap ung tan so ly tuong de bieu dien do thi
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);
%plot
subplot(2,2,1); plot(wl(1:31)/pi,Hrs(1:31),'o',wdl,Hdr);
axis([0,1,-0.1,1.1]);
title('Frequency Samples: M=40, T2 = 0.5925, T1 = 0.1099');
xlabel('frequency in pi units'); ylabel('Hr(k)');
%
subplot(2,2,2); stem(l,h);
axis([-1,M,-0.1,0.3]);
title('Impulse Response');
xlabel('n'); ylabel('h(n)');
%
subplot(2,2,3); plot(ww/pi,Hr,wl(1:31)/pi,Hrs(1:31),'o');
axis([0,1,-0.2,1.2]);
title('Amplitude Response');
xlabel('frequency in pi units'); ylabel('Hr(w)');
%
subplot(2,2,4); plot(w/pi,db);
axis([0,1,-100,10]); grid
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Decibels');

17 | P a g e

2.7. Thit k b lc thng thp theo phng php lp (thut ton ca Parks v
McClellan) vi cc tham s u vo nh sau:
s = 0.2

Rp = 0.25 dB

p = 0.3

As = 50 dB

Lp cng vic tm b lc ti u theo ngha Chebyshev (dng lnh firpm) v tng M sau
mi ln lp tm ra b lc tho mn yu cu thit k, sau tnh v biu din trn
th:
a. Dy p ng xung ca b lc thc t
b. Hm ln tuyt i ca p ng tn s
c. Hm ln tng i tnh theo dB ca p ng tn s
18 | P a g e

d. Hm sai s E()
wp = 0.2*pi; ws =0.3*pi; Rp = 0.25; As = 50;
delta_w = 2*pi/1000;
wsi = ws/delta_w+1;
delta1 = (10^(Rp/20)-1)/(10^(Rp/20)+1);
delta2 = (1+delta1)*(10^(-As/20));
deltaH = max(delta1,delta2);
deltaL = min(delta1,delta2);
weights = [delta2/delta1 1];
deltaf = (ws-wp)/(2*pi);
M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1)
f = [0 wp/pi ws/pi 1];
m = [1 1 0 0];
h = firpm(M-1,f,m,weights);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
Asd = -max(db(wsi:1:501))
while Asd<As
M = M+1
[h,ERR,RES] = firpm(M-1,f,m,weights);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
Asd = -max(db(wsi:1:501))
end
%plot
n = [0:1:M-1];
subplot(2,2,1); stem(n,h);
axis([0,M-1,-0.1,0.3]);
title('Impulse Response');
xlabel('n'); ylabel('h(n)');
%
subplot(2,2,2); plot(w/pi,db); grid;
axis([0,1,-80,10]);
title('Magnitude Response in dB');
xlabel('frequency in pi units'); ylabel('Decibels');
%
subplot(2,2,3); plot(w/pi,mag); grid;
axis([0,1,-0.2,1.2]);
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Hr(w)');
%
subplot(2,2,4); plot(RES.fgrid,RES.error); grid;
axis([0,1,-0.0150,0.0150]);
title('Error Response');
xlabel('frequency in pi units'); ylabel('Er(w)');

19 | P a g e

B. Thit k b lc c p ng xung chiu di v hn (b lc s IIR).


2.8. Thit k b lc thng thp tng t, nh dng Chebyshev-I, ca s vi cc tham s
u vo nh sau:
s = 0.2

Rp = 1 dB

p = 0.3

As = 16 dB

Vit chng trnh tnh v biu din trn th:


a. ln ca p ng tn s
b. Hm p ng pha ca b lc
c. Hm ln tng i tnh theo dB ca p ng tn s
d. Hm p ng xung ca b lc tng t
20 | P a g e

Wp = 0.2*pi; Ws =0.3*pi; Rp = 1; As = 16;


Ripple = 10^(-Rp/20); Attn = 10^(-As/20);
[b,a] = afd_chb1(Wp,Ws,Rp,As);
% Dap ung tan so
[db,mag,pha,w] = freqs_m(b,a,0.5*pi);
%Dap ung xung
[ha,x,t] = impulse(b,a);
%
subplot(2,2,1); plot(w/pi,mag); grid;
axis([0,0.5,-0.1,1.1]);
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Hr(w)');
%
subplot(2,2,2); plot(w/pi,db); grid;
axis([0,0.5,-40,5]);
title('Magnitude Response in dB');
xlabel('frequency in pi units'); ylabel('Decibels');
%
subplot(2,2,3); plot(w/pi,pha/pi); grid;
axis([0,0.5,-1.0,1.0]);
title('Phase Response');
xlabel('frequency in pi units'); ylabel('radians');
%
subplot(2,2,4); plot(t,ha); grid;
axis([0,50,-0.10,0.25]);
title('Impulse Response');
xlabel('time in seconds'); ylabel('ha(t)');

21 | P a g e

2.9. Chuyn i b lc vi cc tham s cho phn 2.16 sang b lc s bng


phng php bin i song tuyn. Hm bilinear cho php thc hin vic chuyn i ny.
Tnh v biu din trn th:
a. ln ca p ng tn s
b. Hm p ng pha ca b lc
c. Hm ln tng i tnh theo dB ca p ng tn s
d. Tr nhm theo tn s.
% Chi tieu ky thuat cua bo loc so:
wp =0.2*pi;
% digital Passband freq in Hz
ws =0.3*pi;
% digital Stopband freq in Hz
Rp = 1;
% Passband ripple in dB
As = 15;
% Stopband attenuation in dB
% Chi tieu ky thuat cua bo loc tuong tu: Anh xa nguoc
T = 1; Fs =1/T;
% Dat T=1
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
% Tinh toan bo loc tuong tu:
[cs, ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
% Bien doi song tuyen:
22 | P a g e

[b,a] = bilinear(cs,ds,Fs);
%
[db,mag,pha,grd,w] = freqz_m(b,a);
%plot
figure(37); clf;
%
subplot(2,2,1); plot(w/pi,mag);
axis([0,1,0,1.2]); grid
title('Amplitude Response');
xlabel('frequency in pi units'); ylabel('|Hr(w)|');
%
subplot(2,2,3); plot(w/pi,db);
axis([0,1,-30,10]); grid
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Decibels');
%
subplot(2,2,2); plot(w/pi,pha/pi);
axis([0,1,-1,1]); grid
title('Phase Response');
xlabel('frequency in pi units'); ylabel('Angle(Hr(w))');
%
subplot(2,2,4); plot(w/pi,grd);
axis([0,1,0,15]); grid
title('Group Delay');
xlabel('frequency in pi units'); ylabel('Samples');

23 | P a g e

2.10. Thc hin yu cu ca cu 2.9 theo phng php bt bin xung, dng hm
impinvar ca MATLAB. So snh kt qu thu c vi cu trn.
% Chi tieu ky thuat cua bo loc so:
wp =0.2*pi;
% digital Passband freq in Hz
ws =0.3*pi;
% digital Stopband freq in Hz
Rp = 1;
% Passband ripple in dB
As = 15;
% Stopband attenuation in dB
% Chi tieu ky thuat cua bo loc tuong tu: Anh xa nguoc
T = 1; Fs =1/T;
% Dat T=1
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
% Tinh toan bo loc tuong tu:
[cs, ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
% Bien doi bat bien xung:
[b,a] = impinvar(cs,ds,Fs);
%
[db,mag,pha,grd,w] = freqz_m(b,a);
%plot
figure(37); clf;
%
subplot(2,2,1); plot(w/pi,mag);
axis([0,1,0,1.2]); grid
title('Amplitude Response');
xlabel('frequency in pi units'); ylabel('|Hr(w)|');
%
subplot(2,2,3); plot(w/pi,db);
axis([0,1,-30,10]); grid
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Decibels');
%
subplot(2,2,2); plot(w/pi,pha/pi);
axis([0,1,-1,1]); grid
title('Phase Response');
xlabel('frequency in pi units'); ylabel('Angle(Hr(w))');
%
subplot(2,2,4); plot(w/pi,grd);
axis([0,1,0,15]); grid
title('Group Delay');
xlabel('frequency in pi units'); ylabel('Samples');

24 | P a g e

2.11. To hm thc hin vic chuyn i bng tn s, tr v hm truyn t ca b lc


mi vi tham s u vo l hm truyn t ca b lc thng thp, hm a thc th hin
php i bin s c lp, ghi li theo tn tp l zmapping.m:
function [bz,az] = zmapping(bZ,aZ,Nz,Dz)
% Chuyen doi bang tan so tu mien Z sang mien z
% ------------------------------------------------------% [bz,az] = zmapping(bZ,aZ,Nz,Dz)
% perform:
%
b(z)
b(Z)|
%
---- = ----|
N(z)
%
a(z)
a(Z)|Z = ---%
D(z)
%
bzord = (length(bZ)-1)*(length(Nz)-1);
azord = (length(aZ)-1)*(length(Dz)-1);
bz = zeros(1,bzord+1);
for k = 0:bzord
pln = [1];
for l = 0:k-1
pln = conv(pln,Nz);
end
25 | P a g e

pld = [1];
for l = 0:bzord-k-1
pld = conv(pld,Dz);
end
bz = bz+bZ(k+1)*conv(pln,pld);
end
%
az = zeros(1,azord+1);
for k = 0:azord
pln = [1];
for l = 0:k-1
pln = conv(pln,Nz);
end
pld = [1];
for l = 0:azord-k-1
pld = conv(pld,Dz);
end
az = az+aZ(k+1)*conv(pln,pld);
end
%
az1 = az(1); az = az/az1; bz=bz/az1;

2.12. Vit chng trnh chuyn i t b lc thng thp theo thit k ca cu 1.9 sang
b lc thng cao c tn s ct c=0,6. Tnh v biu din trn th
a. ln ca p ng tn s
b. Hm p ng pha ca b lc
c. Hm ln tng i tnh theo dB ca p ng tn s
d. Tr nhm theo tn s.
% Chi tieu ky thuat cua bo loc so:
wp =0.2*pi;
% digital Passband freq in Hz
ws =0.3*pi;
% digital Stopband freq in Hz
Rp = 1;
% Passband ripple in dB
As = 15;
% Stopband attenuation in dB
% Chi tieu ky thuat cua bo loc tuong tu: Anh xa nguoc
T = 1; Fs =1/T;
% Dat T=1
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
% Tinh toan bo loc tuong tu:
[cs, ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
% Bien doi song tuyen:
[b,a] = bilinear(cs,ds,Fs);
% Chuyen doi bang tan so
% wc_l: tan so cat cua bo loc thong thap
% wc_h: tan so cat moi
26 | P a g e

wc_h = 0.6*pi;
wc_l = wp;
alpha = -cos((wc_l + wc_h)/2)/cos((wc_l - wc_h)/2);
Nz = -[alpha,1]; Dz = [1,alpha];
[b_h,a_h] = zmapping(b,a,Nz,Dz);
[db,mag,pha,grd,w] = freqz_m(b_h,a_h);
%plot
figure(37); clf;
%
subplot(2,2,1); plot(w/pi,mag);
axis([0,1,0,1.2]); grid
title('Amplitude Response');
xlabel('frequency in pi units'); ylabel('|Hr(w)|');
%
subplot(2,2,3); plot(w/pi,db);
axis([0,1,-30,10]); grid
title('Magnitude Response');
xlabel('frequency in pi units'); ylabel('Decibels');
%
subplot(2,2,2); plot(w/pi,pha/pi);
axis([0,1,-1,1]); grid
title('Phase Response');
xlabel('frequency in pi units'); ylabel('Angle(Hr(w))');
%
subplot(2,2,4); plot(w/pi,grd);
axis([0,1,0,15]); grid
title('Group Delay');
xlabel('frequency in pi units'); ylabel('Samples');

27 | P a g e

- HT -

28 | P a g e

You might also like