Você está na página 1de 28

Overheads and Flash lectures

for Introduction to MATLAB


for engineers
Anthony Rossiter
Department of Automatic Control
and Systems Engineering
University of Sheffield
www.shef.ac.uk/acse

© University of Sheffield 2009 This work is licensed under a


Creative Commons Attribution 2.0 License.
Control with MATLAB

Anthony Rossiter
ACS108 (and ACS211)

Department of Automatic
Control and Systems
Engineering
Overview
1.Representation of Laplace transforms
2.Inverse Laplace
3.Block diagrams
4.Time responses

h e se slid e s a ssu m e yo u h a ve th e co n tro lto o lb ox .


Laplace
transforms
Basic tool is tf.m

Consider

 s 2 + 3s + 2
G= 3
 s + 9 s 2 + 27 s + 27
Numerator coefficients
are
[1 3 2]

Denominator

coefficients are
[1 9 27 27]

tf.m takes vectors of

these coefficients.
The final result is clear
TASK
Use MATLAB to define the following
transfer functions.
Answers are on the next slide.

3s + 2 3
G= 3 H= 2
s + 12 s + 48s + 64
2
s +4
 s+5 2( s + 1)
K = 3  M= 2
 s+6 s + 4s
Answers
G=tf([3,2],[1,12,48,64])
H=tf(3,[1, 0,4])
S e e w e e k6 _la p la ce . m
K=3*tf([1 5],[1 6])
A lso h a s o th e r exa m p le s to lo o k a
M=tf([2 2],[1 4 0])


Note it sometimes better to use

commas rather than spaces to


separate coefficients as this is
clearer.
You should try these if you did not

enter them yet.



Extracting
data
How do I get the

numerator
coefficients out of a
transfer function?

Use tfdata.m as
shown here. [The ‘v’
is important]

Two output

arguments are vector


of numerator coef.
and vector
denominator coef.
TASK
Try extracting numerator and

denominator coefficients for all the


transfer functions defined in the
earlier slides.
Forming polynomials
quickly
If you are given roots
of a polynomial
rather than
coefficients, use
poly.m to find2 the
( s + 1)( s + 2) = s + 3s + 2
coefficients.
 s ( s − 4)( s + 1) = s 3 − 3s 2 − 4 s

If you are given the


coefficients and
want the roots, use
TASK
1. What does the following command
do?
H=tf(poly(-2),poly([0,-3 -5]))

2. Enter the transfer function with the

following poles and zeros.


 Poles at {0,-1,-2+j,-2-j}
 Zeros at {1,-2}
s
3. Find the roots of
4
+ 6 s 3
+ 6 s 2
+ 4 s
Inverse
Laplace
The control toolbox

does this numerically,


not analytically.

Two options exist:


−1
• impulse response L [G ( s )]

• step response −1 G ( s )
 L [ ]
The latter is more
 s
common in control
scenarios.

S e e ila p la ce . m fo r a n a lytic in ve rse


Inverse 2
Impulse Response

Laplace 1.8

1.6

1.4

1.2

Amplitude
1

0.8

0.6

0.4

0.2

0
0 0.5 1 1.5
Impulse
TimeResponse
(sec)
0.5

0.45

0.4

0.35

0.3
Amplitude

0.25

0.2

0.15

0.1

0.05

0
0 1 2 3 4 5 6 7
Time (sec)
Extracting the
numerical
 answers
If you want the

numbers, not the


plots use.

To specify the final



2

time of the data 1.8

computed. 1.6

1.4

1.2

Specify time points



1

where you want 0.8

the inverse 0.6

Laplace computed.
0.4

0.2

0
0 0.5 1 1.5


What about step responses
Same syntax as impulse.m
Just write step instead, e.g.

 [y,t]=step(G,tfinal)
TASKS
1.Compute and plot the impulse and step
responses for all the transfer
functions given earlier.
2.Validate your answers by doing some
computations on pen and paper.
3.Take some examples from the ACS114
notes/lectures and form the
impulse/step responses with
MATLAB.
4.Look at week6_laplace.m,
week6_laplace1.m,
week6_laplace2.m
Non-simple input sequences
1.In some cases the input is neither an
impulse or a step but some more
complicated shape.
2.To simulate the response of a transfer
function in this case use lsim.m
3.This function needs enough information
to define the input precisely, that is
pairs of values (input magnitude,
time).
4.It will interpolate between the values
given, so ensure the time gaps are
small to minimise any errors from
Illustratio
n of
lsim.m
1. Define input
values.
2. Define
corresponding
times.
3. Give three
0.8

0.7

arguments, 0.6

G(s), inputs 0.5


Output response

and times.
Input values

0.4

4. Plotting: 0.3

 Note the input 0.2

values in green 0.1

circles and 0
0 0.5 1 1.5 2 2.5 3 3.5 4
Block diagrams
How do I form the closed-

loop transfer functions


with unity negative
feedback?
G

y= r =G c r
Set point to output.
1+ G
1
u=
Set point to input/error. r = Gcu r
1+ G

Use the command


feedback.m
First argument is forward

path, 2nd argument is


feedback path
Block diagrams
with controller
What happens when I

add a compensator ?

GK
y=
Set point to output.
 r =G c r
1 + GK
Set point to input.
K
u = r = Gcu r

1 + GK

For output, forward path


is GK, feedback path is
1.
For input, forward path

is K, feedback path is
G.
TASK
Use MATLAB for find the closed-loop
transfer functions (setpoint to error,
input and output) for the following
arrangements.
Use pen and paper to validate your

programming.
 3   2 2
G = ; K = 1 G = ; K= 
 s+4   ( s + 1)( s + 2) s
 2   2 s + 0.1 
G = ; K = 1 G = ; K= 
 ( s + 1)( s + 2)   s ( s + 2)( s + 3) s + 0. 04 
Extra task

1.How would you use feedback if there


is a compensator H(s) in the
feedback path as indicated in this
figure ? Try it!
2.How would you compute the closed-
loop poles/zeros for the systems
on the previous slide ?
[Hint look at the slide on tfdata.m and

roots.m, or look up pzmap.m (i.e.


[p,z]=pzmap(G) )]
Closed-loop responses
Now you know how to:

1.Enter transfer functions.


2.Build closed-loop transfer functions.
3.Compute step and impulse
responses.

Next job is to look at the impact of


feedback on closed-loop responses.


Closed-
loop
response

Open the file


compare_open_closed.
Output step response
Closed-loop

m
0.6
Open-loop

Amplitude
0.4

0.2

Note how it overlays 0

-0.2

open and closed-


0 0.2 0.4 0.6 0.8 1 1.2
Time (sec)

Input step response


loop 3
Closed-loop
Open-loop

TASK
2
Amplitude


1

compare_open_closed( 0
-0.2 0 0.2 0.4 0.6 0.8 1 1.2

G,K) Time (sec)


TASK
• Look at the file overlaymany.m
This allows you to compare the closed-loop

responses of a single G(s) with various


alternative compensators.
• For example try:
G=tf(1,[1 2 1 0]); K1=1;K2=0.2;K3=0.2*tf([1 0.1],[1
0.02])
overlaymany(G,K1,K2,K3)

• Try some more examples of your choice.


NOTE: Please make sure all the closed-loops are


stable or the figure will be dominated by the


divergent plots.
TASK for ACS108
Set up a function file that allows the user to
tune a suspension system (constants B
and k) , iteratively (use a while loop), to
give the best behaviour in response to a
range of road surfaces, e.g. small steps
and sinusoidal surfaces of various periods
(ie. Equivalent to changing frequency). You
could use subplots to display responses to
different surfaces in a single figure.
You can assume that the response is given

from X(s) where:


1 1 w1 w2
X ( s) = R ( s ); R( s ) = or or or 
Ms + Bs + k
2
s s 2 + w12 s 2 + w22
TASK for ACS108
A summary of the MATLAB code for ACS108
(and ACS114) is covered in
week6_overview_control.m
In module ACS114 you will have been

introduced to some main control concepts


such as feedback loops, block diagrams
and time responses. MATLAB facilitates
your computation of all these things. You
should read the introduction to the control
system toolbox in the help and become
familiar with standard operations.
Put extra emphasis on the commands such

as series, parallel, feedback, connect and


append to see how to construct the
transfer function of a block diagram.
TASK for ACS108
1.Create a file that overlays the open-
loop and closed-loop step responses
of a system G(s) when connected
with unity negative feedback.
– Modify the file it allows a controller to be
included in the closed-loop.
– Modify the file so that it also produces
the closed-loop input responses
(input is output of controller or input
to plant).
2.Write a file that illustrates resonance.
3.Try right-click on a step response and
observe the characteristics available
(e.g. rise time, peak, settling time,
etc.)

This resource was created by the University of Sheffield and released as an open educational resource through the Open

Engineering Resources project of the HE Academy Engineering Subject Centre. The Open Engineering Resources project
was funded by HEFCE and part of the JISC/HE Academy UKOER programme.

 © 2009 University of Sheffield


 This work is licensed under a Creative Commons Attribution 2.0 License.


The JISC logo is licensed under the terms of the Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales Licence.
 All reproductions must comply with the terms of that licence.

The HEA logo is owned by the Higher Education Academy Limited may be freely distributed and copied for educational purposes only, provided that

appropriate acknowledgement is given to the Higher Education Academy as the copyright holder and original publisher.

The name and logo of University of Sheffield is a trade mark and all rights in it are reserved. The name and logo should not be reproduced without the

express authorisation of the University.


 Where Matlab® screenshots are included, they appear courtesy of The MathWorks , Inc.

Você também pode gostar