You are on page 1of 5

Bi thc hnh x l tn hiu v lc s

BI 1.

1.

M PHNG H THNG V TN HIU RI RC


BNG MATLAB

Yu cu trc khi lm th nghim


Sinh vin nm vng kin thc v Tn hiu v h thng ri rc bao gm:
Cc tn hiu c bn
H thng tuyn tnh bt bin v p ng xung ca h thng tuyn tnh bt
bin
Phng trnh sai phn tuyn tnh h s hng

2.

Mc ch ca phn th nghim
Sinh vin dng MATLAB m phng cc ni dung sau:
Cc tn hiu c bn min thi gian
Tnh tch chp
p ng ca h thng c m t bi phng trnh sai phn tuyn tnh h s
hng

3. Mt s lnh v hm ca MATLAB
Phn ny a ra danh mc cc lnh cc hm ca MATLAB c th s dng trong phn th
nghim ny. bit c th hn v chc nng ca hm v c php ca lnh gi hm, g lnh
help km theo tn ca hm ti ca s lnh ca MATLAB.
zeros: to mt ma trn vi ton b cc phn t c gi tr bng 0.
ones: to mt ma trn vi ton b cc phn t c gi tr bng 1.
rand: to mt ma trn vi cc phn t nhn cc gi tr ngu nhin c phn b u trong
khong t 0 n 1.
randn: to mt ma trn vi cc phn t nhn cc gi tr ngu nhin theo phn b Gauss c gi
tr trung bnh bng 0, phng sai bng 1.
min: tr v gi tr nh nht trong mt ma trn.
max: tr v gi tr ln nht trong mt ma trn.
fliplr: ln ngc li th t cc phn t trong mt ma trn theo hng xut pht t phi qua tri
tr thnh t tri qua phi.
plot v stem: v th ca mt dy s, plot th hin dng lin tc, stem th hin dng ri
rc, thng s dng hm stem v tn hiu min n.
conv: tr v tch chp ca 2 vector.
filter: tr v p ng theo thi gian ca h thng c m t bi mt phng trnh sai phn
tuyn tnh h s hng.
Ngoi ra, sinh vin cn tm hiu mt cch rt cn thn cc php ton trn ma trn v
vector trong phn tr gip (Help) ca MATLAB bng cch nhn F1 ri vo mc
MATLAB -> Getting Started -> Matrices and Arrays.

4.

Cc bc thc hnh

1.1.
To cc dy xung n v v dy nhy n v theo chng trnh mu bng cch g cc
dng lnh cho 2 bng di y vo ca s son tho (Editor) v ghi li theo cc tn tp ln
lt l impseq.m v stepseq.m:
GV: Cao Thnh Ngha

Bi thc hnh x l tn hiu v lc s


Dy xung n v:
function [x,n] = impseq(n0,n1,n2)
%Tao ra day x(n) = delta(n-n0); n1 <= n <= n2
%---------------------------------------------%[x,n] = impseq(n0,n1,n2)
n = [n1:n2]; x = [(n-n0) == 0];
Dy nhy n v:
function [x,n] = stepseq(n0,n1,n2)
%Tao ra day x(n) = u(n-n0); n1 <= n <= n2
%---------------------------------------------%[x,n] = stepseq(n0,n1,n2)
n = [n1:n2]; x = [(n-n0) >= 0];
1.2.
Vit chng trnh to dy hm m thc vi cc tham s u vo v u ra c
nhp theo cu lnh:
[x,n] = expseq(a,n1,n2)
Ch : tham s a c th thc hoc phc
1.3.
Vit chng trnh 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. Cc tham s u vo
v u ra c nhp theo cu lnh:
[x,n] = randnseq(n1,n2)
1.4.
To cc hm cng 2 dy v nhn 2 dy vi cc ch s u v ch s cui ca hai
dy tng ng khc nhau, hm to tr v hm bin s n o theo chng trnh mu bng
cch g cc dng lnh cho 4 bng di y vo ca s son tho (Editor) v ghi li
theo cc tn tp ln lt l cong.m, nhan.m, tre.m v dao.m
Cng 2 dy:
function [y,n] = cong(x1,n1,x2,n2)
%Thuc hien y(n) = x1(n)+x2(n)
%---------------------------------------------%[y,n] = cong(x1,n1,x2,n2)
% y = day tong co vector chi so n
%x1 = day thu nhat co vector chi so n1
%x2 = day thu hai co vector chi so n2 (n2 co the khac n1)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1)) = x1;
y2(find((n>=min(n2))&(n<=max(n2))==1)) = x2;
y = y1+y2;
Nhn 2 dy:
function [y,n] = nhan(x1,n1,x2,n2)
%Thuc hien y(n) = x1(n)*x2(n)
%---------------------------------------------% y = day tich co vector chi so n
%x1 = day thu nhat co vector chi so n1
GV: Cao Thnh Ngha

Bi thc hnh x l tn hiu v lc s


%x2 = day thu hai co vector chi so n2 (n2 co the khac n1)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1)) = x1;
y2(find((n>=min(n2))&(n<=max(n2))==1)) = x2;
y = y1.*y2;
Tr (dch):
function [y,n] = tre(x,m,n0)
%Thuc hien y(n) = x(n-n0)
%---------------------------------------------%[y,n] = tre(x,m,n0)
n = m + n0; y = x;
Bin s n o:
function [y,n] = dao(x,n)
%Thuc hien y(n) = x(-n)
%---------------------------------------------%[y,n] = dao(x,n)
y = fliplr(x); n = -fliplr(n);
1.5.
Vit chng trnh to hm nng lng ca mt dy vi cc tham s u vo v
u ra c nhp vo theo cu lnh: Ex = energy(x,n);
1.6.

Th hin trn th dy x(n) = 2 (n + 2) 2 (n 4), 5 n 5

theo chng trnh mu bng cch g cc dng lnh theo bng di y vo ca s son tho
(Editor)
v ghi li theo tn tp Solution_1_6.
n = [-5:5];
x = 2*impseq(-2,-5,5) - impseq(4,-5,5);
stem(n,x);
title('Day so theo dau bai 1.5');
xlabel('n'); ylabel('x(n)');
G Solution_1_6 ti ca s lnh ca MATLAB chy kch bn ni trn v xem th
ca dy s.
Mt s v d
Bi 1: Cho dy xung n v v chng trnh v chng nh sau:
Dy xung n v:
clf;
% Tao day xung don vi
n = -10:20;
delta = [zeros(1,10) 1 zeros(1,20)];
subplot(2,1,1);
stem(n,delta);
xlabel('thoi gian roi rac n'); ylabel('bien do');
title('tao day xung don vi');
axis([-10 20 0 1.2]);
GV: Cao Thnh Ngha

Bi thc hnh x l tn hiu v lc s


C th nh sau

Yu cu:
T chng trnh trn, hy vit chng trnh v th ca cc dy sau c dng
1. Dy nhy n v u(n) c dng sau:

2. Vit dy dc n v r(n);

3. Vit chng trnh biu din hm m thc trn th


Bi 2: Cho dy ch nht vi chiu di L v chng trnh sau
clf;
%tao day chu nhat
n = 0:20;
L=10;
GV: Cao Thnh Ngha

Bi thc hnh x l tn hiu v lc s


chunhat= [ones(1,L) zeros(1,20-L+1)];
subplot(2,1,1);
stem(n,chunhat); grid;
xlabel('thoi gian roi rac n'); ylabel('bien do');
title('tao day xung chu nhat');
axis([0 20 0 1.2]);

Yu cu:
Trn c s chng trnh cho, sinh vin hy :
- vit thm vo chng trnh va v th cho v va v th ca tn hiu tr
i 3 mu
- Mun thay i chiu di ca dy phi lm th no

GV: Cao Thnh Ngha