Вы находитесь на странице: 1из 16

University of Newcastle upon Tyne

School of Electrical, Electronic and Computer Engineering


CONTROL SYSTEMS
Control Systems and Matlab
Introduction
18( s + 20)
Consider the OLTF with negative feedback: G ( s ) = . 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

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


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
-K -
S te p s 2+4 s
Sum Gain T ra n sfe r Fcn

C (s ) G H =1 C (s ) K
The CLTF is = ⇔ = 2
R(s ) 1 + GH G = 1 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.7

0.6
Am plitude

output

0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25
Tim e tim
(sece .)

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


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
num=[1];
den=[1 4 1];
step(num,den,t);
grid
xlabel('time')
ylabel('output')
title('step response')
S tep Response
step respons e
1

0.9

0.8

0.7

0.6
A m plitude

output

0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25 30
Tim e tim
(sece .)

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
1

0.9

0.8

0.7

0.6
output

0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25 30
tim e

More than one graph can be plotted on the same figure using a combination of plot and step:

Control Systems and Matlab 3


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')

s tep response
1.6

1.4

1.2

1
output

0.8

0.6

0.4

0.2

0
0 5 10 15 20
tim e

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

Frequency Response Bode Diagrams

To plot the Bode diagram we use the command bode(num,den) .


Π.χ. :
% prg16
%bode 1
clc
clear all
clf
num=10;
den=[1 5 5 0];

Control Systems and Matlab 4


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
bode(num,den);

B ode Diagram s

50

-50

P hase (deg); M agnitude (dB )


-100

-150

-100

-200

-300
-2 -1 0 1 2
10 10 10 10 10

Frequency (rad/sec)

As with the root locus plot we can chose the frequencies:


%prg17
%bode 2
clc
clear all
clf
num=10;
den=[1 5 5 0];
w=logspace(-1, 4,100);
bode(num,den,w);
Bode Diagrams

100

-100
Phas e (deg); M agnitude (dB)

-200

-300

-100

-200

-300
-1 0 1 2 3 4
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);

Control Systems and Matlab 5


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS

B ode Diagram s

Gm =8.0 dB (W cg=2.2); P m =25.5 deg. (W cp=1.3)


50

-50

P has e (deg); M agnitude (dB )


-100

-150

-100

-200

-300
-2 -1 0 1 2
10 10 10 10 10

Frequency (rad/sec)

Nichols diagrams

To find the Nichols plot use the command nichols(num,den).


% prg19
clc
clear all
clf
num=10;
den=[1 5 5 0];
nichols(num,den);
ngrid
Nichols
80

60

O 40
pe 0
n- 0.25
Lo 0.5
20 1 -1
op
G 3 -3
6
ai 0 -6
Pm
-12
-20 -20
Gm

-40 -40
- - - - - - -50
Open-Loop Phase
With the Nichols plots we use the ngrid command.

Control Systems and Matlab 6


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
clc
clear all
clf
num=10;
den=[1 5 5 0];
nyquist(num,den);

Ny quis t Diagram s

250

200

150

100
Im aginary A x is

50

-50

-100

-150

-200

-250
-2.5 -2 -1.5 -1 -0.5 0
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

Control Systems and Matlab 7


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS

A 0
0

-5

1
-10 Gm =
0A

-15

-20
-2 -1.8 -1.6 -1.4 -1.2 -1 -0.8 -0.6 -0.4 -0.2 0

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
k
s 2+5 s
Sum Gain T ra n sfe r Fcn

% prg12
% rlocus 1
clc
clear all
num=1;
den=[1 5 0];
rlocus(num,den)

Control Systems and Matlab 8


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
1.5

0.5

Im ag A x is
0

-0.5

-1

-1.5
-6 -5 -4 -3 -2 -1 0 1 2
Real Ax is

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

1
Im ag A x is

-1

-2

-3

-4
-5 -4 -3 -2 -1 0 1 2
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)

Control Systems and Matlab 9


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
8

Im ag Ax is
0

-2

-4

-6

-8
-5 -4 -3 -2 -1 0 1 2
Real Ax is

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
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

Control Systems and Matlab 10


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS

2
Im ag A x is

-2

-4

-6

-8
-5 -4 -3 -2 -1 0 1 2
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 =
x1 x2 x3
x1 -40.40000 -391.00000 -150.00000
x2 1.00000 0 0
x3 0 1.00000 0
b =
u1
x1 1.00000
x2 0
x3 0
c =
x1 x2 x3
y1 0 18.00000 360.00000
d =
u1
y1 0

Control Systems and Matlab 11


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 denominator
A=[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 denominator
num=[1 -5];
den=[1 -6 -3];
[A,B,C,D]=tf2ss(num,den);
printsys(A,B,C,D)

prg5
a =
x1 x2
x1 6.00000 3.00000
x2 1.00000 0

b =
u1
x1 1.00000
x2 0

c =
x1 x2
y1 1.00000 -5.00000

d =
u1
y1 0

Control Systems and Matlab 12


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 9b
a = [6 3;1 0];
b = [1;0];
c = [1 -5];
d = [0];
step(a,b,c,d)
S tep Res pons e

4
A m plitude

0
0 0.16 0.32 0.48 0.64 0.8
Tim e (sec .)

Consider a system that can be described by the following equations:


 x• 
 1  = −1 −1  x1  + 1 1   u1 
 •   6.5 0   x 2  1 0  u2 
x 2 
 y1  1 0  x1 
 y  =  0 1  x 
 2   2 
The step response is:
•  LAPLACE
X = AX + BU  ⇒ sX (s ) = AX (s ) + BU (s ) ⇒ X (s ) = (sI − A) BU (s ) ⇒
−1
  
y = CX  Y (s ) = CX (s )  Y (s ) = CX (s ) 
Y (s )
⇒ Y (s ) = C(sI − A) −1 BU (s ) ⇒ = G(s ) = C(sI − A) −1 B ⇒
U (s )
−1
10 s + 11  11  1 s − 1s 
⇒      = 2  ⇒
01 − 6.5s  10 s + s + 6.5 s + 7.565
 s −1 s 
Y1(s )   s + s + 6.5 s + s + 6.5  U1(s ) 
2 2
⇒  =   ⇒
Y2 (s )  s + 7.5 6 .5  U 2 (s )
 s 2 + s + 6.5 s 2 + s + 6.5 
Y1(s ) s −1 Y (s ) s + 7 .5
= 2 , 2 = 2
U1(s ) s + s + 6.5 U1(s ) s + s + 6.5
Y1(s ) s Y (s ) 6. 5
= 2 , 2 = 2
U 2 ( s ) s + s + 6 .5 U 2 ( s ) s + s + 6 . 5

Control Systems and Matlab 13


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)
Step Response

From: U1 From: U2
0.4

0.2

To: Y 1 0

-0.2
A mplitude

-0.4

1.5
To: Y 2

0.5

0
0 4 8 120 4 8 12

Time (sec.)

If the step response for only one input was wanted:


» step(a,b,c,d,1) or » step(a,b,c,d,2)
Step Response

0.3
Step Response
0.2
0.4
0.1
To: Y 1

0.2
0
To: Y 1

0
-0.1
A mplitude

-0.2 -0.2
Amplitude

-0.4 2

2
1.5
1.5
To: Y 2

1
To: Y 2

1
0.5
0.5

0
0 0 2 4 6 8 10 12
0 2 4 6 8 10 12

Time (sec.) Time (sec.)

Control Systems and Matlab 14


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
k
s 3+6 s 2+1 1 s+6
Sum 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.

1
k
s 3+6 s 2+1 1 s+6
Sum 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.

1
k
s 4+1 .1 s 3+1 0 .3 s 2+5 s
Sum Gain

T ra n sfe r Fcn

Control Systems and Matlab 15


University of Newcastle upon Tyne
School of Electrical, Electronic and Computer Engineering
CONTROL SYSTEMS
2.3 Plot the root locus and find the maximum stable gain. Relate the step response to the CL
pole locations:

s 2+5 s+6
k
s 2+s
Sum Gain
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:

1
k
s 3+6 s 2+2 5 s
Sum Gain
T ra n sfe r Fcn

2.5 Find the gain and phase margin of the above OLTF

3 Produce the Bode, Nyquist and Nichols diagrams for the following systems.
320(s + 1)
G1(s ) =
s(s + 2)(s 2 + 4s + 16)
k
G2 (s ) = , k = 4, 1.5, 0.4
s(s + 1)(s + 2)
k
G3 (s ) = , k = 10, 100
s(s + 1)(s + 5)

Control Systems and Matlab 16

Вам также может понравиться