You are on page 1of 196

T T

Biên

www.hutech.edu.vn
*1ï2019ïCAP221*
này, xin - :
tailieuhoctap@hutech.edu.vn
I

...................................................................................................................I
.......................................................................................................... IV
................................................................................................... VI
AB.....................................................................................................................................1

....................................................................................................... 1
1.2 .......................................................................................... 3
................................................................................. 3
.................................................................................................. 5
...................................................................................... 5
....................................................... 5
.......................................................................................................... 6
........................................................................................................ 12
................................................................................... 12
1.2.8 Các file và hàm.......................................................................................................................................15
............................................................................................................ 20
.................................................................................................. 20
.................................................................................................. 21
.............................................................................................. 21
............................................................................................ 22
......................................................................................... 23
...................................................................................... 24
............................................................................... 25
........................................................... 25
........................................................................... 26
:.......................................................................................... 29
.................................................................................................. 34
................................................................................................................ 36
.................................................................................................... 36

-GUI (GRAPHIC USER INTERFACE) ................................. 39


2.1 ........................................................................................................... 39
................................................................................. 41
........................................................................................................ 43
.......................................................................... 44
................................................................................................. 45
................................................................................................................ 49
.................................................................................................... 49
BÀI 3: SYMBOLIC....................................................................................................................................................52
II
...................................................................................... 53
3.2 TÍCH PHÂN.....................................................................................................................................................54
..................................................................................................... 54
........................................................................................................ 55
................................................................................... 56
.................................................. 57
................................................................................................. 61
................................................................................................................ 62
.................................................................................................... 62
BÀI 4: SIMULINK....................................................................................................................................................63
........................................................................................ 65
........................................................................................................65
...........................................................................................68
.....................................................................................................68
4.1.4 Ghi chú.......................................................................................................................................................69
............................................................................70
...............................................................................71
...........................................................................................71
4.2 MÔ HÌNH HOÁ..............................................................................................................................................72
.........................................................................72
............................................................74
..............................................................................74
.............................................................75
....................................................76
.....................................................77
4.2.7 Mô ....................................................................79
................................................................................79
............................................................................................................81
................................................................................................................ 84
.................................................................................................... 84
BÀI 5: CÁC TOO ................................................................................... 87
5.1 COMMUNICATION.....................................................................................................................................87
5.1.1 Hàm.............................................................................................................................................................87
5.1.2 Simulink...................................................................................................................................................104
..........................................................................................................115
5.2 SIMSCAPE MULTIBODY.......................................................................................................................122
5.2.1 Bodies.......................................................................................................................................................122
5.2.2 Joints.........................................................................................................................................................129
5.2.3 Constraints & Drivers.........................................................................................................................136
5.2.4 Sensors & Actuators...........................................................................................................................140
5.2.5 Force & Elements.................................................................................................................................146
III
..........................................................................................................146
5.3 CONTROL SYSTEM..................................................................................................................................153
5.3.1 .........................................................................................153
.......................................................................................158
5.3.3 PID Tuning..............................................................................................................................................163
Control System Designer...........................................175
.............................................................................................................. 180
.................................................................................................. 180
.......................................................................................... 182
IV

M
Tin h k t cho sinh viên

Bài 1. .

Bài 2. GUI.

Bài 3. Simulink.

Bài 4. Symbolic.

Bài 5. Các toolbox .

c Tin h k t .

ý
V

5 nh, phù h

5 trong 90 phút.
VI

ADS-B - Automatic Dependent Surveillance-Broadcast

AM Amplitude Modulation:

AWGN Additive

BER Bit error rate

BPSK Binary Phase Shift Keying

CPFSK Continuous Phase Frequency Shift Keying: FSK pha

CPM Continuous Phase

CRC Cyclic Redundancy Check m tra

DBPSK Differential BPSK: BPSK

vi phân

FM Frequency Modulation:

FSK - Frequency Shift Keying

GMSK Gaussian Minimum-Shift Keying

IMC

LQG

LTE Long Term Evolution

MIMO Multiple Input Multiple Output

OFDM - Orthogonal Frequency-Division Multiplexing: ghép kênh

OQPSK Offset QPSK

OVSF - Orthogonal Varia giao

PAM - Pulse Amplitude Modulation:

PID - Proportional Integral Derivative

PM Phase Modulation:
VII

QAM Quadrature Amplitude Modulation:

QPSK - Quadature Phase Shift Keying

SER Symbol error rate .


1
BÀI

BÀI 1:

- .

- b.

MATLAB (Matrix laboratory

toolboxes
uy
, fuzzy logic

vào icon

Hình 1.1:
2
BÀI

Hình 1.2:

mand window:

Matlab, là

built-in
function m m-files

A = pi/2;

B = sin(A)

B=1

bytes hó trình.
3
BÀI

edit

Hình 1.3:

% Chuong trinh trong M-file


x= 0:pi/6:2*pi;
y=sin(x);
plot(x,y);
file plot_sin.m s

plot_sin

or:

edit

- script file: nh kê,

1.2 CÁC V N
1.2.1 Các phép toán và toán t

Các phép toán:

+ , - , * , / , \ (chia trái '


4
BÀI

Các toán t :

< , <= , > , >= , == , ~=

Các to :

& , | (or) , ~ (not)

pi 3.14159265

eps 2-52

realmin -1022

realmax 1023

inf vô

NaN Not a number

1.1:

a= 1;

b=-2;

c=1;

delta= b^2- 4*a*c; %Tinh

delta x1=(-b +

sqrt(delta))/(2*a) x2=(-b -

sqrt(delta))/(2*a) Chú ý:

màn hình.

- Các chú thíc .

-
..)
5
BÀI

1.2.2 Khai báo bi n

- i .

-
global

1.2.3 Các l ng dùng


help tên_hàm %

lookfo

clc % Xoá màn hình

clear all %

clf %Xoá figure

save % file

load % file

who %

whos %

which

what

1.2.4 n vào file và l y n i dung bi n t file

save file.

t c các bi n vào file test.mat:


save test.mat
bi n p, q vào file, tron file là 1 bi
n: savefile = 'test.mat';
6
BÀI

p = rand(1, 10);
q = ones(10);
save(savefile, 'p', 'q');
% n d ng c u trúc:
s1.a = 12.7;
s1.b = {'abc', [4 5; 6 7]};
s1.c = 'Hello!';
save('test.mat', '-struct', 's1');

Khi n trong fi
-append.

p = rand(1, 10);
q = ones(10);
save('test.mat', 'p'); % bi n p
save('test.mat', 'q'); % bi n q p b xóa
save('test.mat', - ); % bi n p và không xóa q

load file.

load('test.mat'); % L y t t c các bi
load('test.mat', 'p'); % L y bi n p trong file test.mat

1.2.5 Ma tr n

1.2.5.1 Nh p ma tr n

vector

- r file

- trong MATLAB

-
7
BÀI

- Bao các ph ]

1.2:

A = [16 3 2 13; 5 10 11 8;9 6 7 12;4 15 14 1];

sum(A)

ans = 34 34 34 34

MATLAB dùn ans, vi


answer.

ans =

16 5 9 4
3 10 6 15
2 11 7 14
13 8 12 1

1.2.5.2 Ch s

ý
tham

1.2.5.3 Toán t

Toán t

1:10

ans = 1 2 3 4 5 6 7 8 9 10

100: 5
8
BÀI

ans = 100 93 86 79 72 65 58 51

0: pi/4:
/4

ans = 0 0.7854 1.5708 2.3562 3.1416

A(:,3)

ans =

2
11
7
14

A(3,:)

ans =

9 6 7 12

B=

16 2 3 13

5 11 10 8

9 7 6 12

4 14 15 1

1.2.5.4 T o ma tr n b ng hàm có s n

- linspace: vector

a = linspace vector

a =1.0000 1.2857 1.5714 1.8571 2.1429 2.4286 2.7143 3.0000 3.2857 3.5714 3.8571
4.1429 4.4286 4.7143 5.0000
9
BÀI

- zeros:

z = zeros(2, 4)

z=

0000

0000

- ones

x = ones(2, 3)

x=

111

111

y = 5*ones(2, 2)

y=

55

55

- rand

d = rand(4, 4)

d=

0.9501 0.8913 0.8214 0.9218

0.2311 0.7621 0.4447 0.7382

0.6068 0.4565 0.6154 0.1763

0.4860 0.0185 0.7919 0.4057

- randn

e = randn(3, 3)

e=

-0.4326 0.2877 1.1892

-1.6656 -1.1465 -0.0376

0.1253 1.1909 0.3273


10
BÀI

- magic(n) n2
3).

- pascal(n) Pascal.

pascal(4)

ans = 1

111

1234

1 3 6 10

1 4 10 20

- eye(n)

eye(3)

ans =

100

010

001

- eye(m,n)

eye(3,4)

ans = 1

000

0100

0010

1.2.5.5 N i ma tr n

1.3:

a = ones(3, 3);

b = 5*ones(3, 3);

c = [a+2; b]
11
BÀI

c=

333

333

333

555

555

555

1.2.5.6 Xoá hàng và c t

xoá hàng .

b =[5 5 5;5 5 5;5 5 5];

b(:, 2) = [] ;

b=

55

55

55

b(1:2:5) = [

1.2.5.7 Các l nh x lý ma tr n

:X=A+B

:X=A-B

Nhân: X = A*B

cùng kíc

Chia: X = * inv(B)

X = A\ X = inv(A) * B
12
BÀI

: X = A^2

X = A.^2

X = inv(A)

d = det(A)

1.2.6 a th c

ng các vector hàng


vector chính
m = s4-s3+4s2-5s-

m=[1 -1 4 -5 -1]

c, ta dùng .V
2:

polyval(m,2)

roots(m)

1.2.7 L p trình trong MatLab

1.2.7.1 Các phát bi u ki n if, else, elseif:

end

N if

else và elseif

1.4:

disp Han hanh d ); %X màn hình

x = fix(30*rand);
13
BÀI

disp

g = input( Xin nhap tuoi cua ban

if g < x

disp( Ban );

elseif g > x

disp( Ban );

else

disp( Ban bang tuoi );

end

1.2.7.2 Switch

Cú pháp u:

case n1

case n2

...............
case nn

Otherwise

end

1.2.7.3 While

end
14
BÀI

1.5: chuoi Xin chao

disp( );

g = input(

i = 0;

while i~=g

disp( );

i = i+1

end

1.2.7.4 For

ùng

: :

1.6:

x = fix(100*rand);

n = 7;

t = 1;

for k = 1:1:7

num = int2str(n); % ên thành string

disp( );

disp doan nam trong khoang

0 g = input( ma ban doan

if g < x

disp( );

elseif g>x

disp( o );

else

disp( n dung.Xin chuc mu );


BÀI 1
t = 0;
break;
end
n = n 1;
end
if t > 0
disp( );
numx = int2str(x);
disp( : );
end

1.2.7.5 Break

hay while
k

1.2.8 Các file và hàm

1.2.8.1 Script file

Script là m file

f = [1 1];
i = 1;
while(f(i)+f(i+1))<1000
f(i + 2)= f(i) +f(i+1);
i = i + 1;
end

plot(f)

editor file tên là fibo.m


script file trong file fibo.m

>>fibo và .
16 BÀI 1: B

1.2.8.2 Hàm

Hàm là m-file

function y = tb(x)

%Tinh tri trung binh cua cac phan tu


[m,n] = size(x);
if m == 1
m = n;
end
y = sum(x)/m;

- g function y = tb(x
y, tên hàm tb

- MATLAB.

- .

. Tên

hàm là tb thì tên file tb.m

ATLAB ta gõ l :

z = 1:99;
tb(z)

global.

ngõ vào và ngõ ra thì khai b


function [y1,y2,y3] = tb(x1,x2,x3)

file.m
file.
BÀI 1
1.2.8.3 u khi n vào và ra

disp

a = [1 2 3];

disp(a)

123

disp(t)

Xin chao

format % short

format short % 5 digit

format long % 15 digit

format short e % 5 digit +

format long e % 15 digit +

format hex %

format + % , - và blank

input

x = input( : )

Cho tri cua bien x:4 x

=4

1.2.8.4 Các hàm toán h n:

exp(x) (ex)

sqrt

log(x) logarit

log10(x) logarit

abs(x) module
1 BÀI

angle(x) argument

conj

imag(x)

real(x)

sign

cos(x) tính cos

sin(x) tính sin

tan(x) tính tang

acos(x) tính cos-1

asin(x) tính sin-1

atan(x) tính tang-1

cosh(x) tính (e^x+e^(-x))/2

coth(x) tính cosh(x)/sinh(x)

sinh(x) tính (e^x-e^(-x))/2

tanh(x) tính sinh(x)/cosh(x)

acosh(x) tính cosh-1

acoth(x) tính coth-1

asinh(x) tính sinh-1

atanh(x) tính tanh-1

1.2.8.5 Các phép toán trên hàm toán h c

-
fil
e

file ab.m

function y = ab(x)
BÀI 1
y = 2./(x + 1) + 1./(x.^2 + 2) 1 ;

Các
inline

f = inline

x=

f(2)

ans =

0.833333333333333

1.7:

fplot(@(x)[tan(x),sin(x),cos(x)], 2*pi*[-1 1 -1 1])

Hình 1.4:
:

0.3).^2+0.01)+1./(x.^2+0.04) 6 );
x = fminbnd(f,0.3,1)
2 BÀI

x = 0.999943561455580

1.8: Ta có hàm three_var.m:

function b = three_var(v)

x = v(1);

y = v(2);

z = v(3);

b = x.^2 + 2.5*sin(y) z^2*x^2*y^2;

-0.6, y = -1.2 và z =
0.135:

v = [-0.6 -1.2 0.135];

a = 0.0000 1.5708 0.1803

i m

1.9: T - :

0.3).^2+0.01)+1./(x.^2+0.04)

a = fzero(f,-0.2)

a = -0.443585269991057

1.3 HO
1.3.1 Các l nh v

MATLA

plot: -

plot3: -

loglog: g logarit
21
BÀI

semilogx:

semilogy:

polar

1.3.2 T o hình v

vector thì

t = [0:pi/100:2*pi];

y = sin(t);

->2

1.3.3 Ki ng v

t = [0:pi/100:2*pi];

y = sin(t);

LineWidth

MarkerEdgeColor c

MarkerFaceColor

MarkerSize

r: red m magenta g: green y: yellow

b: blue k: black c: cyan w: white

- g --

-
22
BÀI

o vòng tròn

s hình
vuông
< tam giác sang trái

1.10:

x = -pi: pi/10: pi; y = tan(sin(x)) - sin(tan(x));

hold on

Hình 1.5: sin(tan(x))

1.3.4 V v i hai tr c y


23
BÀI

1.11:

Hình 1.6
t = 0:900; A = 1000;b = 0.005;a = 0.005;z2 = sin(b*t);

z1 = A*exp(-a*t);

1.3.5 V ng cong 3D

t = 0:pi/50:10*pi;

plot3(sin(t),cos(t),t)

Hình 1.7:
24
BÀI

1.3.6 V nhi u tr c to

Hình 1.8:

subplot(2,3,5) %

1.12:

x=linspace(0,2*pi);

y1=sin(x); y2=cos(x); y3=2*exp(-x).*sin(x);

x1=linspace(-2*pi,2*pi); y4=sinc(x1);

subplot

\pi x \over \pi


x}$$','interpreter','latex');
25
BÀI

Hình 1.9:

1.3.7 t các thông s cho tr c

heo

1.3.8 Gi i h n c a tr c và chia v ch trên tr c

axis[xmin , xmax , ymin , ymax]

x = 0:0.025:pi/2;

;
26
BÀI

axis([0 pi/2 0 5]);

1.13:

x = -pi:.1:pi; y = sin(x);

plot(x,y)

pi:pi/2:p);

1.3.9 Ghi nhãn lên các tr c to

zlabel t

x = -pi:.1:pi; y = sin(x);

plot(x,y);

\ ;

title( \it{G ;

t k
27
BÀI

1.14: V t = 0.005:

t = 0:900;

plot(t,0.25*exp( 0.005*t))

text(300,.25*exp( .005*300), \bullet\leftarrow \fontname{times} 0.25{\


ite}^{ 0.005{\itt}} at, {\

gf

\bf

\it nghiêng

\fontname{fontname} .

\fontsize{fontsize} .

\color(colorSpec)
28
BÀI

title('\ite^{i\omega_0\tau} = cos(\omega_0\tau) + i sin( \omega_0

\tau)').

1.15:

text('position',[.2.5], 'fontsize',14, 'interpreter', 'latex', 'string'


, ['$$\hbox {magic(3) is } \left( {\matrix{ 8 & 1 & 6 \cr 3 & 5 & 7 \cr
4 & 9 & 2 } } \right)$$']);

text('position',[.2.3], 'fontsize',14, 'interpreter','latex', 'string', ['$


$\left[ {\matrix{\cos(\phi) & -\sin(\phi) \cr \sin(\phi) & \cos(\phi)
\cr}} \right] \left[ \matrix{x \cr y} \right]$$']);

text('position',[.2.1],'fontsize',14, 'interpreter','latex', 'string'


,['$$L\{f(t)\} \equiv F(s) = \int_0^\infty\!\!{e^{-st}f(t)dt}$$']);

text('position',[.5.5],'fontsize',14, 'interpreter','latex', 'st ring',


'$$e = \sum_{k=0}^\infty {1 \over {k!} } $$');

text('position',[.5.3],'fontsize',14, 'interpreter','latex', 'string',


['$$m \ddot y = -m g + C_D \cdot {1 \over 2}\rho {\dot y}^2 \cdot A$
$']);

text('position',[.5.1],'fontsize',14, 'interpreter','latex', 'string',


'$$\int_{0}^{\infty} x^2 e^{-x^2} dx = \frac{\sqrt{\pi}}{4}$$');
29
BÀI

Hình 1.10

-project.org/

1.3.10 ho c bi t:
a.

bar

barh
ngang.

bar3

3D.

bar3h
30
BÀI

1.16:

y = [5 2 1;6 7 3;8 6 3;5 5 5;1 5 8];

subplot(211);bar(y);

subplot(212);bar3(y);

Hình 1.11:

b.

1.17:

TCE = [515 420 370 250 135 120 60 20];

nhdo = [29 23 27 25 20 23 23 27];

ngay = 0:5:35;

bar(ngay,nhdo);

; ;
31
BÀI

Hình 1.12:
trí
:

h1 = gca;

plot(ngay

sL

c. g:
32
BÀI

y = [5 2 1;6 7 3;8 6 3;5 5 5;1 5 8];

area(Y)

Hình 1.13:
d.

. 2D và 3D.

x = [19.3 22.1 51.6;34.2 70.3 82.4;61.4 82.9 90.8;50.5 54.9 59.1;29.4


36.3 47.0];

x1 = sum(x); explode = zeros(size(x1));

[c,offset] = max(x1); explode(offset) = 1;

subplot(221);pie(x1,explode);

subplot(222);pie3(x1,explode);

Hình 1.14:
33
BÀI

e.

- D
hình.

- D

- D ình.

1.18:

T mv.m

axis equal

M = moviein(16,gcf);

1,

for j = 1:16

plot(fft(eye(j + 16))); ;

M(:,j) = getframe(gcf);

end

clf;

movie(M,30)

:
34
BÀI

Ví 1.19: -file có tên là mv1.m :

t = linspace(0,2*pi,10000); y = exp(sin(t));

h = plot(t,y);

for k = 1:0.01:10

y = exp(sin(t.*k));

h.YData = y;

drawnow

end

1.3.11 ho 3D

a.

b.

[x,y] = meshgrid(-8:.5:8);

r = sqrt(x.^2 + y.^2);
35
BÀI

z = sin(r)./r;mesh(z)

0.5

-0.5
40
30 40
20 30
20
1 10
0 0

Hình 1.15:
36
BÀI

Trong bà

CÂU H
Câu 1: :

a.

b.

c.
sum(A(:,1))).

d. ng các

Câu 2: ;
sau:

a. A'

b. A(:,[1 4])

c. A([2 3],[3 1])

d. reshape(A,2,6)

e. A(:)

f. [A A(end,:)]

g. A(1:3,:)

h. [A ; A(1:2,:)]

i. sum(A)

j. sum(A')
37
BÀI

k. [ [ A ; sum(A) ] [ sum(A,2) ; sum(A(:)) ] ]

Câu 3: c

a. x(3)

b. x(1:7)

c. x(1:end)

d. x(1:end-1)

e. x(6:-2:1)

f. x([1 6 2 1 1])

g. sum(x)

Câu 4:

Câu 5: ) + 3cos( ).

Câu 6: 2x2 + y2 = 10

Câu 7: Dùng hàm tex

Câu 8: dùng hàm surf và mesh.


38
BÀI

Câu 9:

Máy A Máy B
1996 38 48
1997 33 54
1998 36 120
1999 31 92
2000 60 110
2001 70 131
Câu 10:

Câu 11:

không
-GUI (GRAPHIC USER INTERFACE) 39
BÀI

BÀI 2: G -GUI
(GRAPHIC USER INTERFACE)

- .

- .

2.1 T O GUI
K New > App > GUIDE

Hình 2.1:
40
BÀI -GUI (GRAPHIC USER

guide

Blank GUI.

Hình 2.2: a UI Quick Start

Hình 2.3:
-GUI (GRAPHIC USER INTERFACE) 41
BÀI

2.2 HO

Push Button Slider

Radio Button Check box

Edit Text Static Text

Pop-up
List box

Toggle Button
Table

Axes
Panel

Button Group
ActiveX

Hình 2.4: Danh

Radio Button: dùng

Pop-up Menu: h -up.


42
BÀI -GUI (GRAPHIC USER

dùng

Tool > Align Objects).

Hình 2.5: Côn

View > Property Inspector).

Hình 2.6:
-GUI (GRAPHIC USER INTERFACE) 43
BÀI

chú ý:

String

Tag

FontName

FontSize: kích

Unit alized.

Value -menu, List Box, Radio


Button, Check Box, Slider.

Callback .m

2.3 T O MENU
Tools > Menu Editor.

Hình 2.7:
44
BÀI -GUI (GRAPHIC USER

NewMenuItem:

hành

Move Selected

trím phân khác

Xoá menu

Hình 2.8:

file. View > M-file Editor.

Callback c

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject handle to radiobutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1

function mnuTool_Callback(hObject, eventdata, handles)

% hObject handle to mnuTool (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)


-GUI (GRAPHIC USER INTERFACE) 45
BÀI

pushbutton1, mnuTool
( 2.2 và

2.3)

end

2.5 VÍ D T O GUI

Hình 2.9:

Button String: Convert


Tag: pushbuttonConvert

3 Radio Button String: Celcius, Rankine, Kelvin


Value: 1.0, 0.0, 0.0
Tag: radiobuttonC, radiobuttonR, radiobuttonK

Static text String: Fahrenheit degree

Static text String: Celcius degree


Tag: text2
46
BÀI -GUI (GRAPHIC USER

Slider Max: 9032


Min: -459.4
SliderStep: [0.001 0.1]
Tag: SliderDoF
Value: 32

Edit text String: 32


Tag: editDoF

Edit text String: 0


Tag: editKQ

% --- Executes on button press in pushbuttonConvert.

function pushbuttonConvert_Callback(hObject, eventdata, handles)

% hObject handle to pushbuttonConvert (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

doF = str2num(get(handles.editDoF,'String'));

if get(handles.radiobuttonC,'Value') == 1

% Chuyen oC

set(handles.editKQ,'String',num2str((doF-32)*5/9));

elseif get(handles.radiobuttonR,'Value') == 1

%Chuyen oR

set(handles.editKQ,'String',doF+459.7);

else

%Chuyen oK

set(handles.editKQ,'String',(doF-32)*5/9+273.15);

end
-GUI (GRAPHIC USER INTERFACE) 47
BÀI

% --- Executes on button press in radiobuttonC.

function radiobuttonC_Callback(hObject, eventdata, handles)

% hObject handle to radiobuttonC (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobuttonC

set(handles.radiobuttonK,'Value',0);

set(handles.radiobuttonR,'Value',0);

set(handles.text2,'String','Celcius degree');

% --- Executes on button press in radiobuttonR.

function radiobuttonR_Callback(hObject, eventdata, handles)

% hObject handle to radiobuttonR (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobuttonR

set(handles.radiobuttonC,'Value',0);

set(handles.radiobuttonK,'Value',0);

set(handles.text2,'String','Rankine degree');

% --- Executes on button press in radiobuttonK.

function radiobuttonK_Callback(hObject, eventdata, handles)

% hObject handle to radiobuttonK (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobuttonK

set(handles.radiobuttonR,'Value',0);

set(handles.radiobuttonC,'Value',0);
48
BÀI -GUI (GRAPHIC USER

set(handles.text2,'String','Kelvin degree');

% --- Executes on slider movement.

function sliderDoF_Callback(hObject, eventdata, handles)

% hObject handle to sliderDoF (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider

% get(hObject,'Min') and get(hObject,'Max') to determine range of


slider

set(handles.editDoF,'String',get(handles.sliderDoF,'Value'));
-GUI (GRAPHIC USER INTERFACE) 49
BÀI

Câu 1:

Draw

Sin

Sinc

Cos

Exit
View

2D ( 2))

3D ( )

Zoom Fill ( )

Zoom Out ( )
Help

About

-
-
-
50
BÀI -GUI (GRAPHIC USER

Câu 2:

Static Text:

String: Amplitude

Edit Text:

String: 5

Tag: editAmp

Static Text:

String: Frequency

Edit Text:

String: 10

Tag: editFreq

Static Text:

String: Function

Pop-up Menu:

String: cos

sin

sinc

Tag: popupmenuFunc

Button:

String: Draw

Tag: pushbuttonDraw

Axes:

NextPlot: replacechildren

XGrid: on

YGrid: on
BÀI 2: GIA -GUI (GRAPHIC USER INTERFACE) 51
ZGrid: on

Tag: axes1

Câu 3:
52
BÀI 3:

BÀI 3: SYMBOLIC

Khi

syms bien_1 bien_2

Tên hàm

syms
sym
diff
simplify
int Tích phân
subs
factor
expand
ezplot
limit Tìm g
findsyms
pretty
collect
solve
dsolve
laplace
BÀI 3: SYMBOLIC 53

Tên hàm
ilaplace
fourier
ifourier
finverse

3.1 O HÀM VÀ VI PHÂN


h

syms x
y=diff(cos(x))
y=
-sin(x)
diff('x^3+3*x^2+2*x-
ans =
6*x + 6
y = diff('x/(1+x^3)')
y=
1/(x^3 + 1) - (3*x^3)/(x^3 + 1)^2
simplify(y)
ans =
-(2*x^3 - 1)/(x^3 + 1)^2
syms m
z = 2*sin(x) + m^2*cos(x)% z là hàm s theo x,m
diff(z,m,2)
ans =
2*cos(x)
diff(z,x,3)
ans =
sin(x)*m^2 - 2*cos(x)
54
BÀI 3:

3.2 TÍCH PHÂN

y=
atan(x)

do hà
y=
int(log(x)/exp(x^2), x)

y=
¼
y=int(x^3*atan(x),0,pi/4)
y=
pi/16 - atan(pi/4)/4 + (pi^4*atan(pi/4))/1024 - pi^3/768

eval(y)

ans = 0.0529

dùng hàm quad tính tích


.

y = inline('log(x)./exp(x.^2)');

quad(y,0,1)

ans =

-0.9059

3.3 C
.

finverse(1/x)
ans =
1/x
BÀI 3: SYMBOLIC 55

finverse(a*x+b)
ans =
-(b - x)/a

Warning: finverse(x^2) is not unique.


ans =
x^(1/2)

3.4 V TH

syms x

subplot(211);ezplot(sin(x)/x)

subplot(212);ezplot(sin(x)/x,0,4*pi)

Hình 3.1:

ezsurf('x*exp(-x^2 - y^2)')
56
BÀI 3:

Hình 3.2 dùng ezplot

3.5
syms s
y=int('sin(s+2*x)','s',pi/2,pi)
y=
cos(2*x) - sin(2*x)
pretty(y)
cos(2 x) - sin(2 x)

f = sym('x^2-1');
factor(f)
ans =
(x - 1)*(x + 1)
y=expand((x+1)^3-2*(x-1)^2)
y=
x^3 + x^2 + 7*x - 1

y=simplify(sin(x)^2+cos(x)^2)
BÀI 3: SYMBOLIC 57

y=
1
y=simplify((1-x^2)/(1-x))
y=
x+1
simplify((1/x^3+6/x^2+12/x+8)^(1/3))
ans =
((2*x + 1)^3/x^3)^(1/3)

Dùn
vi

phân.

y=solve(x^3+2*x^2+1==0)
y=
root(z^3 + 2*z^2 + 1, z, 1)
root(z^3 + 2*z^2 + 1, z, 2)
root(z^3 + 2*z^2 + 1, z, 3)
i

y=vpa(y)

y=
-2.2055694304005903117020286177838
0.10278471520029515585101430889191 - 0.66545695115281347670619061162908i
0.10278471520029515585101430889191 + 0.66545695115281347670619061162908i

eval(y)
ans =
-2.2056 + 0.0000i
0.1028 - 0.6655i
0.1028 + 0.6655i
58
BÀI 3:

syms x1 x2 x3
[y1,y2,y3]=solve(2*x1+3*x2-2*x3==1,x1-x2+3*x3==2,x2-2*x3==4)

y1 =
35/2

y2 =
-19

y3 =
-23/2
[y1,y2,y3]=solve(2*x1+3*x2-2*x3==1,x1-x2+3*x3==2,x2^2-2*x3==4)

y1 =
(7*329^(1/2))/64 + 21/64
21/64 - (7*329^(1/2))/64
y2 =
5/8 - 329^(1/2)/8
329^(1/2)/8 + 5/8
y3 =
49/64 - (5*329^(1/2))/64
(5*329^(1/2))/64 + 49/64

eval([y1 y2 y3])
ans =
2.3120 -1.6423 -0.6514
-1.6558 2.8923 2.1827
syms x y
[x1,x2]=solve(x^2+x*y+y==1,x^2-4*y==3)
x1 =
-1
BÀI 3: SYMBOLIC 59

- 11^(1/2) - 2
11^(1/2) - 2
x2 =
-1/2
11^(1/2) + 3
3 - 11^(1/2)
eval(x1)
ans =
-1.0000
-5.3166
1.3166
eval(x2)
ans =

-0.5000
6.3166
-0.3166

giác:
solve(2*cos(x)+2)
ans =
pi

solve(2*cos(x))
ans =
pi/2
solve(cos(x)=sin(x))
ans =
pi/4
y=solve(exp(x)==tan(x))
y=
-226.19467105846511316931032359612
60
BÀI 3:

y=dsolve('Dy=y*tan(x)+cos(x)',x)
y=
(x/2 + sin(2*x)/4)/cos(x) + C4/cos(x)
y = simplify(y)
y=
(4*C4 + 2*x + sin(2*x))/(4*cos(x))
pretty(y)
4 C4 + 2 x + sin(2 x)

4 cos(x)

y=dsolve('Dy=1+y^2','y(0)=1','x')

y=

tan(pi/4 + x)

y=dsolve('D2y=cos(2*x)-

y=

(5*cos(x))/3 + sin(x) + sin(x)*(sin(x) - (8*tan(x/2)^2*sin(x))/(3*(tan(x/2)^2 + 1)^2)) -


(2*cos(x)*(- 3*tan(x/2)^4 + 6*tan(x/2)^2 + 1))/(3*(tan(x/2)^2 + 1)^3)

y= simplify(y)

y=

(2*tan(x/2)^3 + (16*tan(x/2)^2)/3 + 2*tan(x/2) + 8/3)/(tan(x/2)^2 + 1)^2 - 5/3

pretty(y)

/ x \4

cos| - | 8

8 cos(x) \2/
+ sin(x) - +1
3 3
BÀI 3: SYMBOLIC 61

[f,s] = dsolve ('Dz=3*z+4*y', 'Dy=-4*z+3*y' ,

f=

cos(4*x)*exp(3*x)

s=

sin(4*x)*exp(3*x)

3.7 TÌM GII H N

syms x a t h

y=limit(sin(x)/x) % x 0

y=

y=limit(sin(x)/x,inf) % x

y=

ans =

Inf

ans =

-Inf

limit((sin(x+h)-sin(x))/h,h,0)

ans =

cos(x)
62
BÀI 3:

Câu 1: 3

Câu 2: Tính tích phân:

Câu 3:

Câu 4: V

Câu 5:

Câu 6:
BÀI 4: SIMULINK 63

BÀI 4: SIMULINK

Simulink.

Hình 4.1:

Hình 4.2: Simulink

Blank Model
64
BÀI 4:

Hình 4.3: link

Library Browser Simulink Library Browser.

Hình 4.4:
BÀI 4: SIMULINK 65

4.1 V SIMULINK
4.1.1
Các kh i

-
66
BÀI 4:

- ình.

- Tag: tr

l.

- 0.

- 0.

-
BÀI 4: SIMULINK 67

Show Names.

-
.

-
68
BÀI 4:

4.1.2
n kh i

nu

: untitled.

menu Edit.

4.1.3
ng

-
BÀI 4: SIMULINK 69

- phân nhánh

4.1.4
Ghi chú


70
BÀI 4:

4.1.5
Làm vi c v i các lo i d li u

double

single

int8

uint8

int16

uint16

int32

uint32

t tín

-
BÀI 4: SIMULINK 71

4.1.6
Làm vi c v i tín hi u ph c

4.1.7
T o h th ng con

Khi mô hì

g con này vào:

- ình.

-
ra.

-
72
BÀI 4:

4.2 MÔ HÌNH HOÁ

4.2.1
Mô hình hoá m
Ph :

F = (9/5)C + 32

Tr ình:

- Ramp trong th Sources .

- Constant Sources .

- Gain Math .

- Sum Math .

- Scope Sinks

Gain và

Constant

Ramp
gán Initial output Gain i Sum
Scope
BÀI 4: SIMULINK 73

Hình 4.5:

Run
Scope.

Hình 4.6:
74
BÀI 4:

4.2.2
Mô hình hoá h n tính

ph

- Algebric Constraint trong th Math ình

- Add trong th Math

- Display Sink

- Constant t Sources

Hình 4.7:

4.2.3
Gi i c cao:

Xét ph

ình: x2 + 3x + 1

=0
BÀI 4: SIMULINK 75

- Algebric Constraint trong th Math ình

- Display trong th Sink

- Constant Sources

- Add Math

- Math Function trong th Math 2

- Gain trong th Math

Hình 4.8:

4.2.4
Mô hình hoá h th ng liên t n

ình vi phân:
76
BÀI 4:

- Gain trong th Math

- Sum Math

- Scope Sink

- Signal Generator trong th Sources

- Integrator trong th Continuous

Hình 4.9:

4.2.5
Mô hình hoá h c cao

x''(t) + 3x'(t) +2x(t) = 4u(t)

p2X(p) + 3pX(p) + 2X(p) = 4U(p)


BÀI 4: SIMULINK 77

- Step trong th Sources

- Transfer Fcn trong th Continuous n

- Scope Sink

Hình 4.10:

4.2.6
Mô hình hoá h u ki u khác không

a. Ph ìn ình:

x'(t) + x(t) = 0

Nh -1 ; C = 1 ; u = 0 ; B = 0, D = 0 và Init = 1

- State-Space Continuous.

- Scope trong th Sink


78
BÀI 4:

u:

Hình 4.11:

b. tr ình:

x''(t) + 3x'(t) +2x(t) = 4u(t)

-2 và x(0) = 1.

1 = x , x2 1(0) = 1 và x2(0) = -2.

Ngoài ra: x2' = x1'' = x''.

x2'(t) + 3x2(t) + 2x1(t) = 4u(t)

Ph

- State-Space trong th Continuous


BÀI 4: SIMULINK 79

- Scope trong th Sink

4.2.7
Mô hình hóa h cho b kh i

n sau:

Hình 4.12:

Ta mô

- Step trong th Sources

- Gain trong th Math

- Transfer Fcn trong th ous

Hình 4.13:

4.2.8
Mô hình hoá h phi tuy n

a. X Pol:

2 =0

1 2 y1(0) = 2 và y2
80
BÀI 4:

- Fcn trong th User Defined Function o hàm.

- Product trong th Math .

- Integrator trong th n Continuous

- Sum trong th Math

- Mux trong th Signal Routing

- Scope trong th Sink

Hình 4.14: Val der Pol


Double- 1(0) = 2.

b. X vi phân sau:

1(0) = a2(0) = 1.3

- Integrator trong th Continuous

- Fcn trong th User Defined Function

- Gain trong th Math


BÀI 4: SIMULINK 81

- Scope trong th Sink

- Sum trong th Math

Hình 4.15:
Double-
là 1.3.

4.2.9
Ví d

m
f u

mv' = u bv hay v' = (u bv)/m

k intergrator
Continuous.
82
BÀI 4:

v = v1dt v1 = v'.

Gain Math

Sum trong th
Math
-
Gain

Step Sources gõ ra
Scope Sinks
BÀI 4: SIMULINK 83

Simulation > Configuration Parameters.

Start
Simulation > Start

msV(s) = U(s) bV(s)

Transfer Fcn Continuous


Step n Sources Scope Sinks

Transfer Fcn Denominator coefficients thành [m b].


84
BÀI 4:

-b/m; B = 1/m; C = 1; D = 0.

State-Space Continuous
Step Sources Scope Sinks
State-Space và

TÓM T
Trong bài này

Câu 1:

b=0

K = Kt =

Ke
BÀI 4: SIMULINK 85

Câu 2: :

M1

M2

x1 , x2

Câu 3:
86
BÀI 4:

m1

m2

K1 )

K2 =

b1

b2

x1 , x2
87
BÀI

BÀI 5:

Sa g bài n

5.1 COMMUNICATION
Communication toolbox

n thông. Toolbox
,
mô hình
Communication toolbox

- Các k

- Hàm MatLab

Toolbox này h
-

5.1.1 Hàm

5.1.1.1
Ngu n d li u, hi n th tín hi u

eyediagram:

5.1:

Fs = 10000; Rs = 100;
88 BÀI 5:

nSamps = Fs/Rs;
rolloff = 0.5; M = 4;
qpskMod = comm.QPSKModulator; u ch QPSK
rctFilt = comm.RaisedCosineTransmitFilter('RolloffFactor', rolloff,
'OutputSamplesPerSymbol', nSamps,'FilterSpanInSymbols', 6, 'Gain',
9.9121);
rcrFilt = comm.RaisedCosineReceiveFilter('RolloffFactor', rolloff,
'InputSamplesPerSymbol', nSamps,'FilterSpanInSymbols', 6,
'DecimationFactor', 1, 'Gain', 0.1009);
% T o tín hi u ch
frameLen = 1000; msgData = randi([0 M-1],frameLen,1);
msgSymbols = qpskMod(msgData); msgTx = rctFilt(msgSymbols);
% T o gi m t
eyeObj = commscope.eyediagram('SamplingFrequency', Fs,
'SamplesPerSymbol', nSamps, 'OperationMode', 'Complex
Signal','PlotType', '2D Line');
update(eyeObj, 0.5*msgTx);

Hình 5.1:

scatterplot
89
BÀI

5.2 u 64-QAM

d = (0:63)';

s = qammod(d,64);

scatterplot(s)

Hình 5.2: -QAM

biterr

randi

symerr tí i và SER

wgn

comm.GoldSequence

comm.HadamardCode

comm.KasamiSequence

comm.BarkerCode

comm.WalshCode

comm.PNSequence
90
BÀI 5: CÁC T

5.1.1.2
Mã hóa ngu n

compand:

5.3:

data = 2:2:12

mu_c = compand(data,255,max(data),'mu/compressor') % Mã hóa lu t

mu_e = compand(mu_c,255,max(data),'mu/expander') % Gi i mã lu t

a_c = compand(data,87.6,max(data),'a/compressor') % Mã hóa lu t A

a_e = compand(a_c,87.6,max(data),'a/expander')% Gi i mã lu t A

data = 2 4 6 8 10 12

mu_c = 8.1644 9.6394 10.5084 11.1268 11.6071 12.0000

mu_e = 2.0000 4.0000 6.0000 8.0000 10.0000 12.0000

a_c = 8.0713 9.5911 10.4802 11.1109 11.6002 12.0000

a_e = 2.0000 4.0000 6.0000 8.0000 10.0000 12.0000

dpcmdeco

dpcmenco Mã hóa PCM vi phân

dpcmopt

5.4

predictor = [0 1]; % y(k)=x(k-1)

partition = [-1:.1:.9];

codebook = [-1:.1:1];

t = [0:pi/50:2*pi];

x = sawtooth(3*t); % Tín hi u g c

% ng t dùng DPCM.

encodedx = dpcmenco(x,codebook,partition,predictor);

decodedx = dpcmdeco(encodedx,codebook,predictor); % Khôi ph c


91
BÀI

plot(t,x,t,decodedx,'--')

legend('Original signal','Decoded signal','Location','NorthOutside');

distor = sum((x-decodedx).^2)/length(x)% L

Hình 5.3:

distor = 0.0327

5.5: So sánh

t = [0:pi/50:2*pi];

x = sawtooth(3*t); %

initcodebook = [-1:.1:1];

[predictor,codebook,partition] = dpcmopt(x,1,initcodebook);

% DPCM.

encodedx = dpcmenco(x,codebook,partition,predictor);

decodedx = dpcmdeco(encodedx,codebook,predictor);

distor = sum((x-decodedx).^2)/length(x)
92
BÀI

distor = 8.6801e-04
5.4.

huffmandict

huffmanenco Mã hóa Huffman

huffmandeco

5.6

symbols = 1:6;

p = [.5.125.125.125.0625.0625];

dict = huffmandict(symbols,p);

sig = randsrc(100,1,[symbols; p]);% T o d li u ng u nhiên

comp = huffmanenco(sig,dict); % Mã hóa Huffman

dsig = huffmandeco(comp,dict); % Gi i mã

isequal(sig,dsig) % Ki m tra d li u sau khi gi i mã

binarySig = de2bi(sig);

seqLen = numel(binarySig)% Chi u dài chu i không mã hóa Huffman

binaryComp = de2bi(comp);

encodedLen = numel(binaryComp)% Chi u dài chu i mã hóa Huffman

ans =

logical

seqLen =

300

encodedLen =

208

lloyds g dùng th
93
BÀI

quantiz

5.1.1.3
Phát hi n và s a sai

1. Mã CRC

comm.CRCDetector:

comm.CRCGenerator:

5.7:

msg = randi([0 1],12,1); % T p ng u nhiên

gen = comm.CRCGenerator([1 0 0 1],'ChecksumsPerFrame',2);

codeword = step(gen,msg); % Thêm mã CRC

detect = comm.CRCDetector([1 0 0 1],'ChecksumsPerFrame',2); %

[~, err] = step(detect,codeword) % Gi i mã và ki m tra

codeword(end) = not(codeword(end)); % Gi l p 1 l i bit cu i

[~,err1] = step(detect,codeword) % Ki m tra l i

err =

err1 =

2. Mã

comm.BCHDecoder

comm.BCHEncoder: mã hóa BCH

comm.RSDecoder -

Solomon comm.RSEncoder: mã hóa Reed -

Solomon
94
BÀI

cyclgen

cyclpoly

decode

encode

gfweight

gen2par

hammgen

bchdec

bchenc: mã hóa BCH

bchgenpoly

bchnumerr mã BCH

rsdec: ã Reed - Solomon

rsenc: mã hóa Reed - Solomon

rsgenpoly -Solomon

rsgenpolycoeffs -Solomon

5.8: i cho mã vòng

n = 7; % Chi u dài mã
k = 4; % Chi p
data = randi([0 1],k,1) % Th p ng u nhiên
pol = cyclpoly(n,k);% T o ma tr n sinh và ma tr n ki m tra cho mã vòng
parmat = cyclgen(n,pol);
genmat = gen2par(parmat);
encData = encode(data,n,k,'linear/binary',genmat);
RevData1 = encData; % D li u không sai
decData1 = decode(RevData1,n,k,'linear/binary',genmat)
RevData2 = encData;
RevData2(3) = ~RevData2(3); % Sai 1 bit
95
BÀI
decData2 = decode(RevData2,n,k,'linear/binary',genmat)
96BÀI 5: CÁC TOOLBOX
BÀI
95
S2 = RevData2'*parmat';S2 = mod(S2,2) % Vector s a sai

RevData3 = encData;
RevData3(2) = ~RevData3(2); % Sai 2 bit
RevData3(1) = ~RevData3(1);
decData3 = decode(RevData3,n,k,'linear/binary',genmat)
S3 = RevData3'*parmat';S3 = mod(S3,2) % Vector s a sai

data = 1 1 0 1

decData1 = 1 1 0 1

decData2 = 1 1 0 1

S2 = 0 0 1

decData3 = 1 1 1 1

S3 = 1 1 0

3. Mã

comm.TurboDecoder

comm.TurboEncoder: mã hóa Turbo

comm.ViterbiDecoder

rbi convenc: Mã hóa c

distspec

vitdec

Viterbi

5.9

t = poly2trellis([4 3],[4 5 17;7 4 2]); % T i cho mã ch


p x = randi([0 1],100,1);
code = convenc(x,t);
decoded = vitdec(code,t,2,'trunc','hard');
biterr(x,decoded) % Ki m tra sai s

5.10 -QAM trong


à không mã hóa.
96
BÀI

M = 64; % 64-QAM
k = log2(M);
EbNoVec = (4:10)'; % Eb/No (dB)
numSymPerFrame = 1000; % S symbol QAM symbols trên 1 frame
berEstSoft = zeros(size(EbNoVec)); % Kh i t ng BER
berEstHard = zeros(size(EbNoVec));
trellis = poly2trellis(7,[171 133]); % T i và chi u dài
tbl = 32;
rate = 1/2;
for n = 1:length(EbNoVec)
snrdB = EbNoVec(n) + 10*log10(k*rate); % Chuy n Eb/No sang SNR
[numErrsSoft,numErrsHard,numBits] = deal(0);
while numErrsSoft < 100 && numBits < 1e7
% T o d li u ng u nhiên
dataIn = randi([0 1],numSymPerFrame*k,1);
% Mã hóa d li u
dataEnc = convenc(dataIn,trellis);
% u ch QAM
txSig = qammod(dataEnc,M,'InputType','bit');
% hi u qua kênh truy n có
AWGN rxSig =
awgn(txSig,snrdB,'measured');
% Gi u ch
rxDataHard = qamdemod(rxSig,M,'OutputType','bit');
rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr',
'NoiseVariance',10.^(snrdB/10));
% Gi i mã Viterbi
dataHard = vitdec(rxDataHard,trellis,tbl,'cont','hard');
dataSoft = vitdec(rxDataSoft,trellis,tbl,'cont','unquant');
numErrsInFrameHard = biterr(dataIn(1:end-tbl),
dataHard(tbl+1:end));
numErrsInFrameSoft = biterr(dataIn(1:end-tbl),
dataSoft(tbl+1:end));
numErrsHard = numErrsHard + numErrsInFrameHard;
numErrsSoft = numErrsSoft + numErrsInFrameSoft;
97
BÀI

numBits = numBits + numSymPerFrame*k;


end
% ng BER
berEstSoft(n) = numErrsSoft/numBits;
berEstHard(n) = numErrsHard/numBits;
end

Hình 5.4

semilogy(EbNoVec,[berEstSoft berEstHard],'-*')
hold on
semilogy(EbNoVec,berawgn(EbNoVec,'qam',M))
legend('Soft','Hard','Uncoded','location','best')
grid
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')

5.1.1.4
u ch

1.

comm.GeneralQAMDemodulator ò

comm.GeneralQAMModulator

comm.PAMDemodulator -ary PAM


98
BÀI

comm.PAMModulator -ary PAM

comm.RectangularQAMDemodulator

comm.RectangularQAMModulator

comm.CPFSKDemodulator

comm.CPFSKModulator

comm.CPMDemodulator

comm.CPMModulator

comm.GMSKDemodulator

comm.GMSKModulator

comm.MSKDemodulator

comm.MSKModulator

comm.FSKDemodulator dùng M-ary FSK

comm.FSKModulator -ary FSK

comm.OFDMDemodulator

comm.OFDMModulator

comm.BPSKDemodulator

comm.BPSKModulator

comm.DBPSKDemodulator DBPSK

comm.DBPSKModulator

comm.DPSKDemodulator -ary

DPSK comm.DPSKModulator -ary DPSK

comm.DQPSKDemodulator

comm.DQPSKModulator
99
BÀI
comm.OQPSKDemodulator: g

comm.OQPSKModulator
100
BÀI

comm.PSKDemodulator -ary

PSK comm.PSKModulator -ary PSK

comm.QPSKDemodulator

comm.QPSKModulator

comm.GeneralQAMTCMDemodulator

comm.GeneralQAMTCMModulator

comm.PSKTCMDemodulator
chòm sao M-ary PSK

comm.PSKTCMModulator
sao M-ary PSK

comm.RectangularQAMTCMDemodulator

comm.RectangularQAMTCMModulator i

pamdemod

pammod

qamdemod

qammod

mskdemod

mskmod

fskdemod:

fskmod

dpskdemod

dpskmod
101
BÀI

oqpskdemod

oqpskmod

pskdemod

pskmod

5.11:

M = 8;
freqSep = 100;
fskMod = comm.FSKModulator(M,freqSep);
fskDemod = comm.FSKDemodulator(M,freqSep);
ch = comm.AWGNChannel('NoiseMethod','Signal to noise ratio
(SNR)','SNR',-2);
err = comm.ErrorRate;
for counter = 1:100
data = randi([0 M-1],50,1);
modSignal = step(fskMod,data);
noisySignal = step(ch,modSignal);
receivedData = step(fskDemod,noisySignal);
errorStats = step(err,data,receivedData);
end
es = 'Error rate = %4.2e\nNumber of errors = %d\nNumber of symbols =
%d\n';
fprintf(es,errorStats)

Error rate = 1.40e-02

Number of errors = 70

Number of symbols = 5000

2.

comm.FMDemodulator

comm.FMModulator

5.12:
102
BÀI

fs = 1e3;ts = 1/fs;fd = 50;


t = (0:ts:0.5-ts)';
x = sin(2*pi*4*t);
MOD = comm.FMModulator('SampleRate',fs,'FrequencyDeviation',fd);
y = step(MOD,x);
plot(t,[x real(y)]);

Hình 5.5: Tín h


3. thông

amdemod

ammod

fmdemod

fmmod

pmdemod

pmmod

ssbdemod
103
BÀI

ssbmod iên

5.13

fs = 100;
t = (0:1/fs:100)';
fc = 10;
x = sin(2*pi*t);
ydouble = ammod(x,fc,fs);
ysingle = ssbmod(x,fc,fs);
plot(ysingle);
sa = dsp.SpectrumAnalyzer('SampleRate',fs, 'PlotAsTwoSidedSpectrum',
false, 'YLimits',[-60 40]);
step(sa,ysingle)
plot(ydouble);
sb = dsp.SpectrumAnalyzer('SampleRate',fs,
'PlotAsTwoSidedSpectrum',false, 'YLimits',[-60 40]);
step(sb,ydouble)

Hình 5.6: Tí
104
BÀI

Hình 5.7:

5.1.1.5
Kênh truy n

comm.AWGNChannel: kênh AWGN

comm.RayleighChannel: kênh Rayleigh

comm.RicianChannel: kênh Rician

comm.MIMOChannel: kênh MIMO

comm.LTEMIMOChannel: kênh LTEMIMO

comm.MemorylessNonlinearity

comm.PhaseNoise

comm.ThermalNoise

5.14: 8-PSK qua kênh AWGN

pskModulator = comm.PSKModulator;
modData = pskModulator(randi([0 7],2000,1));
channel = comm.AWGNChannel('EbNo',20,'BitsPerSymbol',3);
channelOutput = channel(modData);
105
BÀI

scatterplot(modData)
scatterplot(channelOutput)

Hình 5.8: -

5.1.2 Simulink

Hình 4.4.

5.1.2.1
Ngu n d li u, hi n th tín hi u

Bernoulli Binary Generator

Poisson Integer Generator

Random Integer Generator

-1]

Barker Code Generator Barker

Gold Sequence Generator: Gold

Hadamard Code Generator

Kasami Sequence

Generator

OVSF Code Generator


106
BÀI
PN Sequence

Generator
107
BÀI

Walsh Code Generator:

Baseband File Reader

Baseband File Writer

Constellation Diagram

Eye Diagram
108
BÀI

Ví d 5.15

Hình 5.9:

5.1.2.2
Mã hóa ngu n

A-Law Compressor: nén

A-Law Expander

Differential

Decoder
109
BÀI

Differential Encoder

Mu-Law

Compressor

Mu-Law Expander: g µ

5.1.2.3
Phát hi n và s a sai

1. Mã CRC

CRC-N Generator

CRC-N

Syndrome Detector

General CRC Generator:

General CRC Generator HDL Optimized

General CRC Syndrome Detector


110
BÀI

General CRC Syndrome

Detector HDL Optimized:


108
BÀI

5.1

2. Mã
109
BÀI

3.

5.17 dù

,144
11 BÀI

5.1

,0 0018

5.1.2.4
u ch

1.

AM:
BÀI 11
CPM:

FM:

OFDM:

PM:

TCM:
112
BÀI

2.

5.19:

Hình 5.10:
113
BÀI

3. thông

5.20

Hình 5.11:
114
BÀI

5.1.2.5
Kênh truy n

5.21 fading Reyleigh và AWGN

Hình 5.12:
115
BÀI

5.1.3 Ví d

5.22: Mô ph

625 s nh sang t

Modulator và MFSK Modulator. G

Hình 5.13:
116
BÀI

Hình 5.14: -CPM Modulator

Hình 5.15: -FM Demodulator

Hình 5.16:

Hình 5.17:
117
BÀI

Hình 5.18: Phân tích

5.23 -B

máy bay -B dùng


Communication System Toolbox. T x
Communications System Toolbox Support Package for RTL-SDR
Radio này máy bay

ADS- õi máy bay. Côn y cho phép

mô hình -S. Mode- phát

m Mode 3A. Mode-S (Select

-S xem thêm trong International Civil Aviation


Organization, Annex 10, Volume 4. Surveillance and Collision Avoidance
Systems.

Mô hình -
trong các -S có

PPM
118
BÀI

s s

squitter s

sau: ng , dung

(CA), , CRC.

c -S có s,

s hình.

Hình 5.19: -S
userInput.Duration = 10;
userInput.FrontEndSampleRate = 2.4e6;
userInput.RadioAddress = '0';
userInput.LogFileName = 'adsb_messages.txt';

symbolDuration = 1e-6;
chipsPerSymbol = 2;
longPacketDuration = 112e-6;
shortPacketDuration = 56e-6;
preambleDuration = 8e-6;
% T o tín hi u ngu n
bbFileName = 'adsb_capture_01.bb';
sigSrc = comm.BasebandFileReader(bbFileName);
frontEndSampleRate = sigSrc.SampleRate;
adsbParam.isSourceRadio = false;
adsbParam.FrontEndSampleRate = frontEndSampleRate;
chipRate = chipsPerSymbol/symbolDuration;
[n,d]=rat(frontEndSampleRate/chipRate);
119
BÀI

if d>2
interpRate = d;
else
if n <= 1
interpRate = 2*d;
else
interpRate = d;
end
end
adsbParam.InterpolationFactor = interpRate;
sampleRate = frontEndSampleRate * interpRate;
adsbParam.SampleRate = sampleRate;
adsbParam.SamplesPerSymbol = int32(sampleRate * symbolDuration);
adsbParam.SamplesPerChip = adsbParam.SamplesPerSymbol / chipsPerSymbol;
adsbParam.MaxPacketLength = int32((preambleDuration+longPacketDuration)
* sampleRate);

targetSamplesPerFrame = 50000;
maxPacketDuration = (preambleDuration+longPacketDuration);
maxPacketLength = maxPacketDuration*frontEndSampleRate;
minNumSamplesPerFrame = lcm(256,maxPacketLength);
adsbParam.SamplesPerFrame = round(targetSamplesPerFrame /
minNumSamplesPerFrame)*minNumSamplesPerFrame;

adsbParam.MaxNumPacketsInFrame = floor(adsbParam.SamplesPerFrame /
maxPacketLength / 4);

adsbParam.FrameDuration = adsbParam.SamplesPerFrame /
frontEndSampleRate;

adsbParam.LongPacketLength = int32(longPacketDuration*sampleRate);
adsbParam.PreambleLength = int32(preambleDuration*sampleRate);
120
BÀI

adsbParam.LongPacketNumBits = int32(longPacketDuration /
symbolDuration);
adsbParam.ShortPacketNumBits = int32(shortPacketDuration /
symbolDuration);

b = rcosdesign(0.5, 3, double(adsbParam.SamplesPerChip));
adsbParam.InterpolationFilterCoefficients = single(b);

adsbParam.SyncSequence = [1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0];
adsbParam.SyncSequenceLength = length(adsbParam.SyncSequence);
adsbParam.SyncSequenceHighIndices = find(adsbParam.SyncSequence);
adsbParam.SyncSequenceNumHighValues =
length(adsbParam.SyncSequenceHighIndices);
adsbParam.SyncSequenceLowIndices = find(~adsbParam.SyncSequence);
adsbParam.SyncSequenceNumLowValues =
length(adsbParam.SyncSequenceLowIndices);
syncSignal = reshape(ones(adsbParam.SamplesPerSymbol/2,1)
*adsbParam.SyncSequence, 16*adsbParam.SamplesPerSymbol/2, 1);
adsbParam.SyncDownsampleFactor = 2;
adsbParam.SyncFilter = single(flipud(2*
syncSignal(1:adsbParam.SyncDownsampleFactor:end)-1));

sigSrc.SamplesPerFrame = adsbParam.SamplesPerFrame;
viewer = helperAdsbViewer('LogFileName', userInput.LogFileName);
startMapUpdate(viewer);
msgParser = helperAdsbRxMsgParser(adsbParam);

start(viewer)
radioTime = 0;

while radioTime < userInput.Duration

if adsbParam.isSourceRadio
[rcv,~,lost,late] = sigSrc();
121
BÀI

else
rcv = sigSrc();
lost = uint32(0);
late = uint32(1);
end

[pkt,pktCnt] = helperAdsbRxPhy(rcv, radioTime, adsbParam);

[msg,msgCnt] = msgParser(pkt,pktCnt);

update(viewer, msg, msgCnt, lost, late);

radioTime = radioTime + adsbParam.FrameDuration +...


double(lost)/adsbParam.FrontEndSampleRate;
end

stop(viewer)
release(sigSrc)

Hình 5.20:
122
BÀI

Hình 5.21:

5.2 SIMSCAPE MULTIBODY


Simscape Multibody hoá các chi t

Hình 5.22:

5.2.1 Bodies

Hình 5.23: dies

5.2.1.1 Machine Environment

- 2.
123
BÀI

Input gravity a

Analy n mô hình phân tích.

Hình 5.24:

5.2.1.2 Shared Environment

dùng
chung thôn

-
124
BÀI

5.2.1.3 Ground

này v a

tr
ground point.

Thô un

Hình 5.25:
125
BÀI

5.2.1.4 Body

- th

- - CSs)

- êm

- Các port

an.
h g

- ong Body và
126
BÀI

- nt và ellipsoid

-
tr

Joint Initial Condition Actuator

Mass Properties

- t


127
BÀI

Hình 5.26: Các th

-

World.

hay gián t
128
BÀI

- u hình cho Posit

y
radian hay vòng quay
- Euler:

-Y-Z là quay xung


tiên, t

- 3-by-3 Transform:

R-1 = RT

- Quaternion:

[nxsin( /2) nysin( /2) nzsin( /2) cos( /2)]

n = (nx, ny,nz
129
BÀI

5.2.2 Joints

Hình 5.27:

5.2.2.1 Prismatic

Kh

Hình 5.28: ng
Prismatic
130
BÀI

Hình 5.29: Các thôn

Axes: xác

5.2.2.2 Revolute

Hình 5.30:
BÀI 5: CÁC 131

5.2.2.3 Spherical

Hình 5.31: Sperical

ác
uay the

5.2.2.4 Planar

Hình 5.32: planar

planar
i hai t
Prismatic song song nhau.
132
BÀI

5.2.2.5 Universal

B
Revolute nguyên thu

Hình 5.33:

5.2.2.6 Cylindrical

olute.
Hình 5.34:

5.2.2.7 Gimbal

ng nhau

thì quá trình mô .

Hình 5.35:

5.2.2.8 Custom joint

Sperical.
133
BÀI

5.2.2.9 Weld

do). Hai Bo

Hình 5.36:

5.2.2.10 Telescoping

o qua

Hình 5.37:

5.2.2.11 In-plane

Hình 5.38: -plane

5.2.2.12 Bushing

và 3 k
134
BÀI

5.2.2.13 Bearing

Khi

Hình 5.39:
g

5.2.2.14 Six-DoF

5.2.2.15 Screw

do quay tron

Hình 5.40:
0

5.2.2.16 Disassembled prismatic

scape .

Hình 5.41:
Disassembled prismatic
135
BÀI

5.2.2.17 Disassembled cylindrical

Prismatic di

Simscape

Hình 5.42: embled cylindrical

5.2.2.18 Disassembled revolute

Simscape

Hình 5.43: H isassembled revolute

5.2.2.19 Disassembled spherical

Simscape

Hình 5.44: Hình d Disassembled spherical


136
BÀI 5: CÁC TOOLB

5.2.2.20 Revolute Revolute

Hình 5.45: ng
Revolute Revolute

5.2.2.21 Revolute Spherical

Hình 5.46:
Revolute Spherical

5.2.2.22 Spherical Spherical

Hình 5.47:
Spherical Spherical

5.2.3 Constraints & Drivers

Hình 5.48:
137
BÀI

5.2.3.1 Distance Driver

Cho r1, r2
1 r2| = d(t=0) + f(t).

tance Driver

5.2.3.2 Angle Driver

= (t=0) + f(t)

Angl

5.2.3.3 Linear Driver

gian. Cho r1, r2 R = r1 r2 = (X,Y,Z) là

X = X(t=0) + f(t) hay Y = Y(t=0) + f(t) hay Z = Z(t=0) + f(t)

Driver Act h hàm f(t).

World Axis:
138
BÀI

5.2.3.4 Velocity

Cho vB, vF, ,


B F B,
cF, dB, dF theo công
th

= cBvB + dB B - cFvF - dF F = (t=0) + f(t)

p trên trên b giá

5.2.3.5 Point-Curve Constraint

-Curve Constraint.

Hình 5.49: Point-Curve Constraint


139
BÀI

Breakpoints:

X-components, Y-components, Z-components: là các vector xác nh


(X,Y

End conditions

Not-a-

5.2.3.6 Parallel constraint

B, aF là 2 vector nh
tr

|aBaF| = |aB||aF|

Parallel Constraint Axis

5.2.3.7 Gear constraint

1, r2, 1 , 2 là bán

1 r1 = 2 r2

Ground cho 2 body trên.


Hình 5.50:
140
BÀI

5.2.4 Sensors & Actuators

Hình 5.51:

5.2.4.1 Body Actuator

Hình 5.52: Actuator

- Body tr
141
BÀI

5.2.4.2 Joint Actuator

Hình 5.53:

oment (quay) hay chu

- Khô

-
142
BÀI

Hình 5.54: i Joint Actuator

5.2.4.3 Driver Actuator

5.2.3

2f(t)/dt2

i Drive (Distance
Driver, Linear Driver, Velocity Driver) hay quay (Angle Driver).
143
BÀI

m port vào k

Hình 5.55: Driver Actuator

5.2.4.4 Body Sensor

Hình 5.56:

-
T
= RTR = I.
144
BÀI

5.2.4.5 Joint Sensor

- ismatic
trí,

quay.
Hình 5.57: V ensor
-

5.2.4.6 Constraint & Driver Sensor

Hình 5.58:

i Constraint &
Drive

5.2.4.7 Joint Initial Condition

-
145
BÀI

Hình 5.59:

5.2.4.8 Variable Mass & Inertia Actuator

5.2.4.9 Joint Stiction Actuator

- ion Actuator và Joint Actuator l

-
int Sensor.

-
146
BÀI

5.2.5 Force & Elements

Hình 5.60:

5.2.5.1 Body Spring & Damper

A, rB là
A rB

F = -k(|r| - r0)(r/|r|) b(vr)(r/|r|2)

Hình 5.61:

5.2.5.2 Joint Spring & Damper

-k(x x0 ) bv

Quay: F = -k( 0) b

5.2.6 Ví d

5.2.6.1

- .

- Double click v Bodies Machine Evironment



Ground

- Ground
147
BÀI

C Ground eck
box
Show Machine Environment port Ground Machine
Environment Format > Flip Block Ctrl+I

r2L = 2.49 uán tính:

- Body
148
BÀI

- Joints, kéo v Revolute vào mô hình.


149
BÀI

Revolute Ctrl+I Body Ground.

Current base

Current follower S1@Body

- Joint Sensor vào


Revolute Joint Sensor.
150
BÀI

Angle, Angular Velocity


Output selected parameters as one signal

- Simulink Browser Library Mux Signal


Routing), Scope, XY Graph Sinks

- spen.mdl.

- Simulation > Configuration


Parameteres.

Solver Relative tolerance thành 1e-6, Absolute


tolerance thành 1e-4, Max step size thành 0.2, Stop time thành inf.
151
BÀI

XY Graph xmin = 0, xmax = 200,


ymin = -500, ymax = 500.

Start Simulation ng. Double click


Scope Autoscale

- Simulation > Configuration Parameteres.

C box Display Machines after updating diagram và


Show animation during simulation.

Machine of model:
spen Model > Body Geometries > Ellipsoids.
152
BÀI

5.2.6.2 Gear constraint

- Body 1:

Thôn Gi

Mass 2.5
Inertia [1.17 0 0;0 1.17 0;0 0 2.25]
CG [0 0 0] World
CS1 [0 0 0] CG
CS2 [0 0 0] - CG
- Body 2:

Mass 2.5
Inertia [0.13 0 0;0 0.13 0;0 0 0.25]
CG [2 0 0] World
CS1 [0 0 0] CG
CS2 [0 0 0] - CG
- Ground 1: Location: [0 0 0]

- Ground 2: Location: [2 0 0]
153
BÀI

- Gear constraint:

Base pitch circle radius: 1.5


Follower pitch circle radius: 0.5
- Joint Actuator:

Actuate with: Motion

5.3 CONTROL SYSTEM

à bi

ù SISO

- , bi

ng thái khác.

5.3.1 Mô hình h th ng

Control System
, và
154
BÀI

5.3.1.1 n

tf
zpk -
không
ss
frd
pid
pidstd
pid2 ong song
pidstd2
pade Padé
absorbDelay z=0
thiran Thiran
totaldelay th LTI
delayss

5.24

num = [ 1 0 ]; % T s : s
den = [ 1 2 10]; % M u s : s^2 + 2 s + 10
H1 = tf(num,den);
subplot(311);step(H1);title('Transfer function');
z = 0; p = [-1+3*i -1-3*i]; m c c
k = 1; l i
H2 = zpk(z,p,k);
subplot(312);step(H2);title('Zero-pole-gain');
A = [ -2 -10 ; 1 0 ]; B = [ 1 ; 0 ]; C = [ 1 0 ]; D = 0;
H3 = ss(A,B,C,D);
subplot(313);step(H3);title('State-space');
155
BÀI

Hình 5.62: không

s = tf('s'); H1 = s/(s^2+2*s+10);
s = zpk('s'); H2 =
s/(s^2+2*s+10);
156
BÀI

5.3.1.2 K t n i các mô hình

H = H1*H2

H = H1+H2

H = feedback(H1,H2)

H = lft(H1,H2)

Hình 5.63: các mô hình

feedback
157
BÀI

connect
sumblk c
series
parallel
lft Redheffer
5.25

s = tf('s');
F = 1/(s+1);
G = 100/(s^2+5*s+100);
C = 20*(s^2+s+60)/s/(s^2+40*s+400);
S = 10/(s+10);
T = F * feedback(G*C,S); % Mô hìn
step(T)

Hình 5.64:
158
BÀI

5.26 dùng connect:

Hình 5.65

Sum1 = sumblk('e = r - y');


Sum2 = sumblk('u = uC + uF');
i ("u" và "y" là ngõ vào và ngõ ra)
F.u = 'r'; F.y = 'uF';
C.u = 'e'; C.y = 'uC';
G.u = 'u'; G.y = 'ym';
S.u = 'ym'; S.y = 'y';
T = connect(F,C,G,S,Sum1,Sum2,'r','ym');
step(T), grid

5.3.2 Phân tích h th ng

step
stepinfo
impulse
initial
lsim tk
lsiminfo

gensig

bode Bode
bodemag
159
BÀI

nyquist Nyquist
nichols Nichols
sigma iá t ng
evalfr
dcgain LTI
5.27

Hình 5.66:

s = tf('s');
H1 = 1/(s+1); H2 = s/(s^2+5*s+100);
H = H2*H1;
t = 0:0.01:4;
u = exp(-t); % Ngõ vào
v = lsim(F,u,t); % Ngõ ra c a H1
y = lsim(G,v,t); % L y ngõ ra H1 -> H2 và tính ngõ ra c a H2
y1 = lsim(H,u,t); % Ngõ ra c a h th
subplot(121);plot(t,y);
subplot(122);plot(t,y1);
160
BÀI

5.28

s = tf('s'); H = (s^2+2*s+3)/(s^3+2*s^2+10);
figure;bode(H);grid
figure;nyquist(H);grid
figure;nichols(H);grid

Hình 5.67:
161
BÀI

5.29

Hình 5.68:

s = tf('s');
G = -(2*s+1)/(s^2+3*s+2);
k1 = 0.4;
G1 = feedback(G*k1,1);
k2 = 0.7;
G2 = feedback(G*k2,1);
k3 = 1;
G3 = feedback(G*k3,1);
step(G1,'b',G2,'r',G3,'g')
legend('k = 0.4','k = 0.7','k = 1')

Hình 5.69: c Hình 5.68

5.30 Hình 5.68

s = tf('s'); G = -(2*s+1)/(s^2+3*s+2);
162
BÀI

rlocus(G); grid

Hình 5.70: Hình 5.68

hình m

Hình 5.71: Hình 5.68

và k = 1.6:
163
BÀI

Hình 5.72: Hình 5.68

5.3.3 PID Tuning

5.31: PID Tuner cho mô hình

G = zpk(-5,[-1 -2 -3 -4],6,'OutputDelay',1);

pidtool(G,'pi'); %Thi t k b u khi n PI


164
BÀI

Hình 5.73: C

Show Paramters

Hình 5.74:

1.9 6.28
165
BÀI

Click Add Plot input disturbance rejection.

Hình 5.75:

(Response Time)

0.3.
166
BÀI

Hình 5.76:

và Ki = 0.30314.
167
BÀI

5.32 feedback-

Hình 5.77:

Hình 5.78:

t1 = 21.8; t2 = 36.0; tau = 3/2 * ( t2 - t1 )


theta = t2 - tau;
s = tf('s');
Gp = exp(-theta*s)/(1+tau*s)
Kc = 0.859 * (theta / tau)^(-0.977)
tauc = ( tau / 0.674 ) * ( theta / tau )^0.680
C = Kc * (1 + 1/(tauc*s));
Tfb = feedback(ss(Gp*C),1);
168
BÀI

step(Tfb), grid on
title('Response to step change in temperature setpoint T_ {sp}')
ylabel('Tank temperature')

margin(Gp*C), grid

C1 = 0.9 * (1 + 1/(tauc*s)); % gi m Kc t n 0.9


margin(Gp*C1), grid
169
BÀI

step(Tfb,'b', feedback(ss(Gp*C1),1),'r')
legend('Kc = 1.23','Kc = 0.9')
170
BÀI

Hình 5.79:

Gd = exp(-35*s)/(25*s+1);
F = -(21.3*s+1)/(25*s+1) * exp(-25*s);
Tff = Gp * ss(F) + Gd;
step(Tff), grid

Hình 5.80: -feedback


171
BÀI

Gd.u = 'd'; Gd.y = 'Td';


Gp.u = 'V'; Gp.y = 'Tp';
F.u = 'd'; F.y = 'Vf';
C.u = 'e'; C.y = 'Vc';
Sum1 = sumblk('e = Tsp - T');
Sum2 = sumblk('V = Vf + Vc');
Sum3 = sumblk('T = Tp + Td');
Tffb = connect(Gp,Gd,C,F,Sum1,Sum2,Sum3,{'Tsp','d'},'T');

C.u = 'e'; C.y = 'V';


Tfb = connect(Gp,Gd,C,Sum1,Sum3,{'Tsp','d'},'T');
step(Tfb,'b',Tffb,'r--'), grid
title('Closed-loop response to setpoint and disturbance step change')
ylabel('Tank temperature')
legend('Feedback only','Feedforward + feedback')

bodemag(Tfb,'b',Tffb,'r--',{1e-3,1e1})
legend('Feedback only','Feedforward + feedback')
172 BÀI 5: C
173
BÀI

Hình 5.81: h

Hình 5.82:
174
BÀI

Hình 5.83: u

Hình 5.84:
175
BÀI

Hình 5.85: -

5.3.4 Thi t k h th u khi n dùng Control System Designer

Control System Designer cho phép:

1.
không.

2. :

3.

5.33:

-
176
BÀI

- (rise time)

- (settling time)

- (overshoot) 0%.

G = tf(1,[1,1]);
controlSystemDesigner(G);

Hình 5.86:

Step Response Design Requirements


>
New
BÀI 5: CÁC TOO 177

Hình 5.87:

OK

Hình 5.88:

Design Requirements > New


178
BÀI

Hình 5.89:

Root Locus Editor Add Pole/Zero > Integrator.

- Add Pole/Zero > Real Zero

-2.

l Bode Editor,
179
BÀI

Hình 5.90: n
180
BÀI

TÓM T
T
MatLab.

ystem
dùng cho sinh viên ngàn -

Câu 1: u khi n có hàm truy n


i
u khi n .
Câu 2:
i

-
-
-
-
-
Câu 3: Dùng công c Simscape Multibody mô ph ng c ch 4 thanh sau:
181
BÀI

au:

Câu 4: Dùng Simulink mô ph ng ho t ng i u ch thông d i nh sau:


182

1. Mathworks Inc., MatLab Documentation, 2019.

2. Won Y. Yang, Yong S. Cho, Won G. Jeon, Jeong W. Lee, Jong H. Paik, Jae K. Kim,
Mi-Hyun Lee, Kyu I. Lee, Kyung W. Park, Kyung S. Woo, MatLab/Simulink for
Digital Communication, A-Jin Publishing Co.

3. Bill Messner, Dawn Tilbury, Control Tutorials for MATLAB and Simulink, Addison-
Wesley Publishing Company, Inc.

You might also like