Professional Documents
Culture Documents
18( s + 20)
. To define it type
( s + 15)( s + 25)( s + 0.4)
separately the numerator and the denominator as two different polynomials. The code is written in
an m-file.
% prg1
% This m-file creates and prints the transfer function
% num stands for numerators
% den stands for denominator
num=18*[1 20]
den=conv(conv([1 15],[1 25]), [1 0.4])
printsys(num,den,'s')
prg1
num =
18
360
den =
1.0000
40.4000 391.0000 150.0000
num/den =
18 s + 360
---------------------------s^3 + 40.4 s^2 + 391 s + 150
391.0000
150.0000
numcl =
0
0
18
360
dencl =
1.0000
40.4000 409.0000
510.0000
num/den =
18 s + 360
---------------------------s^3 + 40.4 s^2 + 409 s + 510
Step Response
To find the step response of a system use the command:
step(numerator, denominator).
-K S te p
The CLTF is
Sum
s 2+4 s
Gain
H =1
C (s )
G
=
R(s ) 1 + GH G = 1
T ra n sfe r Fcn
C (s )
K
= 2
R(s ) s + 4s + K
s 2 + 4s
So if K=1:
% prg6
% step 1
% This m-file finds the step response
num=[1];
den=[1 4 1];
step(num,den);
grid
xlabel('time')
ylabel('output')
title('step response')
S tep Res pons e
s tep res ponse
1
0.9
0.8
0.6
output
Am plitude
0.7
0.5
0.4
0.3
0.2
0.1
10
15
20
25
e .)
Tim e tim
(sec
The command step takes a default time for the transient response to be finished (i.e. 25s here)
If we want to define the time we can use the next m-file:
% prg7
% step 2
% This m-file finds the step response
t=0:0.1:30;
0.6
output
A m plitude
0.7
0.5
0.4
0.3
0.2
0.1
0
10
15
Tim e tim
(sece .)
20
25
30
For more complex systems it is possible to combine the commands step & plot :
% prg8
% step 3
% This m-file finds the step response
t=0:0.1:30;
num=[1];
den=[1 4 1];
c=step(num,den,t);
plot(t,c,'or')
grid
xlabel('time')
ylabel('output')
title('step response')
s tep response
0.9
0.8
0.7
output
0.6
0.5
0.4
0.3
0.2
0.1
10
15
tim e
20
25
30
More than one graph can be plotted on the same figure using a combination of plot and step:
output
1
0.8
0.6
0.4
0.2
0
10
tim e
15
20
To find the impulse response we use the command impulse. This is used exactly as the command
step. To find the ramp response we have to find the step response of the function G ( s)
s
-50
-100
-150
0
-100
-200
-300
-2
10
10
-1
10
10
10
Frequency (rad/sec)
100
-100
-200
-300
0
-100
-200
-300
-1
10
10
10
10
10
10
Frequency (rad/s ec )
To find the gain and phase margins we use the command margin(num,den) since it is very difficult
to calculated directly from the above figures with any accuracy. This command plots the Bode
diagram and calculates the margins:
% prg18
%bode 3
clc
clear all
clf
num=10;
den=[1 5 5 0];
margin(num,den);
50
-50
-100
-150
0
-100
-200
-300
-2
10
10
-1
10
10
10
Frequency (rad/sec)
Nichols diagrams
40
20
1
3
6
0.25
0.5
-1
-3
-6
Pm
-12
-20
-40
-
-20
Gm
-
Open-Loop Phase
-50
-40
Im aginary A x is
100
50
0
-50
-100
-150
-200
-250
-2.5
-2
-1.5
-1
-0.5
Real A xis
The command nyquist takes both negative and positive values for the frequency. For this reason we
see a curve which is symmetrical to the x-axis. If we want only positive frequencies then:
% prg22
%nyquist 3
clc
clear all
clf
num=10;
den=[1 5 5 0];
w=0:0.1:100;
[re,im,w]=nyquist(num,den,w);
plot(re,im);
grid
-5
Gm =
-10
1
0A
-15
-20
-2
-1.8
-1
-0.2
All the above commands can be used for systems that are described in State Space form see later
Root Locus
The design of the root locus plot of a system is very easy and fast with the use of Matlab. This is
more obvious in more complex systems than the examples used here. To find the root locus we use
the command rlocus(xxx,yyy) where xxx is the numerator and yyy is the denominator of the OLTF
e.g.:
k
Sum
Gain
1
s 2+5 s
T ra n sfe r Fcn
% prg12
% rlocus 1
clc
clear all
num=1;
den=[1 5 0];
rlocus(num,den)
Im ag A x is
0.5
-0.5
-1
-1.5
-6
-5
-4
-3
-2
Real Ax is
-1
The above root locus plot is for values of gain from 0 to a specific value to allow conclusions about
the behaviour and stability of the system. If we would like to define the values of gain then:
% prg13
%rlocus 2
clc
clear all
clf
k=0:1:100;
num=1;
den=[1 5 5 0];
rlocus(num,den,k)
4
Im ag A x is
-1
-2
-3
-4
-5
-4
-3
-2
-1
Real Axis
or
% prg14
%rlocus 3
clc
clear all
clf
k1=0:2:10;
k2=11:0.5:90;
k3=91:10:500;
k=[k1 k2 k3];
num=1;
den=[1 5 5 0];
rlocus(num,den,k)
6
4
Im ag Ax is
0
-2
-4
-6
-8
-5
-4
-3
-2
-1
Real Ax is
To find the poles and a specific point of the locus we use the command rlocfind(xxx,yyy)
% prg15
%rlocus 4
clc
clear all
clf
k1=0:2:10;
k2=11:0.5:90;
k3=91:10:500;
k=[k1 k2 k3];
num=1;
den=[1 5 5 0];
rlocus(num,den,k);
[k,poles]=rlocfind(num,den)
After the execution of the m-file the point of interest can be defined with the mouse:
prg15
Select a point in the graphics window
selected_point =
-0.4330+ 1.1730i
k =
6.4034
poles =
-4.1691
-0.4154+ 1.1676i
-0.4154- 1.1676i
10
6
4
Im ag A x is
0
-2
-4
-6
-8
-5
-4
-3
-2
-1
Real A x is
If that point were on the imaginary axis then this would produce the maximum stable gain.
The commands rlocus, rlocfind can be used for systems that are described in State Space form see
later
State Space
To describe a system in State Space we must define the matrices A,B,C,D:
% prg2
% This m-file creates and prints a system, which is defined in state %
space
a=[-40.4 -391 -150; 1 0 0; 0 1 0];
b=[1 0 0]';
c=[0 18 360];
d=[0];
printsys(a,b,c,d)
prg2
a =
b =
x1
x2
x3
x1
-40.40000
1.00000
0
x1
x2
x3
u1
1.00000
0
0
y1
x1
0
y1
u1
0
c =
d =
x2
-391.00000
0
1.00000
x3
-150.00000
0
0
x2
18.00000
x3
360.00000
11
x1
6.00000
1.00000
x1
x2
u1
1.00000
0
y1
x1
1.00000
x2
3.00000
0
b =
c =
x2
-5.00000
d =
u1
y1
12
A m plitude
0.16
0.32
0.48
0.64
0.8
Tim e (sec .)
y1 1 0 x1
y = 0 1 x
2
2
The step response is:
1
LAPLACE
X = AX + BU sX (s ) = AX (s ) + BU (s ) X (s ) = (sI A) BU (s )
Y (s ) = CX (s )
Y (s ) = CX (s )
y = CX
Y (s ) = C(sI A) 1 BU (s )
Y (s )
= G(s ) = C(sI A) 1 B
U (s )
s 1s
10 s + 11 11
1
= 2
2
2
Y1(s )
s + s + 6.5 s + s + 6.5 U1(s )
6 .5
U 2 (s )
Y2 (s ) s + 7.5
s 2 + s + 6.5 s 2 + s + 6.5
Y1(s )
Y (s )
s 1
s + 7 .5
= 2
= 2
, 2
U1(s ) s + s + 6.5 U1(s ) s + s + 6.5
Y1(s )
Y (s )
s
6. 5
= 2
, 2
= 2
U 2 ( s ) s + s + 6 .5 U 2 ( s ) s + s + 6 . 5
13
From: U1
0.4
To: Y 1
0.2
0
A mplitude
-0.2
-0.4
To: Y 2
1.5
1
0.5
0
0
12
120
Time (sec.)
Step Response
0.2
0.4
To: Y 1
A mplitude
-0.2
-0.4
-0.1
-0.2
2
1.5
To: Y 2
1.5
To: Y 2
Amplitude
0.1
To: Y 1
0.2
0.5
0.5
0
0
10
12
0
0
10
12
Time (sec.)
Time (sec.)
14
1.
1.1
1.2
1.3
k
Sum
1
s 3+6 s 2+1 1 s+6
Gain
T ra n sfe r Fcn
2.1
Find the root locus plot and the maximum stable gain. Relate the step response to the CL
pole locations.
k
Sum
1
s 3+6 s 2+1 1 s+6
Gain
T ra n sfe r Fcn
2.2
Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations.
k
Sum
1
s 4+1 .1 s 3+1 0 .3 s 2+5 s
Gain
T ra n sfe r Fcn
15
k
Sum
Gain
s 2+5 s+6
s 2+s
T ra n sfe r Fcn
2.4
Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations:
k
Sum
2.5
Gain
1
s 3+6 s 2+2 5 s
T ra n sfe r Fcn
16