View
237
Download
0
Category
Preview:
Citation preview
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 1/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Control Systems and MatlabIntroduction
Consider the OLTF with negative feedback:)4.0)(25)(15(
)20(18)(
+++
+=
s s s
s sG . To define it type
separately the numerator and the denominator as two different polynomials. The code is written inan m-file.% prg1% This m-file creates and prints the transfer function% num stands for numerators% den stands for denominatornum=18*[1 20]den=conv(conv([1 15],[1 25]), [1 0.4])printsys(num,den,'s')
» prg1num =
18 360den =
1.0000 40.4000 391.0000 150.0000num/den =
18 s + 360----------------------------s^3 + 40.4 s^2 + 391 s + 150
To find the CLTF we use the command feedback(numg,deng,numh,denh) % prg3% This m-file creates and prints the transfer function% numol stands for numerator of the open loop TF
% denol stands for denominator of the open loop TF% numcl stands for numerator of the close loop TF% dencl stands for denominator of the close loop TF numol=18*[1 20]denol=conv(conv([1 15],[1 25]), [1 0.4])[numcl,dencl]=feedback(numol,denol,1,1)printsys(numcl,dencl,'s')» prg3
numol =18 360
denol =1.0000 40.4000 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
Control Systems and Matlab 1
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 2/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Step Response
To find the step response of a system use the command:
step(numerator, denominator).
1
s +4s2
Transfer FcnSu m
Step
-K-
Gain
The CLTF isK ss
K
sR
sC
GH
G
sR
sC H
ssG ++
=⇔+
==
+= 4)(
)(
1)(
)(2
1
4
12
So if K=1:% prg6% step 1 % This m-file finds the step responsenum=[1];den=[1 4 1];step(num,den);gridxlabel('time')ylabel('output')title('step response')
Time (sec.)
A m p l i t u d e
Step Response
0 5 10 15 20 250
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
step response
time
o u t p u t
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;
Control Systems and Matlab 2
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 3/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMSnum=[1];den=[1 4 1];step(num,den,t);gridxlabel('time')ylabel('output')
title('step response')
Time (sec.)
A m p l i t u d e
Step Response
0 5 10 15 20 25 300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
step response
time
o u t p u t
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')gridxlabel('time')ylabel('output')title('step response')
0 5 10 15 20 25 300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
time
o u t p u t
step response
More than one graph can be plotted on the same figure using a combination of plot and step:
Control Systems and Matlab 3
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 4/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Note that when we found the step response we used as an argument the time. If we do not then step
will take a default number for time and so later when using the command plot, an error message
will be given because the two vectors do not have the same size.% prg9 % step 4 % This m-file finds the step response t=0:0.1:20;%k=1 num1=[1];den1=[1 4 1];%k=100 num2=[100];den2=[1 4 100];c1=step(num1,den1,t);c2=step(num2,den2,t);plot(t,c1,'or',t,c2)grid
xlabel('time')ylabel('output')title('step response')
0 5 10 15 200
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
time
o u t p u t
step response
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 s
s)(G
Frequency Response Bode Diagrams
To plot the Bode diagram we use the command bode(num,den) .Π.χ. :% prg16 %bode 1clcclear all
clfnum=10;den=[1 5 5 0];
Control Systems and Matlab 4
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 5/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMSbode(num,den);
Frequency (rad/sec)
P h a s e ( d e g ) ; M a g n i t u d e ( d B )
Bode Diagrams
-150
-100
-50
0
50
10-2
10-1
100
101
102
-300
-200
-100
0
As with the root locus plot we can chose the frequencies:%prg17 %bode 2clcclear allclfnum=10;den=[1 5 5 0];w=logspace(-1, 4,100);bode(num,den,w);
Frequency (rad/sec)
P h a s e ( d e g ) ; M a g n i t u d e ( d B )
Bode Diagrams
-300
-200
-100
0
100
10-1
100
101
102
103
104
-300
-200
-100
0
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 3clcclear all
clfnum=10;den=[1 5 5 0];margin(num,den);
Control Systems and Matlab 5
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 6/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Frequency (rad/sec)
P h a s e ( d e g ) ; M a g n i t u d e ( d B )
Bode Diagrams
-150
-100
-50
0
50
Gm=8.0 dB (Wcg=2.2); Pm=25.5 deg. (Wcp=1.3)
10-2
10-1
100
101
102
-300
-200
-100
0
Nichols diagrams
To find the Nichols plot use the command nichols(num,den).% prg19 clcclear allclf num=10;den=[1 5 5 0];
nichols(num,den);ngrid
Open-Loop Phase
Open-
LoopGai
Nichols
- - - - - - -50-40
-20
0
20
40
60
80
63
1
0.50.25
0
-1
-3
-6
-12
-20
-40
Pm
Gm
With the Nichols plots we use the ngrid command.
Control Systems and Matlab 6
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 7/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Nyquist diagrams
As with Nichols to create a Nyquist diagram we use the command nyquist(num,den):% prg20%nyquist 1
clcclear allclfnum=10;den=[1 5 5 0];nyquist(num,den);
Real Axis
I m a g i n a r y A x i s
Nyquist Diagrams
-2.5 -2 -1.5 -1 -0.5 0-250
-200
-150
-100
-50
0
50
100
150
200
250
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 clcclear allclfnum=10;den=[1 5 5 0];w=0:0.1:100;[re,im,w]=nyquist(num,den,w);
plot(re,im);grid
Control Systems and Matlab 7
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 8/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
AGm
0
1=
5
A 0
0
-5
-10
-15
-2 -20
-1.8 -1.6 -1.4 -0.2 0 -1.2 -1 -0.8 -0.6 -0.4
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.:
1
s +5s2
Tran sfer FcnSum
k
Ga in
% prg12
ocus 1 % rlclc
llclear anum=1;den=[1 5 0];rlocus(num,den)
Control Systems and Matlab 8
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 9/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
-6 -5 -4 -3 -2 -1 0 1 2-1.5
-1
-0.5
0
0.5
1
1.5
Real Axis
I m a g A x i s
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
clfk=0:1:100;
num=1;
den=[1 5 5 0];
rlocus(num,den,k)
-5 -4 -3 -2 -1 0 1 2-4
-3
-2
-1
0
1
2
3
4
Real Axis
I m a
g A x i s
or % prg14
%rlocus 3
clc
clear allclf
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)
Control Systems and Matlab 9
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 10/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
-5 -4 -3 -2 -1 0 1 2-8
-6
-4
-2
0
2
4
6
8
Real Axis
I m a g A x i s
For k=11 to 90 we have more samples of the locus.
To find the poles and a specific point of the locus we use the command rlocfind(xxx,yyy)% prg15%rlocus 4 clcclear allclfk1=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:» prg15Select 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
Control Systems and Matlab 10
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 11/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
-5 -4 -3 -2 -1 0 1 2-8
-6
-4
-2
0
2
4
6
8
Real Axis
I m a g A x i s
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 – seelater
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)
» prg2a =
x1 x2 x3
x1 -40.40000 -391.00000 -150.00000x2 1.00000 0 0x3 0 1.00000 0
b =u1
x1 1.00000x2 0x3 0
c =x1 x2 x3
y1 0 18.00000 360.00000d =
u1y1 0
Control Systems and Matlab 11
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 12/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
State Space to Transfer Function
From A, B, C, D to find the TF use the command ss2tf( Α ,B,C,D) % prg4% This m-file converts a second order system
% form state space to transfer function% num stands for numerator% den stands for denominatorA=[1 2; 4 5];B=[1 0]';C=[1 0];D=[0];[num,den]=ss2tf(A,B,C,D);printsys(num,den,'s')
» prg4
num/den =s - 5-------------s^2 - 6 s – 3
Transfer Function to State Space
From the TF can find the matrices A,B,C,D with the command tf2ss(num,den) % prg5% This m-file converts a second order system% form transfer function to state space% num stands for numenator% den stands for denominatornum=[1 -5];den=[1 -6 -3];[A,B,C,D]=tf2ss(num,den);printsys(A,B,C,D)
prg5a =
x1 x2x1 6.00000 3.00000x2 1.00000 0
b =u1
x1 1.00000x2 0
c =x1 x2
y1 1.00000 -5.00000
d =u1
y1 0
Control Systems and Matlab 12
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 13/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Step in State Space
The command step can be used for state space defined systems: %prg 9ba = [6 3;1 0];
b = [1;0];c = [1 -5];d = [0];step(a,b,c,d)
Time (sec.)
A m p l i t u d e
Step Response
0 0.16 0.32 0.48 0.64 0.80
1
2
3
4
5
6
7
Consider a system that can be described by the following equations:
x
x
x
x
u
u
y
y
x
x
1
2
1
2
1
2
1
2
1
2
1 1
6 5 0
1 1
1 0
1 0
0 1
•
•
=− −
+
=
.
The step response is:
⇒−==⇒−=⇒
⇒
=
−=⇒
=
+=⇒
=
+=
−−
−•
B AsI C sGsU
sY sBU AsI C sY
sCX sY
sBU AsI s X
sCX sY
sBU s AX ssX
CX y
BU AX X LAPLACE
11
1
)()()(
)()()()(
)()(
)()()(
)()(
)()()(
5.65.6
)()(,
5.6)()(
5.6
5.7
)(
)(,
5.6
1
)(
)(
)(
)(
5.6
5.6
5.6
5.7
5.65.6
1
)(
)(
655.7
1
5.6
1
01
11
5.6
11
10
01
22
22
2
1
21
2
21
1
2
1
22
22
2
1
2
1
++=
++=
++
+=
++
−=
⇒
++++
+
++++
−
=
⇒
⇒
+−
++=
−
+
⇒
−
sssU sY
sss
sU sY
ss
s
sU
sY
ss
s
sU
sY
sU
sU
ssss
s
ss
s
ss
s
sY
sY
s
ss
sss
s
Control Systems and Matlab 13
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 14/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
So we expect four graphs:» a=[-1 -1;6.5 0];» b=[1 1;1 0];» c=[1 0;0 1];» d=[0 0;0 0];
» step(a,b,c,d)
Time (sec.)
A m p l i t u d e
Step Response
-0.4
-0.2
0
0.2
0.4
From: U1
T o : Y 1
From: U2
0 4 8 120
0.5
1
1.5
2
T o : Y 2
0 4 8 12
If the step response for only one input was wanted:
» step(a,b,c,d,1) or » step(a,b,c,d,2)
Time (sec.)
A m p l i t u d e
Step Response
-0.4
-0.2
0
0.2
0.4
T o : Y 1
0 2 4 6 8 10 120
0.5
1
1.5
2
T o : Y 2
Time (sec.)
A m p l i t u d e
Step Response
-0.2
-0.1
0
0.1
0.2
0.3
T o : Y 1
0 2 4 6 8 10 120
0.5
1
1.5
2
T o : Y 2
Control Systems and Matlab 14
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 15/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
Lab Exercises:
1. Consider the following system:
1.1 Find and plot the step response of the CL system.
1.2 Find and plot the step response of the system for k=30,60,90.
1.3 Describe the system in SS.
1
s +6s +11s+63 2
Tran sfer Fcn
Su m
k
Gain
2.1 Find the root locus plot and the maximum stable gain. Relate the step response to the CL
pole locations.
1
s +6s +11s+63 2
Transfer Fcn
Su m
k
Gain
2.2 Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations.
1
s +1.1s +10.3s +5s4 3 2
T ransfer Fcn
Sum
k
Gain
Control Systems and Matlab 15
8/8/2019 CS Matlab Exercises
http://slidepdf.com/reader/full/cs-matlab-exercises 16/16
University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
C l S d M l b 16
2.3 Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations:
s +5s+62
s +s2
Transfer FcnSu m
k
Gain
2.4 Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations:
1
s +6s +25s3 2
Transfer FcnSu m
k
Gain
2.5 Find the gain and phase margin of the above OLTF
3 Produce the Bode, Nyquist and Nichols diagrams for the following systems.
)164)(2(
)1(320)(
21+++
+=
ssss
ssG
4.0,5.1,4,)2)(1(
)(2 =++
= k sss
k sG
100,10,)5)(1(
)(3 =++
= k sss
k sG
Recommended