Control System Toolbox For Matlab: Intro
Control System Toolbox For Matlab: Intro
Control System Toolbox For Matlab: Intro
Intro
Matlab has a number of add-on packages called toolboxes. The Control Toolbox contains
suite of functions and system model representations that make it easy to create and
analyze linear dynamic systems. The Control Toolbox will be found on most university
installations of Matlab but must be purchased separately for the Student Version of
Matlab. At the end of this documents are a number of examples.
H ( s ) = ( s + 1) /( s + 2)
H ( s ) = (3s 2 ) /( 2 s 2 + 6 s + 3)
>> sys1
>> sys2
Another way to enter system models that are specified in transfer function form is to
define 's' as the complex variable used in transfer functions, and then type in the transfer
function directly.
>> s = tf('s');
New, just type in your transfer function. Here are two examples.
3s 2
H ( s) =
2s 2 + 6s + 3
1
G ( s) =
( s + 5)( s + 2) 2
You can create a new system that represents the parallel interconnection of two systems
by adding them together
Or, a system which represents a cascade of two systems by multiplying them together
System analysis
To find the poles, zeros and gain of system sys:
>> pole(sys)
>> zero(sys)
>> dcgain(sys)
>> pzmap(sys)
>> damp(sys)
>> step(sys)
>> impulse(sys)
The above form takes a guess at how far out to plot the response. If you want the
response to stop at a specific time t, use
>> step(sys,t)
To create a custom plot, store the output of step as shown in this script file
[y,t] = step(sys);
plot(t,y)
xlabel(‘Time’)
ylabel(‘Step response’)
To create step responses out to time=stoptime of several systems sys1, sys2, …, sysN on
one figure use
>> initial(sys,x0)
>> bode(sys)
To get the numbers out of a Bode plot without drawing the plot use
>> [mag,phase]=bode(sys)
>> bode(sys,{wmin,wmax})
To build the closed loop transfer function of a feedback system where system s1 is in the
forward path and s2 is in the negative feedback path
+
S1
>> sCL = feedback(s1,s2) -
S2
For a closed-loop system with unity-gain feedback (i.e. nothing in the feedback path) use
+
S1
>> sCL = feedback(s1,1) -
For a closed loop system with a controller Gc in front of a plant Gp in a unity gain
feedback path (the most common configuration for P, PD, PID control) use
+
Gc Gp
>> sCL = feedback(Gc*Gp,1) -
Once you have and open or closed loop system, sys, the following analysis function are
useful:
>> rlocus(Gc*Gp)
The resulting plot shows the positions of the closed-loop poles on the s-plane as K, the
gain in front of your compensator, varies from zero to infinity. To find the value of K for
any particular position, click on the pole plot and a popup window tells you K. Click and
drag to see information about any part of the plot. For example, you might want to see
what the value of K is for any pole which is just crossing into the right half plane. Note
that for a P control, Gc = 1 so you just need rlocus(Gp)
LTIVIEW
The control toolbox includes LTIVIEW a handy utility for examining several aspects of a
system. To start the viewer
>> ltiview
Select File > Import and a dialog box opens listing all systems in your current Matlab
workspace. Click on one to bring it into ltiview.
Select Edit > Plot Configurations and pick the 2 by 2 matrix of plot windows. Using the
Response type entry boxes on the right, have plots 1 thru 4 show step, impluse, bode and
pole/zero representations of the system. Enlarge the plot window so you can see all
representations. Right click on the step or bode plots and select Characteristics to
measure system properties. Left clicking on data points brings up additional information
about the system.
>> sisotool(Gp)
Select File > Import to input other plant models or to import your compensator. Change
controller gain by entering a number in the C(s) box, or by dragging handles in the root
The following demonstrates how you can use the Control Toolbox of Matlab to conduct a
parameter study showing how the natural frequency affects the step response. In this case
we examine the system described by the transfer function
ω n2
H (s) =
s 2 + 2ξω n s + ω n2
We put ω n2 in the numerator so that the steady state gain of the transfer function (which
you can find by setting s = 0 ) is one, which means all the steps will line up in amplitude.
The first .m file shown is a script to plot one step response. Edit the file to change zeta or
wn, save, and run to get different values of damping and natural frequency.
The second .m file and plot shows how you can plot the step response with four different
values of the natural frequency. The .m file demonstrates several useful Matlab tricks.
Notice how the frequency values are defined as a vector a. By putting a(k) in the loop, we
can successively grab the different frequency values and put in the transfer function. The
vector marker is used to make different line style for each successive plot. In Matlab type
“help plot” to see how the marker styles work. The initial ‘k’ means to plot every line in
black which is just what you want if you don’t have a color printer. The marker vector is
set up with semicolons because it is an array of strings (characters) where each new word
must be a new row in the matrix. The clf function clears the prior plot. Without it, the
legend command gets messed up. Everything else is relatively ordinary Matlab code.
The third .m file and plot shows how to create a plot with 4 different values of zeta. You
could do the same thing by running a loop where zeta in incremented.
for k = 1:4
wn = a(k); % nat freq;
sys = tf([wn^2], [1 2*zeta*wn wn^2]); % transfer function
[y,t] = step(sys,tstop); % create the step
plot(t,y,marker(k,:))
end
xlabel('Time (sec)')
ylabel('Step response')
title('Effect of wn^2 on step response')
legend('wn=1','wn=2','wn=3','wn=4')
1
Step response
0.8
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7 8 9 10
Time (sec)
z=.1;
sys1=1/(s^2+2*z*s+1);
z=.5;
sys2=1/(s^2+2*z*s+1);
z=.707;
sys3=1/(s^2+2*z*s+1);
z=1;
sys4=1/(s^2+2*z*s+1);
step(sys1,sys2,sys3,sys4,20)
Transfer function:
10
--------------
s^2 + 2 s + 10
>> pole(sys)
ans =
-1.0000 + 3.0000i
-1.0000 - 3.0000i
>> damp(sys)
>> [y1,t1]=step(sys);
>> [y2,t2]=impulse(sys);
step response
1.5
0.5
0
0 1 2 3 4 5 6
impulse response
3
-1
0 1 2 3 4 5 6
Transfer function:
10 s + 10
--------------
s^2 + 2 s + 10
>> pole(sys)
ans =
-1.0000 + 3.0000i
-1.0000 - 3.0000i
>> zero(sys)
ans =
-1
>> [y1,t1]=step(sys);
>> [y2,t2]=impulse(sys);
step response
3
0
0 1 2 3 4 5 6
impulse response
10
-5
0 1 2 3 4 5 6