Sie sind auf Seite 1von 43

Department of Electrical Engineering

Laboratory Manual
Linear Control System

Imperial College of Business Studies Lahore.


Page 1 of 70
Department of Electrical Engineering
List of Experiments
Experiment 1 ........................................................................................................................................................3
Introduction to MATLAB ....................................................................................................................................3
Experiment 2 ......................................................................................................................................................10
Basic SIMULINK concepts ...............................................................................................................................10
Experiment 3 ......................................................................................................................................................28
Time Response Analysis ....................................................................................................................................28
Experiment 4 ......................................................................................................................................................34
Root Locus Design Using MATLAB.................................................................................................................34
Experiment 5 ......................................................................................................................................................36
Introduction to Bode Plots, Phase and Gain Margin ..........................................................................................36
Experiment 6 ......................................................................................................................................................44
Nyquist Stability.................................................................................................................................................44
Experiment 7 ......................................................................................................................................................46
Closed Loop Proportional Control of the Motor ................................................................................................46
Experiment 8 ......................................................................................................................................................48
Closed Loop Proportional-Integral-Derivative Control of the Motor ................................................................48
Experiment 9 ......................................................................................................................................................50
Open Loop Control of the Light .........................................................................................................................50
Experiment 10 ....................................................................................................................................................53
Closed Loop Proportional-Integral-Derivative Control of the Light .................................................................53
Experiment 11 ....................................................................................................................................................55
Closed Loop Proportional-Integral-Derivative Control of the Temperature ......................................................55
Experiment 12 ....................................................................................................................................................57
Introduction to PLC Board Hardware ................................................................................................................57
Experiment 13 ....................................................................................................................................................60
Introduction to STEP 7 MicroWIN SP8 software ..............................................................................................60
Experiment 14 ....................................................................................................................................................67
To implement logic gates ...................................................................................................................................67
Experiment 15 ....................................................................................................................................................69
To monitor PLC analog input.............................................................................................................................69
Experiment 16 ....................................................................................................................................................70
To implement Digital-To-Analog Converter .....................................................................................................70

Page 2 of 70
Department of Electrical Engineering
Experiment 1
Introduction to MATLAB

Contents:
Overview of basic MATLAB environment and features.
Vectors
Functions
Plotting
Polynomials
Matrices
Printing
Using Mfiles in MATLAB
Getting help in MATLAB

MATLAB is an interactive program for numerical computation and data visualization; it is used
extensively by control engineers for analysis and design. There are many different toolboxes
available which extend the basic functions of MATLAB into different application areas; in these
tutorials, we will make extensive use of the Control Systems Toolbox. MATLAB is supported on
Unix, Macintosh, and Windows environments; a student version of MATLAB is available for personal
computers. For more information on MATLAB, contact the MathWorks.

The idea behind these tutorials is that you can view them in one window while running
MATLAB in another window. You should be able to redo all of the plots and calculations
in the tutorials.

Vectors

Let's start off by creating something simple, like a vector. Enter each element of the vector (separated
by a space) between brackets, and set it equal to a variable. For example, to create the vector a, enter
into the MATLAB command window

a = [1 2 3 4 5 6 9 8 7]
MATLAB should return:
a =
1 2 3 4 5 6 9 8 7
Let's say you want to create a vector with elements between 0 and 20 evenly spaced in increments of
2 (this method is frequently used to create a time vector):
t = 0:2:20

t =
0 2 4 6 8 10 12 14 16 18 20
Manipulating vectors is almost as easy as creating them. First, suppose you would like to add 2 to
each of the elements in vector 'a'. The equation for that looks like:
b = a + 2

b =
3 4 5 6 7 8 11 10 9

Page 3 of 70
Department of Electrical Engineering

Now suppose, you would like to add two vectors together. If the two vectors are the same length, it is
easy. Simply add the two as shown below:
c = a + b

c =
4 6 8 10 12 14 20 18 16
Subtraction of vectors of the same length works exactly the same way.
Functions

To make life easier, MATLAB includes many standard functions. Each function is a block of code
that accomplishes a specific task. MATLAB contains all of the standard functions such as sin, cos,
log, exp, sqrt, as well as many others. Commonly used constants such as pi, and i or j for the square
root of -1, are also incorporated into MATLAB.

sin(pi/4)

ans =

0.7071

To determine the usage of any function, type help [function name] at the MATLAB command
window.
MATLAB even allows you to write your own functions with the function command. More
Information about functions is given at the end of the handbook.
Plotting
It is also easy to create plots in MATLAB. Suppose you wanted to plot a sine wave as a function of
time. First make a time vector (the semicolon after each statement tells MATLAB we don't want to
see all the values) and then compute the sin value at each time.
t=0:0.25:7;
y = sin(t);
plot(t,y)

The plot contains approximately one period of a sine wave. Basic plotting is very easy in M ATLAB,
and the plot command has extensive addon capabilities. More Information about Plotting is given at
the end of the handbook.

Page 4 of 70
Department of Electrical Engineering
Polynomials
In MATLAB, a polynomial is represented by a vector. To create a polynomial in MATLAB, simply
enter each coefficient of the polynomial into the vector in descending order. For instance, let's say
you have the following polynomial:

To enter this into MATLAB, just enter it as a vector in the following manner

x = [1 3 15 2 9]

x =
1 3 15 2 9
MATLAB can interpret a vector of length n+1 as an nth order polynomial. Thus, if your polynomial is
missing any coefficients, you must enter zeros in the appropriate place in the vector. For example,

would be represented in MATLAB as:

y = [1 0 0 0 1]
You can find the value of a polynomial using the polyval function. For example, to find the value of
the above polynomial at s=2,
z = polyval([1 0 0 0 1],2)

z =
17
You can also extract the roots of a polynomial. This is useful when you have a high order polynomial
such as

Finding the roots would be as easy as entering the following command;

roots([1 3 -15 -2 9])

ans =
5.5745
2.5836
0.7951
0.7860
Let's say you want to multiply two polynomials together. The product of two polynomials is found
by taking the convolution of their coefficients. MATLAB's function conv that will do this for you.
x = [1 2];
y = [1 4 8];
z = conv(x,y)

z =
1 6 16 16
Dividing two polynomials is just as easy. The deconv function will return the remainder as well as
the result. Let's divide z by y and see if we get x.
[xx, R] = deconv(z,y)

xx =
1 2

Page 5 of 70
Department of Electrical Engineering

R =
0 0 0 0
As you can see, this is just the polynomial/vector x from before. If y had not gone into z evenly, the
remainder vector would have been something other than zero.
Matrices
Entering matrices into MATLAB is the same as entering a vector, except each row of elements is
separated by a semicolon (;) or a return:
B = [1 2 3 4;5 6 7 8;9 10 11 12]

B =
1 2 3 4
5 6 7 8
9 10 11 12

B = [ 1 2 3 4
5 6 7 8
9 10 11 12]

B =
1 2 3 4
5 6 7 8
9 10 11 12
Matrices in MATLAB can be manipulated in many ways. For one, you can find the transpose of a
matrix using the apostrophe key:
C = B'

C =
1 5 9
2 6 10
3 7 11
4 8 12
It should be noted that if C had been complex, the apostrophe would have actually given the complex
conjugate transpose. To get the transpose, use .' (the two commands are the same if the matrix is not
complex).
Now you can multiply the two matrices B and C together. Remember that order matters when
multiplying matrices.
D = B * C

D =
30 70 110
70 174 278
110 278 446

D = C * B

D =
107 122 137 152
122 140 158 176
137 158 179 200
152 176 200 224
Another option for matrix manipulation is that you can multiply the corresponding elements of two
matrices using the .* operator (the matrices must be the same size to do this).
E = [1 2;3 4]
F = [2 3;4 5]
G = E .* F

Page 6 of 70
Department of Electrical Engineering

E =
1 2
3 4

F =
2 3
4 5

G =
2 6
12 20
If you have a square matrix, like E, you can also multiply it by itself as many times as you like by
raising it to a given power.
E^3

ans =
37 54
81 118
If wanted to cube each element in the matrix, just use the element-by-element cubing.
E.^3

ans =
1 8
27 64
You can also find the inverse of a matrix:
X = inv(E)

X =
2.0000 1.0000
1.5000 0.5000
or its Eigen-values:
eig(E)

ans =
0.3723
5.3723
There is even a function to find the coefficients of the characteristic polynomial of a matrix. The
"poly" function creates a vector that includes the coefficients of the characteristic polynomial.
p = poly(E)

p =

1.0000 5.0000 2.0000

Remember that the Eigen-values of a matrix are the same as the roots of its characteristic
polynomial:
roots(p)

ans =
5.3723
0.3723
Using M-files in MATLAB

There are slightly different things you need to know for each platform.

Page 7 of 70
Department of Electrical Engineering
Windows

Running MATLAB from Windows is very similar to running it on a Macintosh. However, you need to
know that your m-file will be saved in the clipboard. Therefore, you must make sure that it is saved
as filename.m
Getting help in MATLAB
MATLAB has a fairly good online help; type
help commandname

for more information on any given command. You do need to know the name of the command that
you are looking for. Here are a few end notes for this section.

You can get the value of a particular variable at any time by typing its name.
B

B =
1 2 3
4 5 6
7 8 9
You can also have more that one statement on a single line, so long as you separate them with either
a semicolon or comma.
Also, you may have noticed that so long as you don't assign a variable a specific operation or result,
MATLAB with store it in a temporary variable called "ans".

The Control Systems Toolbox in MATLAB


By writing the following command the Graphical User interface of the Control Systems toolbox
opens up:
Sisotool

Page 8 of 70
Department of Electrical Engineering

The Siso design tool allows users to modify the system compensator parameters in any way they find
suitable. They can modify the Root loci in the Root locus editor or specify the frequency domain
characteristics using bode or Nyquist plots. They can also numerically feed in the compensator and
see its effect on both the root loci and bode/Nyquist plots.

By pulling the analysis pulldown menu, they can launch the LinearTimeInvariant Viewer in which
they can view the step and impulse response of system parameters.

The Control Systems Toolbox will be discussed further in all the accompanying sections in this
handbook.

Page 9 of 70
Department of Electrical Engineering

Experiment 2
Basic SIMULINK concepts

Contents:
The Control Systems Toolbox in MATLAB
Basic SIMULINK concepts
Starting Simulink
Model Files
Basic Elements
Running Simulations
Building Systems

Simulink is a graphical extension to MATLAB for modeling and simulation of systems. In Simulink,
systems are drawn on screen as block diagrams. Many elements of block diagrams are available,
such as transfer functions, summing junctions, etc., as well as virtual input and output devices such
as function generators and oscilloscopes. Simulink is integrated with M ATLAB and data can be easily
transferred between the programs. In these tutorials, we will apply Simulink to the examples from
the MATLAB tutorials to model the systems, build controllers, and simulate the systems. Simulink is
supported on Unix, Macintosh, and Windows environments; and is included in the student version of
MATLAB for personal computers. For more information on Simulink, contact the MathWorks.
The idea behind these tutorials is that you can view them in one window while running Simulink in
another window. System model files can be downloaded from the tutorials and opened in Simulink.
You will modify and extend these systems while learning to use Simulink for system modeling,
control, and simulation. Do not confuse the windows, icons, and menus in the tutorials for your
actual Simulink windows. Most images in these tutorials are not live they simply display what you
should see in your own Simulink windows. All Simulink operations should be done in your Simulink
windows.
Starting Simulink
Simulink is started from the MATLAB command prompt by entering the following command:
simulink
Alternatively, you can hit the New Simulink Model button at the top of the MATLAB command
window as shown below:

Page 10 of 70
Department of Electrical Engineering
When it starts, Simulink brings up two windows. The first is the main Simulink window, which
appears as:

The second window is a blank, untitled, model window. This is the window into which a new model
can be drawn.
Model Files
In Simulink, a model is a collection of blocks which, in general, represents a system. In addition, to
drawing a model into a blank model window, previously saved model files can be loaded either from
the File menu or from the MATLAB command prompt. As an example, download the following
model file save the file in the directory you are running MATLAB from.
simple.mdl
Open this file in Simulink by entering the following command in the MATLAB command window.
(Alternatively, you can load this file using the Open option in the File menu in Simulink, or by
hitting Ctrl+O in Simulink.)
simple
The following model window should appear.

A new model can be created by selecting New from the File menu in any Simulink window (or by
hitting Ctrl+N).
Basic Elements
There are two major classes of items in Simulink: blocks and lines. Blocks are used to generate,
modify, combine, output, and display signals. Lines are used to transfer signals from one block to
another.
Blocks
There are several general classes of blocks:

• Sources: Used to generate various signals


• Sinks: Used to output or display signals
• Discrete: Linear, discrete-time system elements (transfer functions, state-space models, etc.)

Page 11 of 70
Department of Electrical Engineering
• Linear: Linear, continuous-time system elements and connections (summing junctions, gains,
etc.)
• Nonlinear: Nonlinear operators (arbitrary functions, saturation, delay, etc.)
• Connections: Multiplex, Demultiplex, System Macros, etc.

Blocks have zero to several input terminals and zero to several output terminals. Unused input
terminals are indicated by a small open triangle. Unused output terminals are indicated by a small
triangular point. The block shown below has an unused input terminal on the left and an unused
output terminal on the right.

Lines
Lines transmit signals in the direction indicated by the arrow. Lines must always transmit signals
from the output terminal of one block to the input terminal of another block. On exception to this is a
line can tap off of another line, splitting the signal to each of two destination blocks, as shown
below: (open the model file named split.mdl).

Lines can never inject a signal into another line; lines must be combined through the use of a block
such as a summing junction.
A signal can be either a scalar signal or a vector signal. For SingleInput, SingleOutput systems,
scalar signals are generally used. For MultiInput, MultiOutput systems, vector signals are often used,
consisting of two or more scalar signals. The lines used to transmit scalar and vector signals are
identical. The type of signal carried by a line is determined by the blocks on either end of the line.
Simple Example

The simple model consists of three blocks: Step, Transfer Fcn, and Scope. The Step is a source
block from which a step input signal originates. This signal is transferred through the line in the
direction indicated by the arrow to the Transfer Function linear block. The Transfer Function
modifies its input signal and outputs a new signal on a line to the Scope. The Scope is a sink block
used to display a signal much like an oscilloscope.

Page 12 of 70
Department of Electrical Engineering
There are many more types of blocks available in Simulink, some of which will be discussed later.
Right now, we will examine just the three we have used in the simple model.
Modifying Blocks
A block can be modified by double clicking on it. For example, if you double click on the "Transfer
Fcn" block in the simple model, you will see the following dialog box.

This dialog box contains fields for the numerator and the denominator of the block's transfer
function. By entering a vector containing the coefficients of the desired numerator or denominator
polynomial, the desired transfer function can be entered. For example, to change the denominator to
s^2+2s+1, enter the following into the denominator field:
[1 2 1]
and hit the close button, the model window will change to the following,

which reflects the change in the denominator of the transfer function. The "step" block can also be
double clicked, bringing up the following dialog box.

Page 13 of 70
Department of Electrical Engineering

The default parameters in this dialog box generate a step function occurring at time=1 sec, from an
initial level of zero to a level of 1. (in other words, a unit step at t=1). Each of these parameters can
be changed. Close this dialog before continuing.

The most complicated of these three blocks is the "Scope" block. Double clicking on this brings up a
blank oscilloscope screen.

When a simulation is performed, the signal which feeds into the scope will be displayed in this
window. Detailed operation of the scope will not be covered in this tutorial. The only function we
will use is the auto-scale button, which appears as a pair of binoculars in the upper portion of the
window.
Running Simulations
To run a simulation, we will work with the following model file:
simple2.mdl
Open this file in Simulink. You should see the following model window.

Before running a simulation of this system, first open the scope window by doubleclicking on the
scope block. Then, to start the simulation, either select Start from the Simulation menu (as shown
below) or hit CtrlT in the model window.

Page 14 of 70
Department of Electrical Engineering

The simulation should run very quickly and the scope window will appear as shown below.

Note that the simulation output (shown in yellow) is at a very low level relative to the axes of the
scope. To fix this, hit the auto-scale button (binoculars), which will rescale the axes as shown below.

Note that the step response does not begin until t=1. This can be changed by doubleclicking on the
"step" block. Now, we will change the parameters of the system and simulate the system again.
Doubleclick on the "Transfer Fcn" block in the model window and change the denominator to
[1 20 400]

Page 15 of 70
Department of Electrical Engineering
Rerun the simulation (hit CtrlT) and you should see what appears as a flat line in the scope window.
Hit the auto-scale button, and you should see the following in the scope window.

Notice that the auto-scale button only changes the vertical axis. Since the new transfer function has a
very fast response, it compressed into a very narrow part of the scope window. This is not really a
problem with the scope, but with the simulation itself. Simulink simulated the system for a full ten
seconds even though the system had reached steady state shortly after one second.
To correct this, you need to change the parameters of the simulation itself. In the model window,
select Parameters from the Simulation menu. You will see the following dialog box.

There are many simulation parameter options; we will only be concerned with the start and stop
times, which tell Simulink over what time period to perform the simulation. Change Start time from
0.0 to 0.8 (since the step doesn't occur until t=1.0. Change Stop time from 10.0 to 2.0, which should
be only shortly after the system settles. Close the dialog box and rerun the simulation. After hitting
the auto-scale button, the scope window should provide a much better display of the step response as

Page 16 of 70
Department of Electrical Engineering
shown below.

Building Systems
In this section, you will learn how to build systems in Simulink using the building blocks in
Simulink's Block Libraries. You will build the following system.

First you will gather all the necessary blocks from the block libraries. Then you will modify the
blocks so they correspond to the blocks in the desired model. Finally, you will connect the blocks
with lines to form the complete system. After this, you will simulate the complete system to verify
that it works.
Gathering Blocks
Follow the steps below to collect the necessary blocks:

Page 17 of 70
Department of Electrical Engineering
• Create a new model (New from the File menu or CtrlN). You will get a blank model window.

• Doubleclick on the Sources icon in the main Simulink window.

This opens the Sources window which contains the Sources Block Library. Sources are used to
generate signals. Click here for more information on block libraries.

Page 18 of 70
Department of Electrical Engineering

Drag the Step block from the sources window into the left side of your model window.

• Doubleclick on the Linear icon in the main Simulink window to open the Linear Block
Library window.
• Drag the Sum, Gain, and two instances of the Transfer Fcn (drag it two times) into your
model window arranged approximately as shown below. The exact alignment is not
important since it can be changed later. Just try to get the correct relative positions. Notice
that the second Transfer Function block has a 1 after its name. Since no two blocks may have
the same name, Simulink automatically appends numbers following the names of blocks to
differentiate between them.

Page 19 of 70
Department of Electrical Engineering

• Doubleclick on the Sinks icon in the main Simulink window to open the Sinks window.
• Drag the Scope block into the right side of your model window.

Modify Blocks
Follow these steps to properly modify the blocks in your model.

• Doubleclick your Sum block. Since you will want the second input to be subtracted, enter +
into the list of signs field. Close the dialog box.
• Doubleclick your Gain block. Change the gain to 2.5 and close the dialog box.
• Doubleclick the leftmost Transfer Function block. Change the numerator to [1 2] and the
denominator to [1 0]. Close the dialog box.
• Doubleclick the rightmost Transfer Function block. Leave the numerator [1], but change the
denominator to [1 2 4]. Close the dialog box. Your model should appear as:

Page 20 of 70
Department of Electrical Engineering

• Change the name of the first Transfer Function block by clicking on the words "Transfer
Fcn". A box and an editing cursor will appear on the block's name as shown below. Use the
keyboard (the mouse is also useful) to delete the existing name and type in the new name, "PI
Controller". Click anywhere outside the name box to finish editing.

• Similarly, change the name of the second Transfer Function block from "Transfer Fcn1" to
"Plant". Now, all the blocks are entered properly. Your model should appear as:

Page 21 of 70
Department of Electrical Engineering
Connecting Blocks with Lines
Now that the blocks are properly laid out, you will now connect them together. Follow these steps.

• Drag the mouse from the output terminal of the Step block to the upper (positive) input of the
Sum block. Let go of the mouse button only when the mouse is right on the input terminal.
Do not worry about the path you follow while dragging, the line will route itself. You should
see the following.

• The resulting line should have a filled arrowhead. If the arrowhead is open, as shown below,
it means it is not connected to anything.

You can continue the partial line you just drew by treating the open arrowhead as an output
terminal and drawing just as before. Alternatively, if you want to redraw the line, or if the
line connected to the wrong terminal, you should delete the line and redraw it. To delete a
line (or any other object), simply click on it to select it, and hit the delete key.

• Draw a line connecting the Sum block output to the Gain input. Also draw a line from the
Gain to the PI Controller, a line from the PI Controller to the Plant, and a line from the Plant
to the Scope. You should now have the following.

Page 22 of 70
Department of Electrical Engineering

• The line remaining to be drawn is the feedback signal connecting the output of the Plant to
the negative input of the Sum block. This line is different in two ways. First, since this line
loops around and does not simply follow the shortest (rightangled) route so it needs to be
drawn in several stages. Second, there is no output terminal to start from, so the line has to
tap off of an existing line.

To tap off the output line, hold the Ctrl key while dragging the mouse from the point on the
existing line where you want to tap off. In this case, start just to the right of the Plant. Drag
until you get to the lower left corner of the desired feedback signal line as shown below.

Now, the open arrowhead of this partial line can be treated as an output terminal. Draw a line
from it to the negative terminal of the Sum block in the usual manner.

Page 23 of 70
Department of Electrical Engineering

• Now, you will align the blocks with each other for a neater appearance. Once connected, the
actual positions of the blocks do not matter, but it is easier to read if they are aligned. To
move each block, drag it with the mouse. The lines will stay connected and reroute
themselves. The middles and corners of lines can also be dragged to different locations.
Starting at the left, drag each block, so that the lines connecting them are purely horizontal.
Also, adjust the spacing between blocks to leave room for signal labels. You should have
something like:

• Finally, you will place labels in your model to identify the signals. To place a label anywhere
in your model, double click at the point you want the label to be. Start by double clicking
above the line leading from the Step block. You will get a blank text box with an editing
cursor as shown below

Page 24 of 70
Department of Electrical Engineering

Type an r in this box, labeling the reference signal and click outside it to end editing.

• Label the error (e) signal, the control (u) signal, and the output (y) signal in the same manner.
Your final model should appear as:

• To save your model, select Save As in the File menu and type in any desired model name.

Simulation
Now that the model is complete, you can simulate the model. Select Start from the Simulation
menu to run the simulation. Doubleclick on the Scope block to view its output. Hit the autoscale
button (binoculars) and you should see the following.

Page 25 of 70
Department of Electrical Engineering

Taking Variables from MATLAB


In some cases, parameters, such as gain, may be calculated in M ATLAB to be used in a Simulink
model. If this is the case, it is not necessary to enter the result of the MATLAB calculation directly
into Simulink. For example, suppose we calculated the gain in MATLAB in the variable K. Emulate
this by entering the following command at the MATLAB command prompt.
K=2.5
This variable can now be used in the Simulink Gain block. In your Simulink model, DoubleClick on
the Gain block and enter the following in the Gain field.
K

Close this dialog box. Notice now that the Gain block in the Simulink model shows the variable K
rather than a number.

Page 26 of 70
Department of Electrical Engineering
Now, you can rerun the simulation and view the output on the Scope. The result should be the same
as before.

Now, if any calculations are done in MATLAB to change any of the variab used in the Simulink
model, the simulation will use the new values the next time it is run. To try this, in M ATLAB, change
the gain, K, by entering the following at the command prompt.
K=5
Start the Simulink simulation again, bring up the Scope window, and hit the auto-scale button. You
will see the following output which reflects the new, higher gain.

Besides variab, signals, and even entire systems can be exchanged between MATLAB and Simulink

Page 27 of 70
Department of Electrical Engineering

Experiment 3
Time Response Analysis

What is the Time Response … ?


It is an equation or a plot that describes the behavior of a system and contains many information
about it with respect to time response specification as overshooting, settling time, peak time, rise
time and steady state error. Time response is formed by the transient response and the steady state
response.
Time response = Transient response + Steady state response
Transient time response (Natural response) describes the behavior of the system in its first short time
until it arrives the steady state value and this response will be our study focus.
If the input is step function the output or the response is called step time response and if the input is
ramp, the response is called ramp time response … etc.

Step time response specification :

• Percent overshoot %OS: is the maximum fraction by which the response overshoots
the steady state value expressed as a percentage. This characteristic is not found in a
first order system and found in higher one for underdamped step response.
• Settling time Ts : is the time required to fall within a certain percentage of the steady
state value for a step input. For example the amount of time required for the step
response to reach and stay within 2% of the steady state value OR in other words we
can define it as the smallest amount of time required to reach the steady state value.
• Peak time Tp : is the time required for the underdamped step response to reach the
first maximum peak.
• Rise time Tr: is the time required for the step response to go from 10% to 90% of the
final value.
• Steady state error : is the difference between the input and the output of a system
after the natural response has finished.

Page 28 of 70
Department of Electrical Engineering
• DC Gain : The DC gain is the ratio of the steady state step response to the magnitude
of a step input. For example if your input is step function with amplitude = 1 and
found the step response output = 5 then the DC gain = 5/1 = 5. In other words it is the
value of the transfer function when s=0.

Step time response :


We know that the system can be represented by a transfer function which has poles ( values make the
denominator equal to zero), depending on these poles the step response divided into four cases:
1. Underdamped response:
In this case the response has an overshooting with a small oscillation which results from
complex poles in the transfer function of the system.
2. Critically response:
In this case the response has no overshooting and reach the steady state value (final value)
in the fastest time. In other words it is the fastest response without overshooting and is
resulted from the existence of real & repeated poles in the transfer function of the system.
3. Overdamped response :
In this case no overshooting will appear and reach the final value in a time larger than
critically case. This response is resulted from the existence of real & distinct poles in the
transfer function of the system.
4. Undamped response :
In this case a large oscillation will appear at the output and will not reach a final value and
this because of the existence of imaginary poles in the transfer function of the system and
the system in this case is called "Marginally stable".

Characteristic of various systems :

❖ First Order system :

Page 29 of 70
Department of Electrical Engineering
The first order system can take the general form
b K dc
G (s) = =
( s + a ) (t.s + 1)
b
DC Gain is = K dc by setting s=0 in the transfer function.
a
Time constant t : is the time to reach 63% of the steady state value for a step input or to
1
decrease to 37% of the initial value and t = . And it is special for first order system only.
a
2 .2
Rise time : Tr =
a
4
Settling time : Ts =
a
The first order systems has no overshooting but can be stable or not depending on the location of its
pole.
The first order system has a single pole at -a. If the pole is on the negative real axis (LHP),
then the system is stable. If the pole is on the positive real axis (RHP), then the system is not
stable. The zeros of a first order system are the values of s which makes the numerator of the
transfer function equal to zero.

❖ Second Order system :


The general form of second order system is :
K dc . n
2
a
G( s) = 2 = 2
( s + bs + c) ( s + 2n s +  n 2 )
Natural frequency ωn is the frequency of oscillation of the system without damping.
b
Damping Ratio ξ =
2 n
Note that the system has a pair of complex conjugate poles at:

S = − n  j n 1 −  2 = −  j , ω : damped frequency of oscillation


a
DC Gain is = K dc
c


1− 2
Percent overshoot OS % = e  100
4 4
Settling time Ts = =
 n 

Peak time Tp =
n 1 −  2

** More details about step response for second order systems are in the appendix.

Matlab commands:

Page 30 of 70
Department of Electrical Engineering
• step : This command is used to plot the step response of a system. For example we would to
plot the step response of the following systems:

1. Transfer function:
9
H ( s) =
s + 2s + 9
2

num=[9];
den=[1 2 9];
step (num,den)
%Another way
Sys=tf (num,den);
step (Sys)

Step Response
1.4

1.2

0.8
Amplitude

0.6

0.4

0.2

0
0 1 2 3 4 5 6
Time (sec)

2. State space model :

_ 
 x1  = − 0.5 − 0.7  x1  +  1 u (t )
 _   0.5 0   x2  − 1
 x2 
x 
y(t ) = 2 6.5 1  + 0u (t )
 x2 

a=[-0.5 -0.7 ; 0.5 0];


b=[1 ; -1];
c=[2 6.5];
d=0;
step (a,b,c,d)
%Another way
Page 31 of 70
Sys= ss (a,b,c,d);
step(Sys)
Department of Electrical Engineering
Step Response
6

2
Amplitude

-1

-2

-3
0 5 10 15 20 25
Time (sec)

Simulink:
We can do the same work by simulink in Matlab :

❖ Components :
For most of the systems we will encounter, we only need to be concerned with a small fraction of
Simulink’s Component library. In particular, the components you should be familiar with are:
• ”Continuous” library
Integrator – integrates a signal
State-Space – used to add a system block in state-space form
Transfer Fcn – used to add a system block in transfer function form
• ”Math Operations” library
Gain – a constant gain
Sum – used to add two or more signals
• ”Sinks” library
Scope – used for viewing system output
To workspace – used to transfer a signal to MATLAB
• ”Sources” library
Ramp–generates a ramp signal
Sine Wave–generates a sinusoid
Step–generates a unit step signal

1. Transfer Function (the above one)

9
s2 +2s+9
Step Transfer Fcn Scope

Page 32 of 70
Department of Electrical Engineering

Double click on Transfer Fcn and enter the numerator & denominator of it.
• You can determine the period of simulation by changing the simulation stop
time in the toolbar. Change it to 10 sec.
• After simulate the model, the result will appear in the "scope" and by double
click on it and pressing "Auto scale" the response can be seen better.

2. State Space Model (the above one)

x' = Ax+Bu
y = Cx+Du
Step1 State-Space Scope1

Notes :
• Consider the previous notes
• Double click on "State-Space" and enter the four matrices A,B,C & D.
******************************************************************
****************
Exercises :

1. For the following system :


2
H (s) =
s + 2 n s + 1
2

a. Let ωn = 1, Obtain the poles of the system for ξ = 0, 0.1, 0.7, 1, 5 and guess the behavior
of step response for every value with explanation.
b. Plot the step response for every ξ above and obtain the behavior of it from the graph with
explanation.
c. Let ωn = 1 , ξ = 0.8. Plot the step response and obtain the OS%, Ts, Tp, S.S.E & DC gain
by : 1. from the graph
2. mathematical by equations.

Page 33 of 70
Department of Electrical Engineering

Experiment 4
Root Locus Design Using MATLAB

A compensator design using the root locus method can be done completely in MATLAB with the
tool “rltool”.
Once the compensator gains have been designed, one should always test the closed loop system
using Simulink before hardware implementation. This is recommended in case errors have been
made in the formulation of the controller.
Experimental Procedure
Experiment 1: Root Locus Design with a Proportional Compensator Only
The open loop hydraulic motor system that utilized the BD90 valve, as identified in Lab 2 at 300 psi,
should have a time constant of about 50 ms and a steady state gain of about 0.60. In this first
exercise, we desire the time constant to be 25 ms. Thus, we close the loop and implement a
proportional only controller because there is no requirement on the steady state error or overshoot.
Save all data as you work in c:\ME460\yourlogin. This includes any M-files, should you choose to use
them.
• First, draw a block diagram of the closed loop system with a proportional controller Kc on paper.
Use symbolic names for the values of the other gains as well. Remember, we are modeling the
physical system so you must incorporate the various calibration parameters into the block diagram.
Refer to Figure 1 at the end of this document.

Using block diagram algebra or any other acceptable method, find the closed loop transfer function
of the system.
• Specify the plant transfer function in MATLAB using the function tf(num, den).

ex) type “G = tf([1 2],[1 0 10])” in command window to specify a transfer function as follows

s+2
𝐺(𝑠) =
s2+ 10

• Run rltool by type it in the command window.


• In the menu file, you can import the plant transfer function into rltool
• You can specify a controller in the tab, Compensator Editor of the window, Control and Estimation
Tool Manager. You can add poles/zeros, and adjust gain of the controller.
• You can also adjust controller using the window, SISO Design for SISO Design Task. Here you can
specify the poles/zeros and gain using graphical user interface. You can change location of
poles/zeros by dragging them in the root locus plot.
• In this 1st exercise, the controller is a proportional controller. So there is no need to add pole/zero.
• Once you have specified controller, you have a root locus plot which relates pole location to
specific Kc values for given controller and plant. A grid of damping and natural frequency is
available in the root locus. The grid is activated by right click on the plot and select Grid.
• By adjusting controller gain, you can determine a gain which satisfies the design requirement. In
this first exercise, we desire the time constant to be 25 ms.
• Using Simulink, create a model of this controlled system and simulate the compensated step
response of the hydraulic motor to a step input of 800 RPM. Set the fixed time step in the
Simulation/Parameters menu at 1 ms and then plot the output and reference.

Next, we will implement this controller on the actual system.

Page 34 of 70
Department of Electrical Engineering
• Modify the template N:\HydraulicsLab\ME460\rloc_template.mdl so that it is the proportional
controller just designed. Save it in c:\ME460\yourlogin. Just like in Lab 3 run your real-time
Simulink model.
• Make the physical connections such as the wiring between the MW2000 and the tachometer output,
and the hose connections for the BD90 valve and the hydraulic motor. Reread the Trainer Stand
Usage & Overview handout if you don’t remember how to do the above.
• Have an instructor check the block diagram, wiring and hosing.

Start the system and start the controller. Obtain a good response for a step input of 800 RPM. Save
the data in c:\ME460\yourlogin.
• Stop the hydraulics.
• Plot the data and the simulated response on the same plot. Be sure to account for any time delay.
Label, title and save the figure.

Lab Report
1. Include all plots created and saved during lab in your lab report.

2. While there is too much uncertainty and variation in the system for the actual and simulated
responses to correspond exactly, they should have the same qualitative ‘shape’. In some cases the
actual step response may exhibit different ‘shape’ features when compared to the simulated response.
Why? Use the plots from both the proportional only and PI compensated systems in formulating an
answer.

3. Theoretically, the system’s response (i.e. ωn or τ) can be made to be arbitrarily fast simply by
increasing the proportional gain and perhaps the ratio Ki/Kc. In practice, this is not true. Why not?

Page 35 of 70
Department of Electrical Engineering

Experiment 5
Introduction to Bode Plots, Phase and Gain Margin

In this lab, concepts of Bode Plots, Phase Margin and Gain Margin will addressed
using MATLAB.
Introduction:
The frequency response method may be less intuitive than other methods you have studied
previously. However, it has certain advantages, especially in real-life situations such as modeling
transfer functions from physical data.
The frequency response of a system can be viewed two different ways: via the Bode plot or via
the Nyquist diagram. Both methods display the same information; the difference lies in the way
the information is presented. We will explore both methods during this lab exercise.
The frequency response is a representation of the system's response to sinusoidal inputs at
varying frequencies. The output of a linear system to a sinusoidal input is a sinusoid of the same
frequency but with a different magnitude and phase. The frequency response is defined as the
magnitude and phase differences between the input and output sinusoids. In this lab, we will see
how we can use the open-loop frequency response of a system to predict its behavior in closedloop.
To plot the frequency response, we create a vector of frequencies (varying between zero or "DC"
and infinity i.e., a higher value) and compute the value of the plant transfer function at those
frequencies. If G(s) is the open loop transfer function of a system and  is the frequency vector,
we then plot G( j) vs.  . Since G( j) is a complex number, we can plot both its magnitude
and phase (the Bode plot) or its position in the complex plane (the Nyquist plot).
List of Equipment/Software
Following equipment/software is required:
• MATLAB
Category Soft Experiment
Deliverables
A complete lab report including the following:
• Figures with plots of all the frequency responses along with the MATLAB codes.
Bode Plots
As noted above, a Bode plot is the representation of the magnitude and phase of G( j) (where
the frequency vector  contains only positive frequencies). To see the Bode plot of a transfer
function, you can use the MATLAB "bode" command. For example,
num = 50;
den = [1 9 30 40];
sys = tf(num,den);
bode(sys)
This displays the Bode plots for the transfer function:
50
𝑠^3 + 9 s^2 + 30 s + 40

Page 36 of 70
Department of Electrical Engineering

Please note the axes of the figure. The frequency is on a logarithmic scale, the phase is given in
degrees, and the magnitude is given as the gain in decibels.
Note: a decibel is defined as 20*log10 ( |G(j*w| )
Gain and Phase Margin
Let's say that we have the following system:

where K is a variable (constant) gain and G(s) is the plant under consideration. The gain margin
is defined as the change in open loop gain required to make the system unstable. Systems with
greater gain margins can withstand greater changes in system parameters before becoming
unstable in closed loop.
Note: Unity gain in magnitude is equal to a gain of zero in dB.
The phase margin is defined as the change in open loop phase shift required to make a closed
loop system unstable.
The phase margin also measures the system's tolerance to time delay. If there is a time delay
greater than 180/ωPC in the loop (where PC ω is the frequency where the phase shift is 180 deg),
the system will become unstable in closed loop. The time delay can be thought of as an extra
block in the forward path of the block diagram that adds phase to the system but has no effect on
the gain. That is, a time delay can be represented as a block with magnitude of 1 and phase
ω *time_delay (in radians/second).

Page 37 of 70
Department of Electrical Engineering
The phase margin is the difference in phase between the phase curve and -180 deg at the point
corresponding to the frequency that gives a gain of 0dB (the gain cross over frequency, gc ω ).
Likewise, the gain margin is the difference between the magnitude curve and 0dB at the point
corresponding to the frequency that gives a phase of -180 deg (the phase cross over
frequency, PC ω ).

When changing the gains, the phase margin plots do not require to update all Bode curves in
order to find the new phase margin. Multiplying the system by a gain shifts the magnitude plot
up or down. Finding the phase margin is a simple matter of finding the new cross-over
frequency. For example, suppose you entered the command bode(sys). You will get the
following bode plot:

Page 38 of 70
Department of Electrical Engineering

You should see that the phase margin is about 100 degrees. Now suppose you added a gain of
100, by entering the command bode(100*sys). You should get the following plot (note we
changed the axis so the scale would be the same as the plot above, your bode plot may not be
exactly the same shape, depending on the scale used):

As you can see the phase plot is exactly the same as before, and the magnitude plot is shifted up
by 40dB (gain of 100). The phase margin is now about -60 degrees. This same result could be
achieved if the y-axis of the magnitude plot was shifted down 40dB. Try this, look at the first
Bode plot, find where the curve crosses the -40dB line, and read off the phase margin. It should

Page 39 of 70
Department of Electrical Engineering

be about -60 degrees, the same as the second Bode plot.


We can find the gain and phase margins for a system directly, by using MATLAB. Just use the
margin command. This command returns the gain and phase margins, the gain and phase cross
over frequencies, and a graphical representation of these on the Bode plot. MATLAB can
determine the phase margin using margin(sys)
>>margin(sys)

Bandwidth Frequency
The bandwidth frequency is defined as the frequency at which the closed-loop magnitude
response is equal to -3 dB. However, when we design via frequency response, we are interested
in predicting the closed-loop behavior from the open-loop response. Therefore, we will use a
second-order system approximation and say that the bandwidth frequency equals the frequency
at which the open-loop magnitude response is between -6 and - 7.5dB, assuming the open loop
phase response is between -135 deg and -225 deg. For a complete derivation of this
approximation, consult your textbook.
In order to illustrate the importance of the bandwidth frequency, we will show how the output
changes with different input frequencies. We will find that sinusoidal inputs with frequency less
than Wbw (the bandwidth frequency) are tracked "reasonably well" by the system. Sinusoidal
inputs with frequency greater than Wbw are attenuated (in magnitude) by a factor of 0.707 or
greater (and are also shifted in phase).
Let's say that we have the following closed-loop transfer function representing a system:

Page 40 of 70
Department of Electrical Engineering

1
---------------
s^2 + 0.5 s + 1
First of all, let's find the bandwidth frequency by looking at the Bode plot:
num = 1;
den = [1 0.5 1];
sys = tf(num,den);
bode (sys)

Since this is the closed-loop transfer function, our bandwidth frequency will be the frequency
corresponding to a gain of -3 dB. looking at the plot, we find that it is approximately 1.4 rad/s.
We can also read off the plot that for an input frequency of 0.3 radians, the output sinusoid
should have a magnitude about one and the phase should be shifted by perhaps a few degrees
(behind the input). For an input frequency of 3 rad/sec, the output magnitude should be about -
20dB (or 1/10 as large as the input) and the phase should be nearly -180 (almost exactly out-
ofphase).
We can use the "lsim" command to simulate the response of the system to sinusoidal
inputs.
First, consider a sinusoidal input with a frequency lower than Wbw. We must also keep in
mind that we want to view the steady state response. Therefore, we will modify the axes in order
to see the steady state response clearly (ignoring the transient response).
w = 0.3;
num = 1;
den = [1 0.5 1];
sys = tf(num,den);
t = 0:0.1:100;
u = sin(w*t);
[y,t] = lsim(sys,u,t);

Page 41 of 70
Department of Electrical Engineering
plot(t,y,t,u)
axis([50,100,-2,2])

Note that the output (blue) tracks the input (purple) fairly well; it is perhaps a few degrees behind
the input as expected.
However, if we set the frequency of the input higher than the bandwidth frequency for the
system, we get a very distorted response (with respect to the input):
w = 3;
num = 1;
den = [1 0.5 1];
sys = tf(num,den);
t = 0:0.1:100;
u = sin(w*t);
[y,t] = lsim(sys,u,t);
plot(t,y,t,u)
axis([90, 100, -1, 1])

Again, note that the magnitude is about 1/10 that of the input, as predicted, and that it is almost
exactly out of phase (180 degrees behind) the input. Feel free to experiment and view the
Page 42 of 70
Department of Electrical Engineering
response for several different frequencies w, and see if they match the Bode plot.
Closed-loop performance
In order to predict closed-loop performance from open-loop frequency response, we need to have
several concepts clear:
 The system must be stable in open loop if we are going to design via Bode plots.
 If the gain cross over frequency is less than the phase cross over frequency (i.e. Wgc <
Wpc), then the closed-loop system will be stable.
 For second-order systems, the closed-loop damping ratio is approximately equal to the
phase margin divided by 100 if the phase margin is between 0 and 60 deg. We can use
this concept with caution if the phase margin is greater than 60 deg.
 For second-order systems, a relationship between damping ratio, bandwidth frequency
and settling time exists.
 A very rough estimate that you can use is that the bandwidth is approximately equal to
the natural frequency.
Let's use these concepts to design a controller for the following system:

Where Gc(s) is the controller and G(s) is:


10
----------
1.25s + 1
The design must meet the following specifications:
 Zero steady state error.
 Maximum overshoot must be less than 40%.
 Settling time must be less than 2 secs.
There are two ways of solving this problem: one is graphical and the other is numerical. Within
MATLAB, the graphical approach is best, so that is the approach we will use. First, let's look at
the Bode plot. Create an m-file with the following code:
num = 10;
den = [1.25,1];
sys = tf(num,den);
bode(sys)

Page 43 of 70

Das könnte Ihnen auch gefallen