Trang 76 Hàm freqs MATLAB decibels.. bài 6.4 bilinear cho phép này.
Trang 1Biên
www.hutech.edu.vn
Trang 2*1.2021.ELS314*
tailieuhoctap@hutech.edu.vn
Trang 3I III
AB 1
1.1 MATLAB 1
1.2 CÁC 5
5
6
6
1.3 TRÌNH TRONG MATLAB 7
7
1.3.2 Sw itch 7
1.3.3 While 8
1.3.4 For 8
1.3.5 Break: 8
1.4 MA 8
8
1.4.2 Vector 13
13
1.5 14
14
15
15
16
-D 16
17
c 18
23
25
26
1.6 CÁC FILE VÀ HÀM 28
28
1.6.2 File hàm .29
30
1.6.4 Các phép toán trên hàm .31
32
41
2.1 CÁC TÍN 41
Trang 42.2 CÁC PHÉP TOÁN 42
2.3 TRA TÍNH TÍNH VÀ 43
2.4 H LTI 45
47
3.1 CÁC VÀ KHÔNG 47
3.2 PHÂN TÍCH DÙNG PHÁP 49
3.3 Z VÀ Z 49
52
4.1 TÍNH DTFT 52
4.2 FFT VÀ CÁC TÍNH 54
56
5.1 CÁC 56
5.2 PHÁP 58
5.3 PHÁP 62
5.4 PHÁP 64
68
6.1 68
6.2 73
TÀI THAM 78
Trang 6- 5
Trang 7MATLAB:
Trang 131.3.2 Switch
case n1
case n2
Trang 14case nn
Trang 17BÀI 1: 11
1.4.1.6 Xoá hàng và c t
1.4.1.7 Các l nh x lý ma tr n
- B Nhân : X = A*B
Trang 18>> A(2,3) Bài 1.1
Trang 25{\
Trang 27BÀI 1: 21
\bf Bold font
\it Italic font
\sl Oblique font (rarely available)
sin(\om ega_0 \tau)')
K t qu :
Trang 28>>text('units','inch' , 'po sitio n',[.2 5],
'fontsize',14, 'inter prete r', ' latex', 'string' ,
['$$\hb ox {magic(3) is } \left( {\ma trix{ 8 & 1 & 6 \cr ' '3 & 5 & 7 \cr 4 & 9 & 2 } } \ri ght)$$']);
>>text('units','inch' , 'po sitio n',[.2 4],
'fontsize ',14, 'in terpr eter','latex', 'stri ng',
['$$\le ft[ {\matrix{\cos(\phi) & -\sin(\phi) \cr'
'\sin(\phi) & \co s(\ph i) \cr}} \right ]'
'\left[ \matrix{x \cr y} \right] $$']);
>>text('unit s','inch' , 'po sition',[.2 3],
'fontsize ',14, 'in terpr eter','latex', 'stri ng',
['$$L\{f(t)\} \equiv F(s) = \in t_0^\infty \!\!{ e^{-st}'
'f(t)dt}$$']);
>>text('units','inch' , 'po sitio n',[.2 2],
'fontsize ',14, 'in terpr eter','latex', 'stri ng',
'$$e = \sum_{k=0} ^\infty {1 \over {k!} } $ $');
>>text('units','inch' , 'po sitio n',[.2 1],
'fontsize ',14, 'in terpr eter','latex', 'stri ng',
['$$m \ddot y = -m g + C_D \cdot {1 \over 2}'
'\rho {\dot y}^2 \cdot A$$' ]);
>>text('unit s','inch' , 'po sition',[.2 0],
'fontsize ',14, 'in terpr eter','latex', 'stri ng',
\frac{\sqrt{ \pi}}{4}$$');
-project.org/
Trang 32>>grid on %hien thi l uoi
>>hold on %giu hinh, mac n hien la hold off
>>y2=sin(x.^2); %luy thua tung phan tu
>>axis([0 4*pi 1.25 1.25] ) %dinh lai toa do h ien thi
>>legenBài 1.11 Th c hi
th cho plot
>>theta=0:0.05:2*pi;
Trang 33BÀI 1: 27
>>r=sin(5*theta);
>>polar(theta,r)Bài 1.14 V hàm s r = 2sin( ) + 3cos( )
Trang 34>> [x,y]=meshgrid(t); %din h luo i ve
i = i + 1;
end plot(f)
Trang 39BÀI 1: 33
MATLAB Editor:
>>edit script file có
% Doan script file nay hien thi loi chao trong 2s Sau do hien thi logo cua MATLAB roi th oat
'Color','w',
Trang 40'Positi on',[0 5],
'Fontsize',32,
'FontAngle','italic') ; axis off;
pause(2); % dung tron g 2 g iay
% Hien thi logo cua MATLAB - - - logo
clear all close
% ket thuc script fil e
Trang 41help <ten toolbox> % chuc nang toolbox
>>help control % liet ke h am cu a control toolbox
lookfor
MATLAB
lookfor <tu khoa tim kiem>
Trang 42function [x1,x2]=gptb 2(a,b ,c)
% Giai phuong trinh b ac ha i ax^ 2+bx+c=0
% [x1,x2]=gptb2(a,b,c )
% Trong do: x1,x2 la nghie m
% a, b, c la 3 he so cua p huong trinh
Trang 43BÀI 1: 37
if nargin<3 error('Error! Nhap 3 he so cua phuong trinh') elseif a==0
x1=-c/b;
x2=[];
else delta = b^2 - 4* a*c;
Bài 1.23
ng Becnulli:
Trang 44function vdcongdb(a,m ,meth od)
% Ve duong cong trong toa do cu c: vdcongdb(a,m ,method)
% method = 'Becnulli' - Ve duong Lemnisca t Bec nulli:
% r=a*sqrt(abs(2*cos( 2*the ta)))
% 'Astroit' - Ve duong Astroit:
theta=0:0.01:2*pi; me thod= upper (method);
switch method case 'BECNULLI' r=a*sqrt(abs(2*cos(2* theta )));
case 'ASTROIT' r=a*sqrt(abs(1-sin(3* theta)/4));
case 'XOANOC' r=a*cos(theta)+1;
otherwise error('Chon: ''Becnul i'', ''Ast roit'' hoa c ''Xoano c''') end % end of switch
% ve do thi close all; figure('Co lor', 'w');
for k=1:m hold on r1=r*k;
mau=[rand(1,1) rand(1 ,1) r and(1 ,1)];
Trang 45tiep = 'y'; sai=0; du ng=0;
disp('Chao mung ban den vo i chuong trinh du do an xuc xa c!') while(lower(tiep)=='y ')
doan=input('Moi ban d u doa n ket qua (1-6) :');
kqua=tungxx;
if (doan ~= kqua)
Trang 46disp('Xin loi, ban da doan sai! ') sai=sai+1;
else disp('Xin chuc mung!' ) dung=dung+1;
end tiep=input('Ban muon choi tiep( ''y'' /''n''):');
end
num2str(sai+dung) ' l an do an'])
% subfunction - function mat = tungxx ()
mat=floor(6*rand(1,1) )+1;
% end
Bài 1.26
Trang 48Bài 2.3 Tín n -10,10); (0,1000); (0,1e6)
Trang 50>>y = n.*(a1*x1 + a2* x2);
>>subplot(211), stem( n,a1* y1+a2 *y2);
>>subplot(212), stem( n,y);
y(n) = x(n2)
Trang 56Bi c:
h các th a s th
Trang 60end
Trang 65BÀI 5: 59
function hd = ideal_l p(wc, M) alpha = (M-1)/2;
function [db,mag,pha, grd,w ] = f reqz_m(b,a)
% db = Do lon tuong d oi th eo dB tren doan tu 0 den pi
% mag = Do lon tuyet doi t ren d oan tu 0 den pi
% pha = Dap ung pha t ren d oan t u 0 den pi
% grd = Tre nhom tren doan tu 0 den pi
% w = Cac mau tan so doan tu 0 den pi
% b = Cac he so da th uc tu so c ua H(z) (voi FIR: b=h)
% a = Cac he so da th uc ma u so cua H(z)(voi FIR: a=[1]) [H,w] = freqz(b,a,1000,'whole' );
p = 0.2 ; s = 0.3 ; Rp = 0.25 dB; As = 50 dB
-
p
Trang 66hamming, blackman, Kaiser
>>Rp = -(min(db(1:1:w p/del ta_w+ 1)))
>>As = -round(max(db( ws/de lta_w +1:1:501)))
Trang 68H(k) = [1,1,1,1,1,1,1,T1,T2 2,T1,1 ,1,1,1 ,1,1]
>>M = 6 0; al pha = (M-1)/2; L = 0:M-1; wl = (2*pi/M )*L;
>>Hk = [ones(1, 7),0.5925,0.1099,zeros(1 ,43), 0.1099, 0.5925, ones(1,6)];
% Dap ung ta n so mau ly tu ong
>>Hdr = [1,1,0,0]; wd l = [ 0,0.2 ,0.3,1];
% Dap ung tan so ly t uong de bi eu dien do thi
Trang 69BÀI 5: 63
>>k1 = 0:flo or((M-1)/2); k2 = f loor( (M-1) /2)+1:M-1;
>>angH = [-alpha*(2*p i)/M* k1, alpha*(2*pi )/M*( M-k2 )];
>>title ('Cac mau tan so: M=60, T2 = 0.592 5, T1 = 0.1099 ');
>>xlabe l(f[* \pi]'); y label ('Hr(k)');
>>title ('Bien do cua dap u ng tan so');
>>xlabe l('f[ *\pi ]'); ylabe l('Hr (w)') ;
>>subpl ot(22 4); plot(w/pi, db);
>>axis( [0,1, -100,10]); gri d
>>title ('Bien do cua dap u ng ta n so ');
>>xlabe l('f[ *\pi ]'); ylabe l('dB ');
Trang 72delta2 = (1+delta1)*( 10^(-As/20 ));
deltaH = max(delta1,d elta2 );
deltaL = min(delta1,d elta2 );
weights = [delta2/del ta1 1 ];
Asd = -max(d b(wsi:1:5 01)) while Asd<As
M = M+1 [h,ERR,RES] = firpm(M -1,f,m,wei ghts) ; [db,mag,pha,grd,w] = freqz _m(h, [1]);
Asd = -max(d b(wsi:1:5 01)) end
n = [0:1:M-1];
subplot(221); stem(n, h);
Trang 73title(' Dap u ng tan so ');
xlabel( 'f[*\pi]'); yl abel('Hr(\omega )');
subplot(224); plot(RE S.fgr id,RES.error); grid;
axis([0,1,-0.0150,0.0 150]) ; title(' Dap u ng tan so cua loi') ; xlabel( 'f[*\pi]'); yl abel( 'Er(\omega )');
Bài 5.16
s1 = 0.2 ; p1 = 0.35 ; p2 = 0.65 ; s2 = 0.8 ; Rp = 1 dB; As = 60 dB
Trang 75impinvar, bilinear
tính
butter, cheby1, cheby2, ellip
tính
Trang 76Hàm freqs MATLAB
decibels
function [db,mag,pha, w] = freqs _m(b,a,wmax);
% db = Do lon tu ong doi theo dB tren doan tu 0 den wmax
% mag = Do lon tuyet doi t ren d oan tu 0 den wmax
% pha = Dap ung pha t ren d oan t u 0 den wmax
% w = Cac mau tan so tren doan tu 0 den wmax
% b = Cac he so da th uc tu so c ua Ha(s)
% a = Cac he so da th uc ma u so cua H a(s)
% wmax = Tan so cuc d ai th eo do n vi rad/sec tren doan
% tan so mong muon ti m dap ung tan so
Trang 77% Bo loc thong thap dang C hebyshev-1
% tan so cat khong du oc ch uan h oa
% [b,a] = u_chb1ap(N, Rp,Om egac)
% b = cac he so da th uc tu so c ua Ha(s)
% a = cac he so da th uc ma u so cua Ha(s)
% N = Bac cua bo loc Cheby shev-I
% Rp = Do gon dai tho ng th eo do n vi dB; Rp > 0
% Omega c = tan so cat theo don vi ra dians /sec [z,p,k] = cheb1ap(N,R p);
Trang 78b0 = k;
b = k*B;
: function [b,a] = afd_ chb1( Wp,Ws ,Rp,As)
% Analog Lowpass Filter De sign: Cheb yshev -1
% [b,a] = afd_chb1(Wp ,Ws,R p,As)
% b = cac he so da th uc tu so c ua Ha(s)
% a = cac he so da th uc ma u so cua Ha(s)
% Wp = tan so cat dai thon g the o don vi rad/sec; Wp >0
% Ws = tan so cat dai chan theo don vi rad/sec; Ws >Wp >0
% Rp = Do gon dai tho ng th eo do n vi dB; (Rp > 0)
% As = Do suy giam da i cha n the o don vi +dB; (Ap > 0)
if Wp <= 0 error('Tan so cat dai thon g pha i lon hon 0') end
if Ws <= Wp error('Tan so cat dai thong phai lon ho n tan so cat da i chan')
end
if (Rp <= 0) | (As<0) error('Do gon dai th ong va/hoac Do suy giam dai chan phai lon hon 0')
end
ep = sqrt(10^(Rp/10)-1);
Trang 80Bài 6.5 bài 6.4
bilinear cho phép
này
bai605.m
wp =0.2*pi; % digital Pass band freq in Hz
ws =0.3*pi; % digital Stop band freq in Hz
Rp = 1; % Passband ri pple in dB
As = 15; % Stopband a ttenu ation in dB
T = 1; Fs =1/T; % Dat T=1 OmegaP = (2/T)*tan(wp /2);
OmegaS = (2/T)*tan(ws /2);
% Tinh toan bo loc tu ong t u:
[cs, ds] = afd_chb1(O megaP ,Omeg aS,Rp,As);
% Bien doi song tuyen tinh : [b,a] = bilinear(cs,d s,Fs);
[db,mag,pha,grd,w] = freqz _m(b, a);
subplot(221); plot(w/ pi,ma g);
axis([0,1,0,1.2]); gr id title('Dap u ng tan so ');
xlabel('f[*\pi]'); yl abel('|H_r(\omega)|');
subplot(222); plot(w/ pi,db );
axis([0,1,-30,10]); g rid title('Dap u ng tan so theo dB');
xlabel('f[*\pi]'); yl abel('dB');
Trang 81BÀI 6: 75
c
subplot(223); plot(w/ pi,ph a/pi);
axis([0,1,-1,1]); gri d title(' Dap u ng pha');
xlabel( 'f[*\pi]'); yl abel( 'Angle(H_r(\omega))');
d
subplot(224); plot(w/pi,grd);
axis([0,1,0,15]); gri d title('Group Delay');
xlabel(' f[*\pi]'); y label ('Samples');
Trang 82bz = zeros(1,bzord+1) ; for k = 0:bzord
pln = [1];
for l = 0:k-1 pln = conv(pln,Nz);
end pld = [1];
for l = 0:bzord-k-1 pld = conv(pld,Dz);
end
bz = bz+bZ(k+1)*conv( pln,p ld); 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,p ld); end
az1 = az(1); az = az/ az1; bz=bz/az1;
Trang 83BÀI 6: 77
c=0.6