Control System Lab Manual
Control System Lab Manual
2
EEE 412
Control System Laboratory
Lab Experiment 01: a) Introduction to MATLAB
Objectives: The objective of this exercise will be to introduce you to the concept of mathematical
programming using the software called MATLAB. We shall study how to define variables, matrices etc,
see how we can plot results and write simple MATLAB codes.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
What is MATLAB?
MATLAB is a computer program that combines computation and visualization power that makes it
particularly useful tool for engineers.
MATLAB is an executive program, and a script can be made with a list of MATLAB commands like
other programming language.
MATLAB Stands for MATrix LABoratory.
The system was designed to make matrix computation particularly easy.
The MATLAB environment allows the user to:
manage variables
import and export data
perform calculations
generate plots
develop and manage files to use with MATLAB.
Variables
Variable names:
Must start with a letter
May contain only letters, digits, and the underscore “_”
MATLAB is case sensitive, i.e. one & OnE are different variables.
MATLAB only recognizes the first 31 characters in a variable name.
Assignment statement:
3
Variable = number;
Variable = expression;
Example:
>> tutorial = 1234; % NOTE: when a semi-colon” ; ” is placed at the end of each command, the result is
% not displayed.
>> tutorial = 1234
tutorial =
1234
Special variables:
ans : default variable name for the result
pi: π = 3.1415926…………
eps: e = 2.2204e-016, smallest amount by which 2 numbers can differ.
Inf or inf : ∞, infinity
NaN or nan: not-a-number
Commands involving variables:
who: lists the names of defined variables
whos: lists the names and sizes of defined variables
clear: clears all varialbes, reset the default values of special variables.
clear name: clears the variable name
clc: clears the command window
clf: clears the current figure and the graph window.
Vectors
A row vector in MATLAB can be created by an explicit list, starting with a left bracket, entering the
values separated by spaces (or commas) and closing the vector with a right bracket.
A column vector can be created the same way, and the rows are separated by semicolons.
Example:
>> x = [ 0 0.25*pi 0.5*pi 0.75*pi pi]
x=
0 0.7854 1.5708 2.3562 3.1416 %x is a row vector.
>> y = [ 0; 0.25*pi; 0.5*pi; 0.75*pi; pi] %y is a column vector.
y=
0
0.7854
1.5708
2.3562
3.1416
Vector Addressing – A vector element is addressed in MATLAB with an integer index enclosed in
parentheses.
o Example:
>> x(3)
ans =
1.5708 3rd elements of vector x
The colon notation may be used to address a block of elements.
(start : increment : end)
4
start is the starting index, increment is the amount to add to each successive index, and end is the ending
index. A shortened format (start : end) may be used if increment is 1.
Example:
>> x(1:3)
ans =
0 0.7854 1.5708
NOTE: MATLAB index starts at 1.
Some useful commands:
x = start:end create row vector x starting with start, counting by one, ending at end
x = start:increment:end create row vector x starting with start, counting by increment, ending at or
before end
linspace(start,end,number) create row vector x starting with start, ending at end, having number
elements
length(x) returns the length of vector x
y = x’ transpose of vector x
dot (x, y) returns the scalar dot product of the vector x and y
Matrices
A Matrix array is two-dimensional, having both multiple rows and multiple columns,
similar to vector arrays: it begins with [, and end with]
spaces or commas are used to separate elements in a row
semicolon or enter is used to separate rows.
Example:
>> f = [ 1 2 3; 4 5 6]
f=
123
456
>> h = [ 2 4 6
1 3 5]
h=
246
135
Magic Function
For example you can generate a matrix by entering
>> m=magic(4)
It generates a matrix whose elements are such that the sum of all elements in its rows, columns and
diagonal elements are same
Sum Function
You can verify the above magic square by entering
>> sum(m)
For rows take the transpose and then take the sum
>> sum(m’)
Diag
You can get the diagonal elements of a matrix by entering
>> d=diag(m)
>> sum(d)
Matrix Addressing:
-- matrixname(row, column)
-- colon may be used in place of a row or column reference to select the entire row or column.
5
Some useful commands:
zeros(n) returns a n x n matrix of zeros
zeros(m,n) returns a m x n matrix of zeros
ones(n) returns a n x n matrix of ones
ones(m,n) returns a m x n matrix of ones
rand(n) returns a n x n matrix of random number
rand(m,n) returns a m x n matrix of random number
size (A) for a m x n matrix A, returns the row vector [m,n] containing the number of
rows and columns in matrix
length(A) returns the larger of the number of rows or
columns in A.
Some more commands
Transpose B = A’
Plotting
Plotting Curves:
plot (x,y) – generates a linear plot of the values of x (horizontal axis) and y (vertical axis).
semilogx (x,y) – generate a plot of the values of x and y using a logarithmic scale for x and a linear
scale for y
semilogy (x,y) – generate a plot of the values of x and y using a linear scale for x and a logarithmic
scale for y.
loglog(x,y) – generate a plot of the values of x and y using logarithmic scales for both x and y
6
Multiple Curves:
plot (x, y, w, z) – multiple curves can be plotted on the same graph by using multiple arguments in a
plot command. The variables x, y, w, and z are vectors. Two curves will be plotted: y vs. x, and z vs.
w.
legend (‘string1’, ‘string2’,…) – used to distinguish between plots on the same graph
Multiple Figures:
figure (n) – used in creation of multiple plot windows. place this command before the plot()
command, and the corresponding figure will be labeled as “Figure n”
close – closes the figure n window.
close all – closes all the figure windows.
Subplots:
subplot (m, n, p) – m by n grid of windows, with p specifying the current plot as the pth window
Command Description
grid on Adds dashed grids lines at the tick marks
grid off removes grid lines (default)
grid toggles grid status (off to on, or on to off)
title (‘text’) labels top of plot with text in quotes
xlabel (‘text’) labels horizontal (x) axis with text is quotes
ylabel (‘text’) labels vertical (y) axis with text is quotes
text (x,y,’text’) Adds text in quotes to location (x,y) on the current axes, where (x,y) is in
units from the current plot.
7
Lab Experiment 01: b) Determining Transfer Function from Zeros
and Poles
Objectives: The objective of this exercise will be to obtain a transfer function from given poles and
zeroes using MATLAB.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
A transfer function is also known as the network function is a mathematical representation, in terms of
spatial or temporal frequency, of the relation between the input and output of a (linear time invariant)
system. The transfer function is the ratio of the output Laplace Transform to the input Laplace Transform
assuming zero initial conditions. Many important characteristics of dynamic or control systems can be
determined from the transfer function.
The transfer function is commonly used in the analysis of single-input single-output electronic system, for
instance. It is mainly used in signal processing, communication theory, and control theory. The term is
often used exclusively to refer to linear time-invariant systems (LTI). In its simplest form for continuous
time input signal x(t) and output y(t), the transfer function is the linear mapping of the Laplace transform
of the input, X(s), to the output Y(s).
Zeros are the value(s) for z where the numerator of the transfer function equals zero. The complex
frequencies that make the overall gain of the filter transfer function zero. Poles are the value(s) for z
where the denominator of the transfer function equals zero. The complex frequencies that make the
overall gain of the filter transfer function infinite.
The general procedure to find the transfer function of a linear differential equation from input to output is
to take the Laplace Transforms of both sides assuming zero conditions, and to solve for the ratio of the
output Laplace over the input Laplace.
MATLAB Program
z=input(‘enter zeroes’)
p=input(‘enter poles’)
k=input(‘enter gain’)
[num,den]=zp2tf(z,p,k)
tf(num,den)
Procedure
Write MATLAB program in the MATLAB editor document.
Then save and run the program.
Give the required input.
The syntax “zp2tf(z,p,k)” and “tf(num,den)” solves the given input poles and zeros and
gives the transfer function.
zp2tf forms transfer function polynomials from the zeros, poles, and gains of a system in factored
form.
Now find the output theoretically for the given transfer function and compare it with the output obtained
practically.
8
Example
Given poles are -3.2+j7.8,-3.2-j7.8,-4.1+j5.9,-4.1-j5.9,-8 and the zeroes are -0.8+j0.43,-0.8-j0.43,-0.6 with
a gain of 0.5.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
The transfer function provides a basis for determining important system response characteristics without
solving the complete differential equation. As defined, the transfer function is a rational function in the
complex variable s=σ+jω, that is
𝑏𝑚 𝑠𝑚 + 𝑏𝑚−1 𝑠𝑚−1 + ⋯ … … … … … … + 𝑏0
𝐻(𝑠) =
𝑎𝑛 𝑠𝑛 + 𝑎𝑛−1 𝑠𝑛−1 + ⋯ … … … … … … + 𝑎0
It is often convenient to factor the polynomials in the numerator and the denominator, and to write the
transfer function in terms of those factors:
𝑁(𝑠) (𝑠 − 𝑧1 )(𝑠 − 𝑧2 ) … … … … … (𝑠 − 𝑧𝑚−1 )(𝑠 − 𝑧𝑚 )
𝐻(𝑠) = =𝐾
𝐷(𝑠) (𝑠 − 𝑝1 )(𝑠 − 𝑝2 ) … … … … … (𝑠 − 𝑝𝑚−1 )(𝑠 − 𝑝𝑚 )
where, the numerator and denominator polynomials, N(s) and D(s), have real coefficients defined by the
𝑏
system’s differential equation and 𝐾 = 𝑚 .
𝑎𝑛
MATLAB Program
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
[z,p,k] = tf2zp(num,den)
Example
Obtain the poles and zeros of the transfer function given below:
𝐶(𝑠) 𝑠 2 + 4𝑠 + 3
= 3
𝑅(𝑠) 𝑠 + 3𝑠 2 + 7𝑠 + 5
Procedure
Type the program in the MATLAB editor that is in M-file.
Save and run the program.
Give the required inputs in the command window of MATLAB in matrix format.
tf2zp converts the transfer function filter parameters to pole-zero-gain form.
[z,p,k] = tf2zp(b,a) finds the matrix of zeros z, the vector of poles p, and the associated vector of
gains k from the transfer function parameters b and a:
The numerator polynomials are represented as columns of the matrix b.
The denominator polynomial is represented in the vector a.
Note down the output of the program that is zeros, poles and gain obtained in MATLAB.
The zeros, poles and gain are also obtained theoretically.
9
EEE 412
Control System Laboratory
Lab Experiment 02: Step, Impulse and Ramp Response of a
Transfer Function
Objectives: The objective of this exercise will be to introduce you to the concept of Step, Impulse and
Ramp Response of a Transfer Function
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
Step Response
A step signal is a signal whose value changes from one level to another level in zero time.
Mathematically, the step signal is represented as given below:
r(t)=u(t), where u(t)=1; t>0
=0; t<0
In the Laplace transform form
R(s)=1/s
The step response of the given transfer function is obtained as follows:
T(s)=C(s)/R(s);
So, C(s)=R(s)T(s)
C(s)=T(s)/s
The output is given by
c(t)=L-1[C(s)]
MATLAB Program
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
step(num,den)
Example
Obtain the step response of the transfer function given below:
𝑠(𝑠 + 3)(𝑠 + 4)
𝑇(𝑠) =
(𝑠 + 1)(𝑠 + 2)(𝑠 + 7)(𝑠 + 11)
Procedure
Type the program in MATLAB editor that is in M-file.
Save and run the program.
Give the required inputs in the command window of MATLAB in matrix format.
‘step’ function calculates the unit step response of a linear system.
Zero initial state is assumed in state-space case.
When invoked with no output arguments, this function plots the step response on the screen.
step (sys) plots the response of an arbitrary LTI system.
10
This model can be continuous or discrete, and SISO or MIMO.
The step response of multi-input systems is the collection of step responses for each input channel.
The duration of simulation is determined automatically based on the system poles and zeroes.
Note down the response of the transfer function obtained in MATLAB.
The response of the transfer function is also obtained theoretically.
Both the responses are compared.
Unit Impulse
An impulse signal is a signal whose value changes from zero to infinity in zero time. Mathematically, the
unit impulse signal is represented as given below:
r(t)=δ(t), where δ(t)=1; t=0
=0; t≠0
In the Laplace transform form
R(s)=1
In the Laplace transform form
R(s)=1
The step response of the given transfer function is obtained as follows:
T(s)=C(s)/R(s);
So, C(s)=R(s)T(s)
C(s)=T(s)
The output is given by
c(t)=L-1[C(s)]
MATLAB Program
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
impulse(num,den)
Example
the impulse response of the transfer function given below:
(𝑠 − 1)
𝐻(𝑠) =
(𝑠 + 1)(𝑠 + 2)
Procedure
Type the program in the MATLAB editor that is in M-file.
Save and run the program.
Give the required inputs in the command window of MATLAB in matrix format.
‘impulse’ calculates the impulse response of a linear system.
The impulse response is the response to the Dirac input, δ (t) for continuous time systems and to a
unit pulse at for discrete time systems.
Zero initial state is assumed in the state space case.
When invoked without left hand arguments, this function plots the impulse response on the screen.
‘impulse(sys)’ plots the impulse response of an arbitrary LTI model sys.
This model can be continuous or discrete, SISO or MIMO.
The impulse response of multi-input systems is the collection of impulse responses for each input
channel.
The duration of simulation is determined automatically to display the transient behavior of the
response.
Note down the response of the given transfer function obtained in MATLAB.
The response of the transfer function is also obtained theoretically.
Both the responses are compared.
11
Ramp
A ramp signal is a signal which changes with time gradually in a linear fashion. Mathematically, the unit
ramp signal is represented as given below:
r(t)=tu(t), where u(t)=1; t>0
=0; t<0
In the Laplace transform form
R(s)=1/s2
The step response of the given transfer function is obtained as follows:
T(s)=C(s)/R(s);
So, C(s)=R(s)T(s)
C(s)=T(s)/s2
The output is given by
c(t)=L-1[C(s)]
MATLAB Program
t=0:0.01:10;
u=t;
num = input(‘enter the numerator of the transfer function’)
den = input(‘enter the denominator of the transfer function’)
lsim(num,den,u,t)
Example
Obtain the ramp response of the transfer function given below:
𝑠(𝑠 + 3)(𝑠 + 4)
𝑇(𝑠) =
(𝑠 + 1)(𝑠 + 2)(𝑠 + 7)(𝑠 + 11)
Procedure
Type the program in the MATLAB editor that is in M-file.
Save and run the program.
Give the required inputs in the command window of MATLAB in matrix format.
lsim simulates the (time) response of continuous or discrete linear systems to arbitrary inputs.
When invoked without left-hand arguments, lsim plots the response on the screen.
lsim(sys,u,t) produces a plot of the time response of the LTI model sys to the input time history t,u.
The vector t specifies the time samples for the simulation and consists of regularly spaced time
samples.
t = 0:dt:Tfinal
The matrix u must have as many rows as time samples (length(t)) and as many columns as system
inputs.
Each row u(i,:) specifies the input value(s) at the time sample t(i).
Note down the response of the transfer function obtained in MATLAB.
The response of the transfer function is also obtained theoretically.
Both the responses are compared.
12
EEE 412
Control System Laboratory
Lab Experiment 03: Performance of First Order and Second Order
Systems
Objectives: The objective of this exercise will be to study the performance characteristics of first and
second order systems using MATLAB
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
An electrical RC-circuit is the simplest example of a first order system. It comprises of a resistor and
capacitor connected in series to a voltage supply as shown below on Figure below
If the capacitor is initially uncharged at zero voltage when the circuit is switched on, it starts to charge
due to the current ‘i' through the resistor until the voltage across it reaches the supply voltage. As soon as
this happens, the current stops flowing or decays to zero, and the circuit becomes like an open circuit.
However, if the supply voltage is removed, and the circuit is closed, the capacitor will discharge the
energy it stored again through the resistor. The time it takes the capacitor to charge depends on the time
constant of the system, which is defined as the time taken by the voltage across the capacitor to rise to
approximately 63% of the supply voltage. For a given RC-circuit, this time constant is . Hence its
magnitude depends on the values of the circuit components.
The RC circuit will always behave in this way, no matter what the values of the components. That is, the
voltage across the capacitor will never increase indefinitely. In this respect we will say that the system is
passive and because of this property it is stable. For the RC-circuit as shown in Fig. above, the equation
governing its behavior is given by
where
vc(t) is the voltage across the capacitor, R is the resistance and C is the capacitance. The constant is
the time constant of the system and is defined as the time required by the system output i.e. vc(t) to rise to
63% of its final value (which is E). Hence the above equation (1) can be expressed in terms of the time
constant as:
13
where τ is time constant of the system and the system is known as the first order system. The performance
measures of a first order system are its time constant and its steady state.
Exercise 1:
a) Given the values of R and C, obtain the unit step response of the first order system.
a. R=2KΩ and C=0.01F
b. R=2.5KΩ and C=0.003F
b) Verify in each case that the calculated time constant (𝜏 = 𝑅𝐶) and the one measured
from the figure as 63% of the final value are same.
c) Obtain the steady state value of the system.
The time response has utmost importance for the design and analysis of control systems because these are
inherently time domain systems where time is independent variable. During the analysis of response, the
variation of output with respect to time can be studied and it is known as time response. To obtain
satisfactory performance of the system with respect to time must be within the specified limits. From time
response analysis and corresponding results, the stability of system, accuracy of system and complete
evaluation can be studied easily.
Due to the application of an excitation to a system, the response of the system is known as time response
and it is a function of time. The two parts of response of any system:
(i) Transient response
(ii) Steady-state response.
Transient response: The part of the time response which goes to zero after large interval of time is known
as transient response.
Steady state response: The part of response that means even after the transients have died out is said to be
steady state response.
The total response of a system is sum of transient response and steady state response:
C(t)=Ctr(t)+Css(t)
Consider the following Mass-Spring system shown in the Figure below. Where K is the spring constant,
B is the friction coefficient, x(t) is the displacement and F(t) is the applied force:
The differential equation for the above Mass-Spring system can be derived as follows
provided that, all the initial conditions are zeros. Then the transfer function representation of the system is
given by
for which the transient output, as obtained from the Laplace transform table (Table 2.3, Textbook), is
where 0 < ζ < 1. The transient response of the system changes for different values of damping ratio, ζ.
Standard performance measures for a second order feedback system are defined in terms of step response
of a system. Where, the response of the second order system is shown below.
where MPt is the peak value of the time response, and fv is the final value of the response.
Settling Time: The time required for the system’s output to settle within a certain percentage of the input
amplitude (which is usually taken as 2%). Then, settling time, Ts, is calculated as
15
Exercise 2: Effect of damping ratio ζ on performance measures. For a single-loop second order feedback
system given below
Find the step response of the system for values of ωn = 1 and ζ = 0.1, 0.4, 0.7, 1.0 and 2.0. Plot all the
results in the same figure window and fill the following table.
Rise time Peak Time % Overshoot Settling time Steady state
𝜉 value
0.1
0.4
0.7
1.0
2.0
MATLAB PROGRAM:
clc
clear
num= [9]; den= [1 2 9];
t = 0:0.005:5;
[y,x,t] = step(num,den,t);
grid on
r = 1; while y(r) < 1.0001; r = r + 1; end;
rise_time = (r - 1) *0.005
[ymax,tp] = max(y);
peak_time = (tp - 1) *0.005
max_overshoot = ymax-1
s = 1001; while y(s) > 0.98 & y(s) < 1.02; s = s - 1; end;
settling_time = (s - 1) *0.005
Procedure
Time response of the system is being found when we give the values of natural undamped frequency
and damping ratio.
When we give these values first rise time, peak time, peak overshoot, transfer function are being
calculated.
Then “ step(s)” And “impulse(s)” generates time response of the system.
The hold function determines whether new graphics object is added to the graph or replaces objects in
the graph.
hold on retains the current plot and certain axes properties so that subsequent graphing command add
to the existing graph.
hold off resets axes properties to their defaults before drawing new plots. Hold off is the default
16
EEE 412
Control System Laboratory
Lab Experiment 04: Root Locus Plot from a Transfer Function
Objectives: The objective of this exercise will be to plot the root locus for a given transfer function of the
system using MATLAB.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
rlocus computes the Evans root locus of a SISO open-loop model. The root locus gives the closed-loop
pole trajectories as a function of the feedback gain k (assuming negative feedback). Root loci are used to
study the effects of varying feedback gains on closed-loop pole locations. In turn, these locations provide
indirect information on the time and frequency responses.
rlocus(sys) calculates and plots the rootlocus of the open-loop SISO model sys. This function can be
applied to any of the following feedback loops by setting sys appropriately.
Example
Transfer function = R A N D O M
Procedure
Write MATLAB program in the MATLAB specified documents.
Then save the program to run it.
The input is to be mentioned.
The syntax “h=tf(num,den)” gives the transfer function and is represented as h.
The syntax “rlocus(h)” plots the rootlocus of the transfer function h.
Generally the syntax is of the form
rlocus(sys)
rlocus(sys,k)
rlocus(sys1, sys2, ….)
[r,k] = rlocus(sys)
r = rlocus(sys,k)
17
rlocus(sys) calculates and plots the root locus of the open loop SISO model sys.
Now we have to solve it theoretically.
Now we have to compare the practical and theoretical outputs to verify each other correctly.
18
EEE 412
Control System Laboratory
Lab Experiment 05: Bode Plot from a Transfer Function
Objectives: The objective of this exercise will be to obtain bode plot for a given transfer function of the
system using MATLAB.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
Bode computes the magnitude and phase of the frequency response of LTI models. When invoked
without left-side arguments, bode produces a Bode plot on the screen. The magnitude is plotted in
decibels (dB), and the phase in degrees. The decibel calculation for mag is computed as 20log10(|H(jw)|),
where H(jw) is the system's frequency response. Bode plots are used to analyze system properties such as
the gain margin, phase margin, DC gain, bandwidth, disturbance rejection, and stability.
bode(sys) plots the Bode response of an arbitrary LTI model sys. This model can be continuous or
discrete, and SISO or MIMO. In the MIMO case, bode produces an array of Bode plots, each plot
showing the Bode response of one particular I/O channel. The frequency range is determined
automatically based on the system poles and zeros.
bode(sys,w) explicitly specifies the frequency range or frequency points to be used for the plot. To focus
on a particular frequency interval [wmin,wmax], set w = {wmin,wmax}. To use particular frequency
points, set w to the vector of desired frequencies. Use logspace to generate logarithmically spaced
frequency vectors. All frequencies should be specified in radians/sec.
19
mix of continuous and discrete systems. This syntax is useful to compare the Bode responses of multiple
systems.
return the magnitude and phase (in degrees) of the frequency response at the frequencies w (in rad/sec).
The outputs mag and phase are 3-D arrays with the frequency as the last dimension (see "Arguments"
below for details). You can convert the magnitude to decibels by magdb = 20*log10(mag).
MATLAB Program
num=input('enter the numerator of the transfer function')
den=input('enter the denominator of the transfer function')
h=tf(num,den)
[gm pm wcp wcg]=margin(h)
bode(h)
Example
Transfer function = R A N D O M
Procedure
Write the MATLAB program in the MATLAB editor.
Then save and run the program.
Give the required inputs.
The syntax "bode(h)" solves the given input transfer function and gives the bode plot,
where num,den are the numerator and denominator of the transfer function.
Now plot the bode plot theoretically for the given transfer function and compare it with the plot
obtained practically.
20
EEE 412
Control System Laboratory
Lab Experiment 06: Nyquist Plot from a Transfer Function
Objectives: The objective of this exercise will be to obtain Nyquist plot for a given transfer function of
the system using MATLAB.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
A nyquist plot is used in automatic control and signal processing for assessing the stability of a system
with feedback. It is represented by a graph in polar coordinates in which the gain and phase of a
frequency response are plotted. The plot of these phasor quantities shows the phase as the angle and the
magnitude as the distance from the origin. This plot combines the two types of Bode plot — magnitude
and phase — on a single graph with frequencry as a parameter along the curve.
Nyquist calculates the Nyquist frequency response of LTI models. When invoked without left hand
arguments, nyquist produces a Nyquist plot on the screen. Nyquist plots are used to analyze system
properties including gain margin, phase margin, and stability.
The nyquist stability criterion , provides a simple test for stability of a closed-loop control system by
examining the open-loop system's Nyquist plot. Stability of the closed-loop control system may be
determined directly by computing the poles of the closed-loop transfer function. The Nyquist Criteria can
tell us things about the frequency characteristics of the system. For instance, some systems with constant
gain might be stable for low-frequency inputs, but become unstable for high-frequency inputs. Also, the
Nyquist Criteria can tell us things about the phase of the input signals, the time-shift of the system, and
other important information.
The Nyquist Contour
The nyquist contour, the contour that makes the entire nyquist criterion work, must encircle the entire
right half of the complex s plane. Remember that if a pole to the closed-loop transfer function (or
equivalently a zero of the characteristic equation) lies in the right-half of the s plane, the system is an
unstable system.To satisfy this requirement, the nyquist contour takes the shape of an infinite semi-circle
that encircles the entire right-half of the s plane.
Nyquist Criteria
Let us first introduce the most important equation when dealing with the Nyquist criterion:
N=Z - P
Where:
N is the number of encirclements of the (-1, 0) point.
Z is the number of zeros of the characteristic equation.
P is the number of poles of the characteristic equation.
With this equation stated, we can now state the Nyquist Stability Criterion:
MATLAB Program
num=input(‘enter the numerator of the transfer function’)
den=input(‘enter the denominator of the transfer function’)
h=tf(num,den)
nyquist(h)
[gm pm wcp wcg]=margin(h)
if(wcp>wcg)
disp(‘system is stable’)
else
disp(‘system is unstable’)
end
Procedure
Write MATLAB program in the MATLAB editor document.
Then save and run the program.
Give the required input.
The syntax “tf(num,den)” solves the given transfer function and gives poles and zeros of the function.
“nyquist(sys)”, nyquist calculates the Nyquist frequency response of LTI models. When invoked
without left-hand arguments, nyquist produces a Nyquist plot on the screen. Nyquist plots are used to
analyze system properties including gain margin, phase margin, and stability. “nyquist(sys)” plots the
Nyquist response of an arbitrary LTI model sys.
This model can be continuous or discrete, and SISO or MIMO. In the MIMO case, nyquist produces
an array of Nyquist plots, each plot showing the response of one particular I/O channel. The
frequency points are chosen automatically based on the system poles and zeros.
“[Gm,Pm,Wcg,Wcp] = margin(sys)”, margin calculates the minimum gain margin, phase margin, and
associated crossover frequencies of SISO open-loop models. The gain and phase margins indicate the
relative stability of the control system when the loop is closed.
22
EEE 412
Control System Laboratory
Lab Experiment 07: a) Determining Transfer Function from State
Model
Objectives: The objective of this exercise will be to introduce you to obtain the transfer function from the
state model.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
The transfer function is defined as the ratio of Laplace transform of output to Laplace transform of input.
The transfer function of a given state model is given by:
Transfer Function = C(SI-A)-1B
A state space representation is a mathematical model of a physical system as a set of input, output and
state variables related by first-order differential equations. The state space representation (also known as
the "time-domain approach") provides a convenient and compact way to model and analyze systems with
multiple inputs and outputs.
Unlike the frequency domain approach, the use of the state space representation is not limited to systems
with linear components and zero initial conditions.
"State space" refers to the space whose axes are the state variables. The state of the system can be
represented as a vector within that space. The input state equation is given by,
𝑋̇ = 𝐴𝑋 + 𝐵𝑈
The output equation is written as,
𝑌 = 𝐶𝑋 + 𝐷𝑈
MATLAB Program
A =input(‘enter the matrix A’)
B= input(‘enter the matrix B’)
C = input(‘enter the matrix C’)
D= input(‘enter the matrix D’)
Sys =ss2tf(A,B,C,D)
Example
Obtain the transfer function from the State Model given below:
A=
B=
C=
D=
Procedure
Type the program in the MATLAB editor that is in M-file.
Save and run the program.
23
Give the required inputs in the command window of MATLAB in matrix format.
The command ss2tf(A,B,C,D)) converts the given transfer function into a state model.
Note down the output obtained in MATLAB.
The Transfer Function is also obtained theoretically.
Both the state models are compared.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
There are three methods for obtaining state model from transfer function:
1. Phase variable method
2. Physical variable method
3. Canonical variable method
Out of three methods given above canonical form is probably the most straightforward method for
converting from the transfer function of a system to a state space model is to generate a model in
"controllable canonical form." This term comes from Control Theory but its exact meaning is not
important to us. To see how this method of generating a state space model works, consider the third order
differential transfer function:
𝑌(𝑠) 𝑏0 𝑠 2 + 𝑏1 𝑠 + 𝑏2
𝐻(𝑠) = = 3
𝑈(𝑠) 𝑠 + 𝑎1 𝑠 2 + 𝑎2 𝑠 + 𝑎3
We start by multiplying by Z(s)/Z(s) and then solving for Y(s) and U(s) in terms of Z(s). We also convert
back to a differential equation.
𝑌(𝑠) = (𝑏0 𝑠 2 + 𝑏1 𝑠 + 𝑏2) 𝑍(𝑠) 𝑦 = 𝑏0 𝑧̈ + 𝑏1 𝑧̇ + 𝑏2 𝑧
𝑈(𝑠) = (𝑠 3 + 𝑎1 𝑠 2 + 𝑎2 𝑠 + 𝑎3 )𝑍(𝑠) 𝑢 = 𝑧⃛ + 𝑎1 𝑧̈ + 𝑎2 𝑧̇ + 𝑎3 𝑧
We can now choose z and its first two derivatives as our state variables
𝑞1 = 𝑧 𝑞̇ 1 = 𝑧̇ = 𝑞2
𝑞̇ 2 = 𝑧̈ = 𝑞3
𝑞̇ 3 = 𝑧⃛ = 𝑢 − 𝑎1 𝑧̈ − 𝑎2 𝑧̇ − 𝑎3 𝑧
= 𝑢 − 𝑎1 𝑞3 − 𝑎2 𝑞2 − 𝑎3 𝑞1
Now we just need to form the output
𝑦 = 𝑏0 𝑧̈ + 𝑏1 𝑧̇ + 𝑏2 𝑧
= 𝑏0 𝑞3 + 𝑏1 𝑞2 + 𝑏2 𝑞1
From these results we can easily form the state space model:
24
0 1 0 0
𝒒̇ = 𝐴𝒒 + 𝐵𝒖 = ⟦ 0 0 1 ⟧ 𝒒 + ⟦0⟧ 𝒖
−𝑎3 −𝑎2 −𝑎1 1
𝑦 = 𝐶𝒒 + 𝐷𝒖 = [𝑏2 𝑏1 𝑏0 ]𝒒 + [0]𝒖
MATLAB Program
num=input(‘enter the numerator of the transfer function’)
den=input(‘enter the denominator of the transfer function’)
ss(tf(num,den))
Example
Obtain the state model from the transfer function given below:
T(s)= R A N D O M
Procedure
Type the program in the MATLAB editor that is in M-file.
Save and run the program.
Give the required inputs in the command window of MATLAB in matrix format.
The command ss(tf(num,den)) converts the given transfer function into a state model.
Note down the output obtained in MATLAB.
The state model is also obtained theoretically.
Both the state models are compared.
25
EEE 412
Control System Laboratory
Lab Experiment 08: a) Determining State from Zeroes and Poles
Objectives: The objective of this exercise will be to Determine State from Zeroes and Poles
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
Let’s say we have a transfer function defined as a ratio of two polynomials:
𝑁(𝑠)
𝐻(𝑠) =
𝐷(𝑠)
Where N(s) and D(s) are simple polynomials.
Zeroes are the roots of N(s) (the numerator of the transfer function) obtained by setting N(s)=0 and
solving for s. Poles are the roots of D(s) (the denominator of the transfer function), obtained by setting
D(s)=0 and solving for s.
The state space model represents a physical system as n first order coupled differential equations.
This form is better suited for computer simulation than an nth order input-output differential equation.
The general vector-matrix form of state space model is:
𝑋̇ = 𝐴𝑋 + 𝐵𝑈
Where,
X = state vector
U = input vector
A = n x n matrix
B = n x 1 matrix
The output equation for the above system is,
𝑌 = 𝐶𝑋 + 𝐷𝑈
MATLAB Program
z=input('enter zeros')
p=input('enter poles')
k=input('enter gain')
[A,B,C,D]=zp2ss(z,p,k)
Procedure
Open the MATLAB window and open a new MATLAB editor.
Write the MATLAB program in the MATLAB editor.
Save and run the MATLAB program.
Enter the given poles, zeros and gain as input in matrix format.
The syntax “[A,B,C,D]=zp2ss(z,p,k)” solves zeroes, poles and gain given in the matrix format as
input and gives the output in the form of a state model.
This syntax transforms the given zeros, poles and gain into a state model.
26
Note down the output state model obtained practically by using the syntax “[A,B,C,D]=zp2ss(z,p,k)”.
Now find the state model theoretically for the given poles, zeros and gain.
Compare the theoretically obtained state model from the given poles, zeros and gain with the one
obtained practically. Write the result based on the comparison between thoretical and practical result.
Where,
X = state vector
U = input vector
A = n x n matrix
B = n x 1 matrix
The output equation for the above system is,
𝑌 = 𝐶𝑋 + 𝐷𝑈
MATLAB Program
Example
A=
B=
C=
D=
Procedure
the MATLAB window and open a new MATLAB editor.
Write the MATLAB program in the MATLAB editor.
Open Save and run the MATLAB program.
The state model is given as input and entered in matrix format.
27
The syntax “[z,p,k]=ss2zp(A,B,C,D)” solves the given state model entered in matrix format as input
and gives the output in the form of poles, zeros and gain.
This syntax transforms the given state model into poles, zeros and gain
Note down the output zeros, poles and gain obtained practically by using the syntax
“[z,p,k]=ss2zp(A,B,C,D)”.
Now find the poles, zeros and gain theoretically for the given state model
Compare the theoretically obtained poles, zeros and gain from the given state model with the one
obtained practically. Write the result based on the comparison between theoretical and practical
result
28
EEE 412
Control System Laboratory
Lab Experiment 09: Step, Impulse and Ramp Response of a State
Model
Objectives: The objective of this exercise will be to Determine the Step, Impulse and Ramp Response of
a State Model
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts and their results should be reported properly.
Introduction
Step Response
A step signal is a signal whose value changes from one level to another level in zero time.
Mathematically, the step signal is represented as given below:
r(t)=u(t), where u(t)=1; t>0
=0; t<0
In the Laplace transform form
R(s)=1/s
The step response of the state model is obtained as follows:
1. The state model is first converted into a transfer function.
2. Step response for that transfer function is obtained as follows.
T(s)=C(s)/R(s);
So, C(s)=R(s)T(s)
C(s)=T(s)/s
The output is given by
c(t)=L-1[C(s)]
MATLAB program
A=input(‘enter matrix A’)
B=input(‘enter matrix B’)
C=input(‘enter matrix C’)
D=input(‘enter matrix D’)
step(A,B,C,D)
Example
A=
B=
C=
D=
29
Procedure
Step calculates the unit step response of a linear system. Zero initial state is assumed in the state-
space case.
When invoked with no output arguments, this function plots the step response on the screen.
Step(sys) plots the step response of an arbitrary LTI model sys. This model can be continuous or
discrete, and SISO or MIMO.
The duration of simulation is determined automatically based on the system poles and zeros.
You can specify either a final time t = Tfinal (in seconds), or a vector of evenly spaced time samples
of the form- t = 0:dt:Tfinal
For discrete systems, the spacing dt should match the sample period. For continuous systems, dt
becomes the sample time of the discretized simulation model (see "Algorithm"), so make sure to
choose dt small enough to capture transient phenomena.
To plot the step responses of several LTI models sys1,..., sysN on a single figure, use
step(sys1,sys2,...,sysN)
step(sys1,sys2,...,sysN,t)All systems must have the same number of inputs and outputs but may
otherwise be a mix of continuous- and discrete-time systems.
This syntax is useful to compare the step responses of multiple systems
Unit Impulse
An impulse signal is a signal whose value changes from zero to infinity in zero time. Mathematically, the
unit impulse signal is represented as given below:
r(t)=δ(t), where δ(t)=1; t=0
=0; t≠0
An examination of the impulse function will show that it is related to the unit-step function as
𝑑𝑢
follows:𝛿(𝑡) = 𝑑𝑡 and 𝑢(𝑡) = ∫ 𝛿(𝑡)𝑑𝑡.
The impulse function is not defined at point t = 0, but the impulse response must always satisfy
+∞
the following condition, or else it is not a true impulse function: ∫−∞ 𝛿(𝑡)𝑑𝑡 = 1.
MATLAB Program
A=input('enter matrix A')
B=input('enter matrix B')
C=input('enter matrix C')
D=input('enter matrix D')
impulse(A,B,C,D)
Example
A=
B=
C=
30
D=
Procedure
Impulse calculates the unit impulse response of a linear system.
Zero initial state is assumed in the state-space case. When invoked without left-hand arguments, this
function plots the impulse response on the screen.
Impulse(sys) plots the impulse response of an arbitrary LTI model sys. This model can be continuous
or discrete, and SISO or MIMO.
The duration of simulation is determined automatically to display the transient behavior of the
response.
Impulse(sys,t) sets the simulation horizon explicitly. You can specify either a final time t= Tfinal (in
seconds), or a vector of evenly spaced time samples of the formt = 0:dt:Tfinal
For discrete systems, the spacing dt should match the sample period. For continuous systems, dt
becomes the sample time of the discretized simulation model (see "Algorithm"), so make sure to
choose dt small enough to capture transient phenomena.
To plot the impulse responses of several LTI models sys1,..., sysN on a single figure, use
impulse(sys1,sys2,...,sysN)
impulse(sys1,sys2,...,sysN,t)
Ramp
A ramp signal is a signal which changes with time gradually in a linear fashion. Mathematically, the unit
ramp signal is represented as given below:
r(t)=tu(t), where u(t)=1; t>0
=0; t<0
In the Laplace transform form
R(s)=1/s2
The step response of the given transfer function is obtained as follows:
T(s)=C(s)/R(s);
So, C(s)=R(s)T(s)
C(s)=T(s)/s2
The output is given by
c(t)=L-1[C(s)]
MATLAB Program
t=0:0.01:10;
u=t
A=input('enter matrix A')
B=input('enter matrix B')
C=input('enter matrix C')
D=input('enter matrix D')
lsim(A,B,C,D,u,t)
Example
A=
B=
C=
D=
Procedure
lsim simulates the (time) response of continuous or discrete linear systems to arbitrary inputs.
When invoked without left-hand arguments, lsim plots the response on the screen lsim(sys,u,t)
produces a plot of the time response of the LTI model sys to the input time history t,u.
The vector t specifies the time samples for the simulation and consists of regularly spaced time
samples. t = 0:dt:Tfinal
31
The matrix u must have as many rows as time samples (length(t)) and as many columns as system
inputs. Each row u(i,:) specifies the input value(s) at the time sample t(i) .
The LTI model sys can be continuous or discrete, SISO or MIMO. In discrete time, u must be
sampled at the same rate as the system (t is then redundant and can be omitted or set to the empty
matrix).
In continuous time, the time sampling dt=t1-t2 is used to discretize the continuous model.
If dt is too large (undersampling), lsim issues a warning suggesting that you use a more appropriate
sample time, but will use the specified sample time.
lsim(sys,u,t,x0) further specifies an initial condition x0 for the system states. This syntax applies only
to state-space models.
32
EEE 412
Control System Laboratory
Lab Experiment 10: Study of PID Controller
Objective: Study the three term (PID) controller and its effects on the feedback loop response. Investigate
the characteristics of the each of proportional (P), the integral (I), and the derivative (D) controls, and how
to use them to obtain a desired response.
List of Equipment/Software
Following equipment/software is required:
MATLAB
LabVIEW
Category Soft – Experiment
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
Controller design and parameters for each of the given exercises.
Introduction
Example
33
Suppose we have a simple mass, spring, and damper problem.
MATLAB command window should give you the plot shown below.
34
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to a unit step
input. This corresponds to the steady-state error of 0.95, quite large indeed. Furthermore, the rise time is
about one second, and the settling time is about 1.5 seconds. Let's design a controller that will reduce the
rise time, reduce the settling time, and eliminates the steady-state error.
Proportional control:
The closed-loop transfer function of the above system with a proportional controller is:
𝑋(𝑠) 𝐾𝑃
=
𝐹(𝑠) 𝑠 2 + 10𝑠 + (20 + 𝐾𝑃 )
Let the proportional gain (KP) equal 300:
Kp=300;
contr=Kp;
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
MATLAB command window should give you the following plot.
Note: The MATLAB function called feedback was used to obtain a closed-loop transfer function directly
from the open-loop transfer function (instead of computing closed-loop transfer function by hand). The
above plot shows that the proportional controller reduced both the rise time and the steady-state error,
increased the overshoot, and decreased the settling time by small amount.
Proportional-Derivative control:
The closed-loop transfer function of the given system with a PD controller is:
𝑋(𝑠) 𝐾𝑃 + 𝐾𝐷 𝑠
= 2
𝐹(𝑠) 𝑠 + (10 + 𝐾𝐷 )𝑠 + (20 + 𝐾𝑃 )
Let KP equal 300 as before and let KD equal 10.
MATLAB Program
Kp=300;
35
Kd=10;
contr=tf([Kd Kp],1);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
MATLAB command window should give you the following plot.
This plot shows that the derivative controller reduced both the overshoot and the settling time,
and had a small effect on the rise time and the steady-state error.
Proportional-Integral control
Before going into a PID control, let's take a look at a PI control. For the given system, the
closed-loop transfer function with a PI control is:
𝑋(𝑠) 𝐾𝑃 𝑠 + 𝐾𝐼
= 3 2
𝐹(𝑠) 𝑠 + 10𝑠 + (20 + 𝐾𝑃 )𝑠 + 𝐾𝐼 )
Let's reduce the KP to 30, and let KI equal 70.
MATLAB Program:
Kp=30;
Ki=70;
contr=tf([Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
36
We have reduced the proportional gain (Kp) because the integral controller also reduces the rise time and
increases the overshoot as the proportional controller does (double effect). The above response shows that
the integral controller eliminated the steady-state error.
Proportional-Integral-Derivative control:
Now, let's take a look at a PID controller. The closed-loop transfer function of the given system with a
PID controller is:
𝑋(𝑠) 𝐾𝐷 𝑠 2 + 𝐾𝑃 𝑠 + 𝐾𝐼
= 3
𝐹(𝑠) 𝑠 + (10 + 𝐾𝐷 )𝑠 2 + (20 + 𝐾𝑃 )𝑠 + 𝐾𝐼 )
After several trial and error runs, the gains KP=350, KI=300, and KD=50 provided the desired response.
To confirm, enter the following commands to an m-file and run it in the command window. You should
get the following step response.
MATLAB Program
Kp=350;
Ki=300;
Kd=50;
contr=tf([Kd Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Now, we have obtained a closed-loop system with no overshoot, fast rise time, and no steady state error.
37
The characteristics of P, I, and D controllers:
The proportional controller (KP) will have the effect of reducing the rise time and will reduce, but never
eliminate, the steady state error. An integral controller (KI) will have the effect of eliminating the steady
state error, but it may make the transient response worse. A derivative control (KD) will have the effect of
increasing the stability of the system, reducing the overshoot and improving the transient response. Effect
of each controller KP, KI and KD on the closed-loop system are summarized below
Note that these corrections may not be accurate, because KP, KI, and KD are dependent of each other. In
fact, changing one of these variables can change the effect of the other two. For this reason, the table
should only be used as a reference when you are determining the values for KP, KI, and KD.
Exercise
Consider a process given below to be controlled by a PID controller,
400
𝐺(𝑠) =
𝑠(𝑠 + 48.5)
a) Obtain the unit step response of Gp(s).
b) Try PI controllers with (KP=2, 10, 100), and KI=KP/10. Investigate the unit step response in each case,
compare the results and comment.
c) Let KP=100, KI=10, and add a derivative term with (KD=0.1, 0.9, 2). Investigate the unit step response
in each case, compare the results and comment.
38
EEE 412
Control System Laboratory
Lab Experiment 11: Modeling of Physical System using Simulink
Objective: The objective of this exercise is to use graphical user interface diagrams to model the physical
systems for the purpose of design and analysis of control systems. We will learn how MATLAB /
SIMULINK helps in solving such models.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Category Soft – Experiment
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts, SIMULINK diagrams and their results for all the assignments and
exercises should be properly reported.
Introduction
This lab introduces powerful graphical user interface (GUI), Simulink of Matlab. This software is used
for solving the modeling equations and obtaining the response of a system to different inputs. Both linear
and nonlinear differential equations can be solved numerically with high precision and speed, allowing
system responses to be calculated and displayed for many input functions. To provide an interface
between a system’s modeling equations and the digital computer, block diagrams drawn from the
system’s differential equations are used. A block diagram is an interconnection of blocks representing
basic mathematical operations in such a way that the overall diagram is equivalent to the system’s
mathematical model. The lines interconnecting the blocks represent the variables describing the system
behavior. These may be inputs, outputs, state variables, or other related variables. The blocks represent
operations or functions that use one or more of these variables to calculate other variables. Block
diagrams can represent modeling equations in both input-output and state variable form.
We use MATLAB with its companion package Simulink, which provides a graphical user interface (GUI)
for building system models and executing the simulation. These models are constructed by drawing block
diagrams representing the algebraic and differential equations that describe the system behavior. The
operations that we generally use in block diagrams are summation, gain, and integration. Other blocks,
including nonlinear elements such as multiplication, square root, exponential, logarithmic, and other
functions, are available.
Provisions are also included for supplying input functions, using a signal generator block, constants etc
and for displaying results, using a scope block. An important feature of a numerical simulation is the ease
with which parameters can be varied and the results observed directly. MATLAB is used in a supporting
role to initialize parameter values and to produce plots of the system response. Also MATLAB is used for
multiple runs for varying system parameters. Only a small subset of the functions of MATLAB will be
considered during these labs.
39
Simulink
Simulink provides access to an extensive set of blocks that accomplish a wide range of functions useful
for the simulation and analysis of dynamic systems. The blocks are grouped into libraries, by general
classes of functions.
Mathematical functions such as summers and gains are in the Math library.
Integrators are in the Continuous library.
Constants, common input functions, and clock can all be found in the Sources library.
Scope, To Workspace blocks can be found in the Sinks library.
Simulink is a graphical interface that allows the user to create programs that are actually run in
MATLAB. When these programs run, they create arrays of the variables defined in Simulink that can be
made available to MATLAB for analysis and/or plotting. The variables to be used in MATLAB must be
identified by Simulink using a “To Workspace” block, which is found in the Sinks library. (When using
this block, open its dialog box and specify that the save format should be Matrix, rather than the default,
which is called Structure.) The Sinks library also contains a Scope, which allows variables to be displayed
as the simulated
system responds to an input. This is most useful when studying responses to repetitive inputs.
Simulink uses blocks to write a program. Blocks are arranged in various libraries according to their
functions. Properties of the blocks and the values can be changed in the associated dialog boxes. Some of
the blocks are given below.
40
CONSTANTS (Source library)
Constants are created by the Constant block, which closely resembles Figure 4. Double clicking on the
symbol opens a dialog box to establish the constant’s value. It can be a number or an algebraic expression
using constants whose values are defined in the workspace and are therefore known to MATLAB.
Two additional blocks will be needed if we wish to use MATLAB to plot the responses versus time.
These are the Clock and the To Workspace blocks.
41
MATLAB can make plots versus “time.” The clock output could be given any arbitrary name; we use “t”
in most of the cases.
In the Simulink diagram, the appearance of a block can be changed by changing the foreground or
background colours, or by drop shadow or other options available in the format drop down menu. The
available options can be reached in the Simulink window by highlighting the block, then clicking the right
mouse button. The Show Drop Shadow option is on the format drop-down menu.
Simulink provides scores of other blocks with different functions. You are encouraged to browse the
Simulink libraries and consult the online Help facility provided with MATLAB.
42
The differential equation for the above Mass-Spring system can then be written as follows
𝑑2 𝑥 𝑑𝑥
𝑀 2 +𝐵 + 𝐾𝑥 = 𝐹𝑎
𝑑𝑡 𝑑𝑡
Exercise 1: Modeling of a second order system
Construct a Simulink diagram to calculate the response of the Mass-Spring system. The input
force increases from 0 to 8 N at t = 1 s. The parameter values are M = 2 kg, K= 16 N/m, and
B =4 N.s/m.
Steps:
Draw the free body diagram.
Write the modeling equation from the free body diagram
Solve the equations for the highest derivative of the output.
Draw a block diagram to represent this equation.
Draw the corresponding Simulink diagram.
Use Step block to provide the input fa(t).
In the Step block, set the initial and final values and the time at which the step occurs.
Use the “To Workspace” blocks for t, fa(t), x, and v in order to allow MATLAB to plot the desired
responses. Set the save format to array in block parameters.
Select the duration of the simulation to be 10 seconds from the Simulation >Parameters entry on the
toolbar
Given below is a file that will set up the MATLAB workspace by establishing the values of the
parameters needed for the Simulink simulation of the given model.
43
Simulink block diagram
A semicolon in a physical line ends the logical line, and anything after it is treated as if it were on a new
physical line. A semicolon at the end of a line that generates output to the command window suppresses
the printing of that output.
Program Execution:
Follow the following steps to execute these files:
Enter the command exl_parameter in the command window. This will load the parameter values
of the model.
Open the Simulink model exl_model.mdl and start the simulation by clicking on the toolbar entry
Simulation> Start.
Enter the command exl_plot in the command window to make the plot.
M-file to use “sim” function and produce multiple runs and their plots
% This file is named ex2_plots.m.
% It plots the data produced by exl_model.mdl for
% several values of B. Execute exl_parameter.m first.
sim(’exl_model’) % Has the same effect as clicking on
% Start on the toolbar.
plot(t,x) % Plots the initial run with B=4
hold on % Plots later results on the same axes % as the first.
B = 8; % New value of B; other parameter values % stay the same.
sim(‘exl_model’) % Rerun the simulation with new B value.
plot(t,x) % Plots new x on original axes.
B 12; sim(’exl_model’);plot(t,x)
B = 25; sim(’exl_model’ ) ;plot(t,x)
hold off
45
EEE 412
Control System Laboratory
Lab Experiment 12: Block Diagram Reduction using Simulink
Objective: The objective of this exercise will be to learn commands in MATLAB that would be used to
reduce linear systems block diagram using series, parallel and feedback configuration.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Category Soft – Experiment
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts, SIMULINK diagrams and their results for all the assignments and
exercises should be properly reported.
Introduction
Series configuration: If the two blocks are connected as shown below then the blocks are said to be in
series. It would like multiplying two transfer functions. The MATLAB command for the such
configuration is “series”.
Example 1: Given the transfer functions of individual blocks generate the system transfer function of the
block combinations.
46
Parallel configuration: If the two blocks are connected as shown below then the blocks are said to be in
parallel. It would like adding two transfer functions.
The MATLAB command for implementing a parallel configuration is “parallel” as shown below:
Example 2: For the previous systems defined, modify the MATLAB commands to obtain the overall
transfer function when the two blocks are in parallel.
Feedback configuration: If the blocks are connected as shown below then the blocks are said to be in
feedback. Notice that in the feedback there is no transfer function H(s) defined. When not specified, H(s)
is unity. Such a system is said to be a unity feedback system.
The MATLAB command for implementing a feedback system is “feedback” as shown below:
When H(s) is non-unity or specified, such a system is said to be a non-unity feedback system as shown
below:
47
Example 3: Given a unity feedback system as shown in the figure, obtain the overall transfer function
using MATLAB:
Example 4: Given a non-unity feedback system as shown in the figure, obtain the overall transfer
function using MATLAB:
Poles and Zeros of System: To obtain the poles and zeros of the system use the MATLAB command
“pole” and “zero” respectively as shown in example 5. You can also use MATLAB command “pzmap” to
obtain the same.
Example 5: Given a system transfer function plot the location of the system zeros and poles
using the MATLAB pole-zero map command.
48
For example:
Exercise 1: For the following multi-loop feedback system, get closed loop transfer function and the
corresponding pole-zero map of the system.
1 1 𝑠2 +1 𝑠+1 𝑠+1
Given 𝐺1 = (𝑠+10); 𝐺2 = (𝑠+1); 𝐺3 = 𝑠2 +4𝑠+4; 𝐺4 = (𝑆+6); 𝐻1 = (𝑠+2); 𝐻2 = 2; 𝐻3 = 1
49
MATLAB program
50
EEE 412
Control System Laboratory
Lab Experiment 13: Effect of Feedback on Disturbance & Control
System Design
Objective: The objective of this exercise will be to study the effect of feedback on the response of the
system to step input and step disturbance taking the practical example of English Channel boring machine
and design a control system taking in account performance measurement.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Simulink
Category Soft – Experiment
Deliverables
A complete lab report including the following:
Summarized learning outcomes.
MATLAB scripts, SIMULINK diagrams and their results for all the assignments and exercises
should be properly reported.
Introduction
The construction of the tunnel under the English Channel from France to the Great Britain began in
December 1987. The first connection of the boring tunnels from each country was achieved in November
1990. The tunnel is 23.5 miles long and bored 200 feet below sea level. Costing $14 billion, it was
completed in 1992 making it possible for a train to travel from London to Paris in three hours.
The machine operated from both ends of the channel, bored towards the middle. To link up accurately in
the middle of the channel, a laser guidance system kept the machines precisely aligned. A model of the
boring machine control is shown in the figure, where Y(s) is the actual angle of direction of travel of the
boring machine and R(s) is the desired angle. The effect of load on the machine is represented by the
disturbance, Td(s).
Exercise 1:
a) Get the transfer function from R(s) to Y(s)
b) Get the transfer function from D(s) to Y(s)
c) Generate the system response; for K= 10, 20, 50, 100; due to a unit step input - r(t)
d) Generate the system response; for K= 10, 20, 50, 100; due to a unit step disturbance d(t)
e) For each case find the percentage overshoot(%O.S.), rise time, settling time, steady state of y(t)
f) Compare the results of the two cases
51
g) Investigate the effect of changing the controller gain on the influence of the disturbance on the system
output
MATLAB Program for two cases of K=20 and K=100 are shown below
Due to unit step – r(s) % Response to a Unit Step Input R(s)=1/s for K=20 and
K=100 %
numg=[1];deng=[1 1 0];sysg=tf(numg,deng);
K1=100;K2=20; num1=[11 K1];
num2=[11 K2];den=[0 1];
sys1=tf(num1,den);sys2=tf(num2,den);
% sysa=series(sys1,sysg);sysb=series(sys2,sys d);
sysc=feedback(sysa,[1]);sysd=feedback(sys b,[1]);%
t=[0:0.01:2.0];
[y1,t]=step(sysc,t);[y2,t]=step(sysd,t);
subplot(211);plot(t,y1);
title(‘Step Response for K=100’);
xlabel(‘Time (seconds)’);
ylabel(‘y(t)’);grid on;
subplot(212);plot(t,y2);
title(‘Step Response for K=20’);
xlabel(‘Time (seconds)’);
ylabel(‘y(t)’);grid on;
Due to unit disturbance – Td(s) % Response to a Disturbance Input D(s)=1/s for
K=20 and K=100 %
numg=[1];deng=[1 1 0];sysg=tf(numg,deng);
K1=100;K2=20; num1=[11 K1];
num2=[11 K2];den=[0 1];
sys1=tf(num1,den);sys2=tf(num2,den);
% sysa=feedback(sysg,sys1);sysa=minreal(sys a);
sysb=feedback(sysg,sys2);sysb=minreal(sys b); %
t=[0:0.01:2.5];
[y1,t]=step(sysa,t);[y2,t]=step(sysb,t);
subplot(211);plot(t,y1);
title(‘Disturbance Response for K=100’);
xlabel(‘Time (seconds)’);
ylabel(‘y(t)’);grid on; subplot(212);plot(t,y2);
title(‘Disturbance Response for K=20’);
xlabel(‘Time (seconds)’);
ylabel(‘y(t)’);grid on;
52