University of Newcastle upon Tyne School of Electrical, Electronic and Computer Engineering CONTROL SYSTEMS Control Systems and Matlab Introduction Consider the OLTF with negative feedback: ) 4 . 0 )( 25 )( 15 ( ) 20 ( 18 ) ( + + + + = s s s s s G . To define it type 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 To find the CLTF we use the commandfeedback(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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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
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;
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
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);
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;
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)
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)