MATLAB and Simulink for Control Systems
V.SitaramGupta
Control Systems
• Control means to regulate, direct, command, or govern. A system is a
collection, set, or arrangement of elements (subsystems).
• A control system is an interconnection of components forming a system
configuration that will provide a desired system response
• In order to identify, delineate, or define a control system, we introduce
two terms: input and output here
• The input is the stimulus, excitation, or command applied to a control
system, and the output is the actual response resulting from a control
system
Control Systems• Control systems can have more than one input or output
• The input and the output represent the desired response and the actual
response respectively. A control system provides an output or response
for a given input or stimulus, as shown in Fig
• Control system applications are found in robotics, space-vehicle
systems, aircraft autopilots and controls, ship and marine control
systems, intercontinental missile guidance systems, automatic control
systems for hydrofoils, surface-effect ships, and high-speed rail systems
including the magnetic levitation systems
Examples of Control Systems• Residential heating and air-conditioning systems controlled by a thermostat
• The cruise (speed) control of an automobile
• Manual control:
– Opening or closing of a window for regulating air temperature or air quality
– Activation of a light switch to regulate the illumination in a room
– Human controlling the speed of an automobile by regulating the gas supply to
the engine
• Automatic traffic control (signal) system at roadway intersections
• Control system which automatically turns on a room lamp at dusk, and turns it off in
Daylight
• Automatic hot water heater
Control System Configuration
• Block: -A block is a set of elements that can be grouped together, with
overall characteristics described by an input/output relationship as
shown in Fig
• Transfer Function: - The transfer function is a property of the system
elements only, and is not dependent on the excitation and initial
conditions. The transfer function of a system (or a block) is defined as
the ratio of output to input as shown in Fig
Control System Configuration• Open-loop Control System: - Open-loop control systems represent the
simplest form of controlling devices. A general block diagram of open-
loop system is shown in Fig
• Closed-loop (Feedback Control) System: - Closed-loop control systems
derive their valuable accurate reproduction of the input from feedback
comparison.
Control System Terminology
An Introduction to MATLAB
and the Control Systems toolbox
MATLAB• MATLAB is essentially a programming interface that can be used for a
variety of scientific calculations, programming and graphical visualization
• Its basic data element is an array, and its computations are optimized for
this data type, which makes it ideal for problems with matrix and vector
formulations
• MATLAB is also extendible by means of add-on script packages called
toolboxes, which provide application-specific functions for use with
MATLAB
• For this course, we will mostly be using MATLAB’s basic matrix/vector
operations and graphing capabilities in conjunction with the control
system toolbox
Interface
See the text book Analysis and Design of Control System using MATLAB
Examples an MATLAB and Basic Control Systems
Control System Toolbox• Control System Toolbox is a package for MATLAB consisting of tools
specifically developed for control applications
• The package offers data structures to describe common system
representations such as state space models, zero-pole gain and transfer
functions, as well as tools for analysis and design of control systems
• It has a collection of algorithms, written mostly in M-files, that
implements common control system design, analysis, and modeling
techniques
• Here you will get to know the basic commands of Control System
Toolbox. When you have completed this exercise, you should be able to
understand and use Control Systems Toolbox
Control System Toolbox• The most commonly used functions are presented below. You are
encouraged to look through the help files for other functions and options
that you might find useful in future
• Using MATLAB to Create Models: -
• Why Model?
– Represent
– Analyze
• What kind of systems are we interested?
– Single-Input-Single-Output (SISO)
– Linear Time Invariant (LTI)
– Continuous
Control System Toolbox• Three Basic types of model representation for continuous LTI systems
– Transfer Function Representation (TF)
– Zero-Pole-Gain Representation (ZPK)
– State Space Representation (SS)
• Transfer Function Models are created using the function
tf( numerator, denominator) where numerator and denominator are
two vectors containing the coefficients of the polynomials in the
numerator and denominator of the transfer function
Control System Toolbox• State space models are created using the function ss(A,B,C,D) where
A,B,C and D are the matrices forming the state space system
• Zero-Pole-Gain forms of transfer functions, ie
• can be specified directly as zpk(z,p,K) where z and p are the vectors of
zero and pole values in the complex plane (z = [z1 z2 …] and p = [p1 p2
…]), and K is the gain
Control System Toolbox
• The models thus generated can be used in conjunction with the operators
+,- and * to generate new models. sys1 * sys2 produces a series
interconnection from input through sys2 and sys1 (in that order) to the
output. sys1 ± sys2 represent parallel interconnections
• Converting Models:- Control system models can be converted from
one form to the other. The three functions presented above (ss(), tf(),
zpk()) are overloaded to perform arbitrary system conversions. For
example, if sys1 is a state-space model, we can generate an equivalent
transfer function model sys2 by issuing the command
>> sys2 = tf(sys1);
• In addition to these, there are other functions that are used for converting
elements of one form(say, the matrices of a state-space model) to the
elements of another form(say, the numerator and denominator of a
transfer function model: tf2ss, ss2tf, tf2zp, zp2tf, zp2ss, ss2zp
Control System Toolbox
Control System ToolboxSystem Analysis: -
• Once a model has been introduced in MATLAB, we can use a series of
functions to analyze the system.
• Key analyses at our disposal:
– Stability analysis
e.g. pole placement
– Time domain analysis
e.g. response to different inputs
– Frequency domain analysis
e.g. bode plot
Control System ToolboxStability analysis: -
• Stability of a linear system is determined by the location of its poles in
the complex plane. (What is the condition for stability?) Use the
commands ssdata and tfdata to extract the necessary data from the
models, and eig and roots to determine stability of the system
Control System Toolbox
When a system becomes unstable, the output of the system approaches infinity
(or negative infinity) Example: - An example to illustrate the importance of
stability is the control of a nuclear reactor
Control System Toolbox
• Time domain analysis:- in the form of time response of a system to a
specified input can be obtained using the following commands:
– step(sys) plots the step response of a system sys.
– impulse(sys) plots the impulse response of sys
– lsim(sys,input_vector,time_vector,initial_state_vector) plots the response
of sys to an arbitrary input. The elements of input_vector define the values of
the input at times corresponding to the elements of time_vector. The initial
state vector can be specified for state-space models only
– Once a model has been inserted in MATLAB, the step response can be
obtained directly from: step(sys) and etc.,
Control System Toolbox
0 0.5 1 1.5 2 2.5 30
0.2
0.4
0.6
0.8
1
1.2
1.4Step Response
Time (sec)
Am
plitu
de
• MATLAB also caries other useful functions for time domain analysis:– Impulse response impulse(sys)– Response to an arbitrary input e.g. t = [0:0.01:10]; u = cos(t); lsim(sys,u,t)
Control System Toolbox
0 1 2 3 4 5 6 7 8 9 10-1.5
-1
-0.5
0
0.5
1
1.5Linear Simulation Results
Time (sec)
Am
plitu
de
0 0.5 1 1.5 2 2.5 3-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5Impulse Response
Time (sec)
Am
plitu
de
Control System Toolbox• Frequency domain analysis tools: -
– rlocus(sys) plots the root locus of the system sys with variations in gain
– bode(sys) plots the magnitude and phase angle Bode plots
– [Gm,Pm,Wg,Wp] = margin(sys) calculates the gain margin Gm, the phase
margin Pm, and the frequencies corresponding to their occurrence. Issuing
the command margin(sys) alone plots the Bode diagram and marks the
margins on it
– nyquist(sys) plots the Nyquist plot of the system. Note that the loop at
infinity is not represented on the plot
– sisotool(plant,compensator) opens an interactive mode of the root locus
and bode plots, which can be used to modify the compensator and gain to
achieve the desired system characteristics
Control System Toolbox
-60
-40
-20
0
20
Mag
nitu
de (
dB)
10-1
100
101
102
-180
-135
-90
-45
0
Pha
se (
deg)
Bode Diagram
Frequency (rad/sec)
Pole-Zero Map
Real Axis
Imag
inar
y A
xis
-2 -1.8 -1.6 -1.4 -1.2 -1 -0.8 -0.6 -0.4 -0.2 0-5
-4
-3
-2
-1
0
1
2
3
4
5
System: sysPole : -2 + 4.58iDamping: 0.4Overshoot (%): 25.4Frequency (rad/sec): 5
System: sysPole : -2 - 4.58iDamping: 0.4Overshoot (%): 25.4Frequency (rad/sec): 5
Control System Toolbox• Extra: Partial Fraction Expansion: -
Control System Toolbox
State – space tools: -
• ctrb(sys) returns the controllability matrix of a state-space system sys
• obsv(sys) returns the observability matrix of a state-space system sys
• [K,S,E] = lqr(A,B,Q,R) : Linear quadratic regulator design – calculates
optimal gain K for a state space system, based on the optimizing
matrices Q and R provided by the designer
Control System ToolboxSome useful MATLAB commands
SIMULINK Control System• Simulink is a simulation program based upon MATLAB
• There are several ways to define a model. One can work graphically
and connect block diagrams with pre-define blocks
• Alternatively one can give the mathematical description in forms of
differential equations in an m file (the format for programs written in the
MATLAB programming language)
• MATLAB/SIMULINK supports both these representations as well as
combinations. Furthermore one can use descriptions that include a
hierarchy of connected subsystems
SIMULINK Control SystemHow to Start Simulink: -
• Start Matlab 9. Then give the command SIMULINK in MATLAB. This
gives a window with blocks as in Figure
SIMULINK Control SystemA Simple System
• Click on File in the Simulink window and choose New->Model. Click on
the block Continous and move a Transfer Fcn to the new window called
“Untitled”. Do the same with Source->Step Fcn and Sinks->Scope.
Draw arrows (left mouse button) and connect the ports on the block. You
should now have a block diagram as in Figure.
• Choose Simulation->Parameters in the window called “Untitled”. Set
Stop time to 5. Open the window Scope by double clicking on it. Put
Horizontal Range to 6. Start a simulation by Simulation->Start (or by
pressing Ctrl t in the window called “Untitled’)
SIMULINK Control System
How to Change a System To change the system to
you double click on the block Transfer Fcn and change Denominator to [1
0.5 2]. Simulate the new system (Simulation->Start or Ctrl t). Change
parameters in the Simulation menu and the scales in the block Scope until
you are satisfied
SIMULINK Control System• How to Change an Input Signal : -To change the input signal, start
with removing the block Step Fcn by clicking on it and delete it by
using Edit->Cut (or pressing Ctrl x). Replace it by a Sources->Signal
Gen block. Double click on Signal Gen and select signal, amplitude and
frequency. Also change Simulation-> Start->Stop Time to 99999 and
press Simulation->Start. This gives an “infi nite” simulation that can be
stopped by pressing Simulation->Stop (or Ctrl t). Can the amplitude of
the input signal be changed during simulation? Also try to change the
block Transfer Fcn during simulation
SIMULINK Control System• How to Use Matlab Variables in Blocks :- Note that variables defined in the
MATLAB environment can be used in Simulink. Define numerator and
denominator by writing the following in the MATLAB window
– num=[1 1]
– den=[1 2 3 4]
• Change Transfer Fcn->Numerator to num and Denominator to den
• How to Save Results to MATLAB variables To save input and output move
two copies of the block Sinks->To Workspace. Make sure that the “save
format” option is set to “Array”