MATLAB & CONTROL SYSTEM TOOLBOX
MATLAB & CONTROL SYSTEM
TOOLBOX
Introduction
Definition of a linear system
Block diagram reduction
Time response
Frequency response
Other functions
Simulink
2/8/2021
Automatic Control Systems 1
MATLAB & CONTROL SYSTEM TOOLBOX
INTRODUCTION
MATLAB (matrix laboratory) is developed
by MathWorks.
Il allows matrix manipulations, plotting of functions
and data, creation of user interfaces.
It interface with programs written in C, C++, Java,
and Fortran.
Many toobox: Control System, Finacial, Fuzzy Logic,
Signal Processing, Statistics, Symbolic, System
Identification, …
Website [Link]
2/8/2021
Automatic Control Systems 2
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Transfer function (1)
Syntax
SYS = tf(num,den, Ts)
Creates a continuous-time transfer function SYS
num: numerator
den: denominator
Ts: sample time (for discrete system)
Example
s2
G1 ( s ) 3 num1=3*[1 2];den1=[1 2 4];G1=tf(num1,den1);
s 2 2s 4
z 0.6 num2=2.1*[1 -0.6];den2=[1 -0.56]; T=0.5;
G2 ( z ) 2.1
z 2 0.56 z 0.4 G2=tf(num2,den2,T)
2/8/2021
Automatic Control Systems 3
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Transfer function (2)
For MIMO system
U1 Y1 G11 ( s ) G12 ( s ) ... G1n ( s )
G ( s ) G ( s ) G ( s )
G (s)
21 22 2 n
Un G Yn
...
G p1 ( s ) G p 2 ( s ) G pn ( s )
G11=tf(num11,den11,T); G12=tf(num12,den12,T);...; G1n=tf(num1n,den1n,T);
G21=tf(num21,den21,T); G22=tf(num22,den22,T);...; G2n=tf(num2n,den2n,T);
Gp1=tf(nump1,denp1,T); G12=tf(nump2,denp2,T);...; Gpn=tf(numpn,denpn,T);
G=[G11,G12,...,G1n;G21;G22;...;G2n;...;Gp1,Gp2,...,Gpn];
2/8/2021
Automatic Control Systems 4
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Zero-pole-gain model
Syntax
SYS=zpk(Z,P,K,Ts)
• Z : zeros
• P: poles
• K: gain
• Use [] if no zero/pole
Example
s2
G(s) Z=-2;P=[0 -5];K=1;G=zpk(Z,P,K);
s(s 5)
2/8/2021
Automatic Control Systems 5
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
State space
Syntax
SYS=ss(A,B,C,D,Ts)
Example
̇ −2 0 1 0.0025
= +
̇ 2 −4 2 0.0025
2/8/2021
Automatic Control Systems 6
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Conversion
State space to transfer function
Syntax: [num,den] = ss2tf(A,B,C,D)
ZPK to transfer function
Syntax: [num,den] = zp2tf(Z,P,K)
Transfer function to state space
Syntax: [A,B,C,D]=tf2ss(num,den)
2/8/2021
Automatic Control Systems 7
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Conversion of continuous-time models to
discrete time
• Syntax
• SYS_dis=c2d(SYS_con,T,’method’)
SYS_dis: discrete time model
SYS_con: continuous time model
method of discretization:
• ‘zoh’: zero order hold
• ‘foh’: first order hold
• ‘impulse’: impulse invariant discretization
• ‘tustin’: bilinear approximation
2/8/2021
Automatic Control Systems 8
MATLAB & CONTROL SYSTEM TOOLBOX
DEFINITION OF A LINEAR SYSTEM
Access of transfer function data
Syntax
[num,den]=tfdata(SYS,’v’)
[A,B,C,D]=ssdata(SYS)
System with delay
Syntax
SET(SYS,’Iodelay’,t0)
t0: time delay
2/8/2021
Automatic Control Systems 9
MATLAB & CONTROL SYSTEM TOOLBOX
BLOCK DIAGRAM
Series
Syntax: SYS=series(SYS1,SYS2)
Parallel
Syntax: SYS=parallel(SYS1,SYS2)
Feedback
Syntax: SYS=feedback(SYS1,SYS2,sign)
2/8/2021
Automatic Control Systems 10
MATLAB & CONTROL SYSTEM TOOLBOX
TIME RESPONSE
Step response
Syntax
step(sys)
step(sys,t_end)
step(sys,T)
With T=Tinitial:dt:Tfinal
step(sys1,sys2,sys3,…)
2/8/2021
Automatic Control Systems 11
MATLAB & CONTROL SYSTEM TOOLBOX
TIME RESPONSE
Impulse response
• Syntax: impulse(sys)
Time response of arbitrary inputs
• Syntax: lsim(sys,u,t)
(u,t) describe input signal
• Example:
Time response of a single-input model SYS to the
input u(t)=sin(t) during 5 seconds:
T=0:0.1:5;u=sin(t);lsim(SYS,u,t)
2/8/2021
Automatic Control Systems 12
MATLAB & CONTROL SYSTEM TOOLBOX
FREQUENCY RESPONSE
Bode plot
Syntax
bode(sys)
bode(sys,{w_min,w_max}):
bode(sys,w)
w: user-supplied vector of frequencies
bode(sys1,sys2,sys3,…)
2/8/2021
Automatic Control Systems 13
MATLAB & CONTROL SYSTEM TOOLBOX
FREQUENCY RESPONSE
Nyquist plot
Syntax: nyquist(sys)
Nichols plot
Syntax: nichols(sys)
2/8/2021
Automatic Control Systems 14
MATLAB & CONTROL SYSTEM TOOLBOX
OTHER FUNCTIONS (1)
Compute steady state gain
Syntax: dcgain(sys)
Compute poles of LTI model
Syntax: pole(sys)
Compute zeros of LTI model
Syntax: tzero(sys)
Sketch pole-zero map
Syntax: pzmap(sys)
2/8/2021
Automatic Control Systems 15
MATLAB & CONTROL SYSTEM TOOLBOX
OTHER FUNCTIONS (2)
Root locus of a SISO system
Syntax: rlocus(sys)
Compute gain, phase margin and crossover
frequency
Syntax: [Gm,Pm,Wcg,Wcp] = MARGIN(SYS)
Compute the observability matrix.
Syntax: CO = OBSV(SYS)
2/8/2021
Automatic Control Systems 16
MATLAB & CONTROL SYSTEM TOOLBOX
SIMULINK
Thư viện Sources
• Step
• Ramp
• Constant
Thư viện Sink
• Scope
• XY Graph
• To Workspace
2/8/2021
Automatic Control Systems 17
MATLAB & CONTROL SYSTEM TOOLBOX
SIMULINK
Thư viện Continuous
• Transfer Fcn
• State space
• ….
Thư viện Discrete
• Discrete Transfer Fcn
• Discrete State Space
• …
2/8/2021
Automatic Control Systems 18
MATLAB & CONTROL SYSTEM TOOLBOX
SIMULINK
Thư viện Signal & System
• Mux
• Demux
• In1
• Out1
• ….
Thư viện Maths
• Abs
• Sign
• Sum
• …
2/8/2021
Automatic Control Systems 19
MATLAB & CONTROL SYSTEM TOOLBOX
SIMULINK
Examples
2/8/2021
Automatic Control Systems 20