EE-371 Linear Control System Lab Manual
EE-371 Linear Control System Lab Manual
Name:
CMS ID: Class: Section:
Batch: Semester:
Department:
Objective:
Gain familiarity with MATLAB/Python basics relevant to linear control systems.
1.1 MATLAB
MATLAB is a programming and numeric computing platform millions of engineers and
scientists use to analyze data, develop algorithms, and create models.
Page 1
This tells MATLAB to take the first row, all columns. You can also refer to any matrix with
only one index. It will use that index to count down the columns. c(5) will give you 7, for
example.
1.1.4 Help
Typing ”help name” at the MATLAB prompt displays the help text for the functionality
specified by name, such as a function, method, class, toolbox, or variable.
1.1.5 Plotting
The basic syntax to get a plot in MATLAB is
1 t = 0:0.01:10;
2 y = cos ( t ) ;
3 plot (t , y ) ;
(The x values always come before the y values, t, and y represent variables in which your
data is stored.) You can plot multiple values with plot(x1, y1, x2, y2) and specify a plot’s
color and line type as something like plot(x1, y1,′ w∗′ ) to get white ∗’s for each data point.
To split your plot into a bunch of smaller plots, you can use the subplot command to split
it up into rows and columns.
1 subplot (r , c , n ) ;
This will split the plot window into r rows and c columns of plots and set the current plot
to plot number n of those rows and columns. For example, subplot(2, 1, 1) splits the plot
window into two rows in a single column and prepares to plot in the top plot. Then your
plot command will plot in the top plot. Then you could switch to the bottom plot with
subplot(2, 1, 2) and use another plot command to plot in the bottom plot. You can add
titles, labels, and legends to plots.
1 title ( ’ This is a Title ’)
2 xlabel ( ’ My X axis ’)
3 ylabel ( ’ My Y axis ’)
1.1.6 Polynomials
MATLAB can treat a vector as a polynomial. It will assume that the numbers represent the
coefficients of the polynomial going from highest order to lowest order.
1 p = [1 2 2 4 1]
can represent the polynomial x4 +2x3 +2x2 +4x+1. Several functions use this representation
of polynomials:
Page 2
1 r = roots ( p )
Gives you the roots of the polynomial represented by the vector p.
1 polyval (p , 4)
Gives you the value of the polynomial p when x = 4. Similarly,
1 polyval (p , [1:10])
Gives you the value of the polynomial evaluated at each of the points in the vector. Given
the roots of a polynomial in a vector, a vector of polynomial coefficients can be obtained by
1 p = poly ( r )
Page 3
1.1.9 Partial Fractions using MATLAB
You write the coefficients of the numerator and the denominator in separate vectors and
MATLAB gives you the coefficients of the partial fraction expansion.
1 n = [4 4 4];
2 d = [1 3 2 0 0];
3 [A , p , K ] = residue (n , d )
1.2 Python
Python is a versatile, high-level programming language that prioritizes code readability
through significant indentation. It is dynamically typed, has garbage collection, and supports
multiple programming paradigms, including structured, object-oriented, and functional pro-
gramming. Python is often referred to as a language with a comprehensive standard library
due to its ”batteries included” nature.
Page 4
You can get a whole row of a matrix with
1 c [0]
This tells Python to take the first row, all columns. The determinant method inside the
numpy library can be used to find the determinant of a matrix.
1 det = np . linalg . det ( c )
1.2.3 Plotting
Plotting is possible in Python using matplotlib. Importing the library is done by the following
command.
1 import matplotlib . pyplot as plot
To plot a simple trigonometric function a simple plot method suffices.
1 t = np . arange (1 , 6.25 , 0.25) # Time Vector
2 x = np . sin ( t )
3 plot . subplot (2 , 1 , 1)
4 plot . plot (t , x )
5 plot . title ( ’ This is my title ’)
6 plot . ylabel ( ’Y axis ’)
7 plot . subplot (2 , 1 , 2)
8 plot . plot (t , np . cos ( t ) )
9 plot . xlabel ( ’X axis ’)
10 plot . ylabel ( ’Y axis ’)
11 plot . show ()
When plotting, the x-values should always come before the y-values. The variables t and x
are used to store your data. You can customize the color and line type of a plot. To divide
your plot into multiple smaller plots, you can use the subplot command to create rows and
columns. This splits the plot window into r rows and c columns of plots and then sets the
current plot to plot number n in those rows and columns. For example, plot.subplot(2, 1, 1)
divides the plot window into two rows in a single column and prepares to plot in the top
plot. After that, you can switch to the bottom plot and use another plot command to plot
there. Additionally, you can add titles, labels, and legends to your plots. Finally, use the
’show’ method to display the plot.
1.2.4 Polynomials
In Python polynomials can be stored by the use of the method ’poly1d’ in the numpy library.
1 p = np . poly1d ([1 , 2 , 2 , 4 , 1])
can represent the polynomial x4 +2x3 +2x2 +4x+1. Several functions use this representation
of polynomials:
1 r = p.r
Gives you the roots of the polynomial represented by the vector p.
1 c = p (4)
Gives you the value of the polynomial p when x = 4. Similarly,
1 c = p ( np . arange (1 , 11) )
Gives you the value of the polynomial evaluated at each of the points in the vector.
Page 5
1.2.5 Solution of Equations using Symbolic Library
The symbolic library in Python can solve many types of equations, including non-linear ones
and several simultaneous equations.
Example: Find the solutions to an algebraic simultaneous equation:
x2 y 2 = 0
x−y (1.3)
=a
2
1 import sympy as syms
2 x , y , a = syms . symbols ( ’x y a ’)
3 syms . init_printing ( use_unicode = True )
4 Eq1 = syms . Eq ( x * x * y *y , 0)
5 Eq2 = syms . Eq ( x - ( y / 2) , a )
6 sol1 , sol2 = syms . solve ([ Eq1 , Eq2 ] , [x , y ])
7 print ( " x = " + str ( sol1 ) )
8 print ( " y = " + str ( sol2 ) )
1.3 Practical
1.3.1 Pre-Lab Tasks
Write code to solve the following problems using MATLAB or Python. Additionally, display
the results of the code.
Page 6
1. Create a 4 × 4 matrix with the following elements
1 2 4 −3
3 −1 9 0
5 6 10 2 (1.4)
7 8 11 −1
2. Plot two functions on the graph, y1 = x2 and y2 = 2x3 . Use the domain −10 ≤ x ≤ 10.
Add titles, labels, and grids to your plot.
Page 7
4. Find and print the Laplace transform of f (t) = 3t2 + 2t + 1.
10
5. Find and print the inverse Laplace transform of F (s) = s(s+3)
.
Page 8
2. How does MATLAB/Python handle trigonometric functions like sin() when applied to
arrays or vectors?
1.4 Conclusion
Page 9
Lab No. 02: System Representation
Objective:
Gain an understanding of creating transfer functions and state space representations, and
learn to input them into MATLAB, Python, or Simulink for analysis and simulation.
2.1 Theory
Linear time-invariant systems (LTI systems) are a class of systems used in signals and systems
that are both linear and time-invariant. Linear systems are systems whose outputs for a linear
combination of inputs are the same as a linear combination of individual responses to those
inputs. Time-invariant systems are systems where the output does not depend on when an
input was applied. These properties make LTI systems easy to represent and understand
graphically.
Page 10
The general state space system has the following set of equations:
ẋ(t) = Ax(t) + Bu(t)
(2.6)
y(t) = Cx(t) + Du(t)
Where A, B, C, and D are matrices, the state space system of the differential equation in
Equation (2.1) can be constructed using the definition of the state variables in Equation
(2.5). The state space is given by:
ẋ1 (t) 0 1 x1 (t) 0
ẋ2 (t) = 2
−3 −3 5 + 4 u(t)
x2 (t) 3
(2.7)
x1 (t)
y(t) = (1 0) x (t)
2
2.2 MATLAB
Transfer functions can be represented in MATLAB as LTI objects using numerator and
s+1
denominator polynomials. Consider the transfer function given by G(s) = s2 +3s+1 . It can be
represented in MATLAB as
1 Num = [1 1];
2 Den = [1 3 1];
3 G = tf ( Num , Den )
Transfer functions can also be entered directly in polynomial form as we enter them in the
notebook using LTI objects
1 s = tf ( ’s ’) ;
2 G = ( s + 1) / ( s * s + 3 * s + 1)
Poles and zeros of any transfer function can be calculated by
1 P = pole ( G )
2 Z = zero ( G )
Obtaining a pole-zero plot in the s-plane can be done by
1 pzmap ( G ) ;
Extracting numerator and denominator polynomials from a transfer function can be achieved
by
1 [ Num , Den ] = tfdata (G , ’v ’)
There are several useful MATLAB commands related to design in state space. The state
space equations can be represented in MATLAB by defining the matrix A, and the vectors
B and C.
1 A = [0 1 0; 0 0 1; 0 -2 -3];
2 B = [0; 0; 1];
3 C = [1 0 0];
4 D = 0;
5 SS = ss (A , B , C , D )
Eigenvalues of the A matrix can be found by
1 E = eig ( SS )
Transforming the transfer function model to the state space model is achieved by
1 [A , B , C , D ] = tf2ss ( Num , Den ) ;
2 SS = ss (A , B , C , D )
Where N um and Den are the coefficients of the numerator and denominator polynomial.
Converting a state space model to a transfer function is done by
Page 11
1 [ Num , Den ] = ss2tf (A , B , C , D ) ;
2 G = tf ( Num , Den )
2.3 Python
Transfer functions can be represented in Python by the use of the Control System Library.
The library can be imported as
1 import control
The first method for entering a transfer function is by using numerator and denominator
s+1
polynomials. Consider the transfer function given by G(s) = s2 +3s+1 . It can be represented
in Python as
1 Num = np . array ([1 , 1])
2 Den = np . array ([1 , 3 , 1])
3 G = control . tf ( Num , Den )
Transfer functions can also be entered directly in polynomial form as we enter them in the
notebook using
1 s = control . TransferFunction . s
2 H = ( s + 1) / ( s * s + 3 * s + 1)
Poles and zeros of any transfer function can be calculated by
1 p = control . poles ( G )
2 z = control . zeros ( G )
Obtaining a pole-zero plot in the s-plane can be done by
1 plot . scatter ( np . real ( p ) , np . imag ( p ) , None , None , " x " )
2 plot . scatter ( np . real ( z ) , np . imag ( z ) , None , None , " o " )
3 plot . title ( ’ Pole Zero Plot ’)
4 plot . xlabel ( ’ Real (\ u03c3 ) ’)
5 plot . ylabel ( ’ Imaginary ( jw ) ’)
6 plot . grid ( True )
7 plot . show ()
Extracting numerator and denominator polynomials from a transfer function can be achieved
by
1 ( Num , Den ) = control . tfdata ( H )
There are several useful commands related to design in state space. The state space equations
can be represented in Python by defining the matrix A, and the vectors B and C.
1 A = np . array ([[0 , 1 , 0] , [0 , 0 , 1] , [0 , -2 , -3]])
2 B = np . array ([[0] , [0] , [1]])
3 C = np . array ([1 , 0 , 0])
4 D = 0
5 H = control . ss (A , B , C , D )
Eigenvalues of the A matrix can be found by
1 E = np . linalg . eigvals ( A )
Transforming the transfer function model to the state space model is achieved by
1 SS = control . ss ( G )
Converting a state space model to a transfer function is done by
1 TF = control . tf ( H )
Page 12
2.4 Simulink
SIMULINK (SIMUlation LINK) is an extension of MATLAB for modeling, simulating, and
analyzing dynamic, linear/nonlinear, complex control systems. Graphical User Interface
(GUI) and visual representation of the simulation process by simulation block diagrams
are two key features that make SIMULINK one of the most successful software packages,
particularly suitable for control system design and analysis.
Simulation block diagrams are nothing but the same ones we use to describe control system
structures and signal flow graphs. SIMULINK offers many ready-to-use building blocks
to build mathematical models and system structures in terms of block diagrams. Block
parameters should be supplied by the user. Once the system structure is defined, some
additional simulation parameters must also be set to govern how the numerical computation
will be carried out and how the output data will be displayed.
Because SIMULINK is graphical and interactive, we encourage you to jump right in and
try it. To help you start using SIMULINK quickly, we describe here the simulation process
through a demonstration example. To start SIMULINK, enter the SIMULINK command at
the MATLAB prompt. Alternatively, one can also click on the SIMULINK icon shown in
the figure below.
Page 13
for example, expanding the Sources subnode displays a long list of Sources library blocks.
Simply click on any block to learn about its functionality in the description box, see Figure
(2.3a).
You may now collapse the Sources subnode and expand the Sinks subnode. A list of Sinks
library blocks appears, see Figure (2.3b). Learn the purpose of various blocks in the Sinks
subnode by clicking on the blocks.
We have described some of the subsystem libraries available that contain the basic building
blocks of simulation diagrams. The reader is encouraged to explore the other libraries as well.
You can also customize and create your blocks. For information on creating your blocks, see
the MATLAB documentation on ‘Writing S-Functions’.
We are now ready to proceed to the next step, which is the construction of a simulation
diagram. In the SIMULINK library browser, follow File → New → Model or press Ctrl+N to
open an ‘untitled’ workspace, see Figure (2.4), to build up an interconnection of SIMULINK
blocks from the subsystem libraries.
Page 14
Figure 2.5: Block Diagram of a DC Motor (Armature-Controlled) System
Where:
• Ra is the resistance of the motor armature = 1.7 Ω.
• La is the inductance of the motor armature = 2.83 ∗ 10−4 H.
• Kt is the torque constant = 0.0924 N m/A.
• Kb is the back emf constant = 0.0924 V sec/rad.
Identifying the block(s) required for simulation purposes is the first step of the construction
of the simulation diagram in SIMULINK. The next step is to ‘drag and drop‘ the required
blocks from SIMULINK block libraries to the untitled workspace. Let us put the very first
block for applied voltage (Ea) to the workspace.
Expand the Sources subnode, move the pointer, and click the block labeled Constant, and
while keeping the mouse button pressed down, drag the block, and drop it inside the Simu-
lation Window; then release the mouse button shown in Figure (2.7).
Right-clicking on the block will provide various options to users from which one can cut,
copy, delete, and format (the submenu provides facilities for rotation of the block, flipping,
changing the font of the block name, etc.)
It is visible that all the block parameters are in their default settings. For example, the default
1
transfer function of the Transfer Function block is s+1 and the default signs of the Sum block
are ++. We need to configure these block parameters to meet our modeling requirements.
Page 15
Figure 2.7: Drag and Drop Blocks to Workspace from the Library Browser
It is straightforward. Double-click the block to set up its parameters. For example, double-
clicking the Transfer Function block opens the window titled Block Parameters: Transfer
Function, shown in Figure (2.9).
For the armature circuit transfer function, no need to change the numerator parameter. For
denominator parameters, enter [2.83 ∗ 10−4 1.7] for [La Ra ], which will be interpreted by
SIMULINK as La s + Ra . To enhance the interpretability of the simulation diagram, we can
also change the block identification name. Simply click on the text Transfer Function to
activate the small window around the text to change the block name. For our simulation
block diagram, the suitable text for the Transfer Function block may be the Armature Circuit.
Note that the Decimation parameter value by default is 1. Increasing this value reduces the
number of data samples taken over the simulation time. We have used the default value of
1.
Lines are drawn to interconnect these blocks as per the desired structure. A line can connect
the output port of one block to the input port of another block. A line can also connect
the output port of one block with the input ports of many blocks by using branch lines.
We suggest readers perform the following line/block operations on blocks dragged in the
workspace to get hands-on practice. To connect the output port of one block to the input
port of another block:
Page 16
Figure 2.9: Transfer Function Block Parameters Window
1. Position the pointer on the first block’s output port; note that the cursor shape changes
to a crosshair.
2. Press and hold down the left mouse button.
3. Drag the pointer to the second block’s input port.
4. Position the pointer on or near the port, the pointer changes to a double crosshair.
5. Release the mouse button. SIMULINK replaces the port symbol with a connecting line
with an arrow showing the direction of signal flow.
Another simple methodology doesn’t require dragging the line. Block1 output port is re-
quired to be connected to Block2 input port.
We can use branch lines to connect the output port of one block with the input ports of
several blocks. Both the existing line and the branch line carry the same signal. To add a
branch line, do the following:
1. Position the pointer on the line where you want the branch line to start.
Page 17
2. While holding down the Ctrl key, left-click on the line segment; note that the cursor
shape changes to a crosshair.
3. Release the control key, while pressing down the left mouse button; drag the pointer
to the input port of the target block.
4. Release the mouse button; the target block will be connected to the line segment.
Some of the important line segment and block operations are as follows:
1. To move a line segment, position the pointer on the segment you want to move. Press
and hold down the left mouse button. Drag the pointer to the desired location and
release. Note that this operation is valid with line segments only, not with the dedicated
connecting lines between two blocks.
2. To disconnect a block from its connecting lines, hold down the shift key, then drag the
block to a new location. Incoming and outgoing lines will be converted to red-colored
dotted lines. One can insert a different block between these lines.
Now let us give a name to the untitled workspace. Hit Ctrl + S to save the developed
simulation diagram to the disk with an appropriate name. The file will be saved with the
extension .mdl, an abbreviation for the ‘model’.
2.5 Practical
2.5.1 Pre-Lab Tasks
Write code to solve the following problems using MATLAB or Python. Additionally, display
the results of the code.
(s−1)(s−2)(s−3)
2. Define the transfer function H(s) = (s−1)(s+2)(s+3)(s+4) . Find out and print the numer-
ator and the denominator polynomials.
Page 18
3. Define the state space representation of a system with
−1 2 0
! !
1
A = 0 −3 4 B = 0
1 −1 0 0 (2.8)
1 0 0 0
C= 0 1 0 D= 0
4. Convert the transfer function G(s) in Task 1 to state space and print the result.
5. Convert the state space system in Task 3 to the transfer function and print the result.
Page 19
mv̇(t) + bv(t) = u(t) (2.9)
Where
3. Consider a dynamic system consisting of a single output y, and two inputs r and w:
Page 20
J θ̈(t) + bθ̇(t) = Kt i(t)
d (2.11)
L i(t) + Ri(t) = V (t) − Kb θ̇(t)
dt
Where
1. RC dtd Vout (t) + Vout (t) = Vin (t). Where R = 10 kΩ, C = 1 µF , Vin (t) is the voltage
applied to the filter, and Vout (t) is the filtered voltage.
2
2. L dtd 2 Vout (t) + R dtd Vout (t) + C1 Vout (t) = C1 Vin (t). Where R = 100 Ω, L = 1 H, C =
0.01 F , Vin (t) is the voltage applied to the circuit, and Vout (t) is the output voltage of
the circuit.
Page 21
2
3. m dtd 2 x(t) + b dtd x(t) + kx(t) = F (t). Where m = 1 kg, k = 10 N
m
, b = 0.5 Nms , F (t) is
the force applied to the system, and x(t) is the displacement of the system.
4. ( RJ2 +m)r̈(t) = −mg Ld θ(t). Where m = 0.11 kg, R = 0.015 m, d = 0.03 m, g = 9.8 sm2
, L = 1 m, J = 9.99 µkgm2 , r(t) is the ball position, and θ(t) is the servo gear angle.
2.6 Conclusion
Page 22
Lab No. 03: System Transient Response
Objective:
To create plots of system responses using MATLAB, SIMULINK, or Python, and to be
able to analyze the transient characteristics of a system response. This includes performing
analysis of the system using generic first-order and second-order transfer functions.
3.1 Theory
Transient characteristics of a control system refer to its behavior during the transition from
one steady state to another following a change in input or disturbance. These characteristics
describe how the system responds dynamically over time, revealing details such as its speed of
response, stability, and damping. Key parameters include rise time, settling time, overshoot,
and damping ratio, which collectively depict how quickly and smoothly the system reaches its
new equilibrium state without oscillations or excessive deviations. Understanding transient
characteristics is crucial in designing and analyzing control systems to ensure they meet
performance requirements and operate effectively under varying conditions and disturbances.
The transfer function’s gain, K, represents the steady-state value of the unit step response,
indicating the system’s response when subjected to a step input. The system takes ap-
proximately 5τ , known as the settling time, to reach a steady-state condition, after which
it remains stable. Before reaching 5τ , the system is in a transient state, characterized by
temporary fluctuations as it approaches stability.
Page 23
help of these parameters, the step response of the system can be accurately predicted. The
step response of the transfer function is illustrated below.
Where:-
These parameters in the step response can be calculated using the values of ζ and ωn and
the formulas given below.
π−β ωd p
tr = , β = tan−1 , ω d = ωn 1 − ζ 2
ωd ζωn
4 3
ts = (2% criterion), (5% criterion) (3.3)
ζωn ζωn
−πζ
Mp (%) = 100 exp p
1 − ζ2
In the above formulas, ωd is the damped frequency. The system is in transient condition
before settling time and in steady-state condition after settling time has passed. There are
two criteria to determine the settling time. The first criterion states that when the system
response is within 2% of the steady-state value, then the system has entered the steady-state
condition. The second criterion states that when the system response is within 5% of the
steady-state value, then the system has entered the steady-state condition.
Page 24
3.2 MATLAB
Step and impulse responses of LTI objects can be obtained by the commands ’step’ and
’impulse’. For example, to obtain the step response of the system represented in LTI object
G, enter
1 step ( G ) ;
To obtain the impulse response, enter
1 impulse ( G ) ;
Step and impulse response data can be collected into MATLAB variables by using two left-
hand arguments. For example, the following commands will collect step and impulse response
amplitudes in yt and time samples in t.
1 [ yt , t ] = step ( G ) ;
2 [ yt , t ] = impulse ( G ) ;
The response of LTI systems to arbitrary inputs can be obtained by the command ’lsim’.
This command plots the time response of the LTI model G to the input signal described by
u and t. The time vector t consists of regularly spaced time samples and u is a matrix with
as many columns as inputs and whose ith -row specifies the input value at time t(i). The
following MATLAB code is shown to obtain the time response of LTI system G to sinusoidal
input of unity magnitude.
1 t = 0: 0.01: 7;
2 u = sin ( t ) ;
3 lsim (G , u , t ) ;
The function ’gensig’ generates periodic signals for time response simulation with ’lsim’
function. It can generate sine, square, and periodic pulses. All generated signals have unit
amplitude. The following MATLAB code is shown to simulate G(s) for 20 seconds with a
sine wave of a period of 5 seconds.
1 [u , t ] = gensig ( ’ sin ’ , 5 , 20) ;
2 lsim (G , u , t ) ;
On the step plot in MATLAB, you can right-click on the plot and select your desired char-
acteristic to display on the plot. Selecting a characteristic will place a point on your step
response. Hovering your mouse over the point will show you the value of your selected
characteristic. Clicking on that value will keep the value on your step response.
3.3 Python
To obtain the unit step response of a system, you can use the ’step response’ method in the
Control Systems Library. This function returns a time array and an output array, which can
then be used to plot the unit step response on a graph.
1 T = np . linspace (0 , 30)
2 t , y = control . step_response (G , T )
3 plot . plot (t , y )
4 plot . title ( ’ Step Response ’)
5 plot . xlabel ( ’ Time ( s ) ’)
6 plot . ylabel ( ’ Amplitude ’)
7 plot . axhline (1 , color = ’r ’ , linestyle = ’: ’ , label = ’ Unit Step Input ’)
8 plot . legend ()
9 plot . grid ()
10 plot . show ()
To obtain a scaled step response, use the ’forced response’ method in the Control Systems
Library. This function requires input for the amplitude of the step response.
Page 25
1 T = np . linspace (0 , 30)
2 t , y = control . forced_response (G , T , 5)
3 plot . plot (t , y )
4 plot . title ( ’ Step Response ’)
5 plot . xlabel ( ’ Time ( s ) ’)
6 plot . ylabel ( ’ Amplitude ’)
7 plot . axhline (5 , color = ’r ’ , linestyle = ’: ’ , label = ’ Step Input ’)
8 plot . legend ()
9 plot . grid ()
10 plot . show ()
To obtain the unit impulse response of a system, you can use the ’impulse response’ method
in the Control Systems Library. This function returns a time array and an output array,
which can then be used to plot the unit impulse response on a graph.
1 t , y = control . impulse_response ( G )
2 plot . plot (t , y )
3 plot . title ( ’ Impulse Response ’)
4 plot . xlabel ( ’ Time ( s ) ’)
5 plot . ylabel ( ’ Amplitude ’)
6 plot . axvline (0 , color = ’r ’ , linestyle = ’: ’ , label = ’ Unit Impulse Input ’)
7 plot . legend ()
8 plot . grid ()
9 plot . show ()
To obtain responses from other inputs, such as sine waves or square waves, you can use the
’lsim’ method in the Control Systems Library. Before writing the code, make sure to include
the necessary command to import the ’lsim’ method.
1 from control . matlab import lsim
Then, simply generate the system response using the ’lsim’ method.
1 T = np . arange (0 , 7.01 , 0.01)
2 u = np . sin ( T )
3 y , t , x = lsim (G , u , T )
4 plot . plot (t , u , color = ’r ’ , linestyle = ’: ’ , label = ’ Sinusoidal Input ’)
5 plot . plot (t , y )
6 plot . title ( ’ Sinusoidal Response ’)
7 plot . xlabel ( ’ Time ( s ) ’)
8 plot . ylabel ( ’ Amplitude ’)
9 plot . legend ()
10 plot . grid ()
11 plot . show ()
Generating a square wave signal in Python can be accomplished using the ’square’ method
in the scipy library. The code to generate a square wave and then obtain its system response
is provided below.
1 from scipy import signal
2 T = np . arange (0 , 1.001 , 0.001)
3 u = signal . square (2 * np . pi * 5 * T )
4 y , t , x = lsim (G , u , T )
5 plot . plot (t , u , color = ’r ’ , linestyle = ’: ’ , label = ’ Square Wave Input ’)
6 plot . plot (t , y )
7 plot . title ( ’ Square Wave Response ’)
8 plot . xlabel ( ’ Time ( s ) ’)
9 plot . ylabel ( ’ Amplitude ’)
10 plot . legend ()
11 plot . grid ()
12 plot . show ()
Page 26
3.4 Practical
3.4.1 Pre-Lab Tasks
Write code to solve the following problems using MATLAB, SIMULINK, or Python. Addi-
1
tionally, display the results of the code. Consider G(s) = 5s+1
3. Obtain and plot the system response of G(s) when the input is a constant 10.
4. Obtain and plot the system response of G(s) when the input is a cosine wave with an
amplitude of 0.5.
Page 27
5. Obtain and plot the system response of G(s) when the input is a square wave between
0 and 2.
2. Obtain the unit step and ramp responses of the system in Task 1 on SIMULINK. Find
the rise time, maximum overshoot, settling time, and steady-state value. Compare
your results obtained in this task with your previous task.
3. Generate square and pulse signals with a period of 4 seconds and obtain the time
s+1
response of G(s) = s2 +3s+1 for 30 seconds on MATLAB/Python as well as SIMULINK.
Page 28
Figure 3.3: Series RC Circuit
5. Consider R = 1 KΩ and L = 1 mH. Find out the transfer function of the circuit ( VV(s)
L
)
in Figure (3.4). Plot the sinusoidal response of the system on SIMULINK/Python.
Page 29
0.75
2. G(s) = s+4
1
3. G(s) = s2 +s+1
2
4. G(s) = s2 +2.8s+2
1
5. G(s) = s2 +0.24s+1
3.5 Conclusion
Page 30
Lab No. 04: Steady-State Response
Objective:
To create feedback systems using MATLAB, SIMULINK, or Python, and to analyze the
stability of the system by examining the poles on the s-plane.
4.1 Theory
4.1.1 The S-Plane
It is a two-dimensional plane where the horizontal axis is the real part (σ) and the vertical
axis is the imaginary part (jω) of a complex variable (s), which is used in Laplace transforms.
In the s-plane, poles, and zeros of a system’s transfer function are plotted, providing insight
into the system’s stability and dynamic behavior.
The s-plane consists of the left half plane (LHP) and the right half plane (RHP). Stability
can be analyzed by the location of the poles of a transfer function. The vertical axis that
divides the two planes is called the line of marginal stability. If a pole of a transfer function
lies on the vertical axis, the system is marginally stable. If all the poles of a transfer function
lie in the left half plane, then the system is considered stable. However, if even one pole of
a transfer function lies in the right half plane, then the system is considered unstable.
The step response of a transfer function can be predicted by the location of the poles of
that transfer function on the s-plane. If a pole lies on the horizontal axis, it produces an
exponential response. If the pole lies in the right half plane, it produces an exponentially
increasing response; otherwise, it makes an exponentially decaying response. Poles exist on
the vertical axis as complex conjugates. If a conjugate pole pair lies on the vertical axis, it
produces a steady sinusoidal response. If a conjugate pole pair lies in the right half plane,
the response is sinusoidally increasing; otherwise, the response is sinusoidally decaying. The
figure below shows the s-plane.
Figure (4.2) shows the effect of the value of the damping ratio on the maximum overshoot
and the undamped natural frequency.
When the dominant conjugate pole pair lies on the vertical axis (ζ = 0), it results in a
steady sinusoidal response. If the dominant conjugate pole pair lies in the left half plane
(0 < ζ < 1), the response is classified as underdamped. When the dominant two poles lie
Page 31
Figure 4.2: The Significance of Damping Ratio on Maximum Overshoot and Undamped
Natural Frequency
in the left half plane on the horizontal axis, one on top of the other (ζ = 1), the response is
classified as critically damped. If the dominant two poles lie in the left half plane on the
horizontal axis but have different values (ζ > 1), the response is classified as overdamped.
In the block diagram above, the blocks must be replaced by equivalent hardware using oper-
ational amplifiers. The configurations of amplifiers used are summing amplifier, integrating
amplifier, voltage follower, and inverting amplifier. The inverting amplifier is used to provide
gain to the second state.
The integrating amplifiers are used to integrate and obtain both states. The gain of the
integrating amplifier is set to 1, so it only integrates and does not amplify the signal. The
Page 32
voltage follower is used to invert the sign to obtain the output. The summing amplifier is
used to perform the summation operation to get the derivative of the second state. The gain
of the summing amplifier is also set to 1. The resultant hardware diagram is shown below.
4.2 MATLAB
In a control system, multiple blocks are interconnected to form a block diagram representation
of a feedback control system. MATLAB provides several functions for performing block
diagram manipulations, including solutions via ’series’, ’parallel’, and ’feedback’ commands.
1 C = series (G , D ) ;
for a cascade connection of G(s) and D(s);
1 P = parallel ( G1 , G2 ) ;
for a parallel connection of G1 (s) and G2 (s);
1 S = feedback (G , H , sign ) ;
for a closed-loop connection with G(s) in the forward path and H(s) in the feedback path,
and the sign is −1 for negative feedback or +1 for positive feedback (the sign is optional for
negative feedback).
4.3 Python
In a control system, multiple blocks are interconnected to form a block diagram representation
of a feedback control system. The Python Control Systems Library provides several functions
for performing block diagram manipulations, including solutions via ’series’, ’parallel’, and
’feedback’ commands.
1 Sys = control . series ( G1 , G2 )
for a cascade connection of G1 (s) and G2 (s);
1 Sys = control . parallel ( G1 , G2 )
for a parallel connection of G1 (s) and G2 (s);
1 Sys = control . feedback ( G1 , H )
for a closed-loop connection with G1 (s) in the forward path and H(s) in the feedback path,
and the sign is −1 for negative feedback or +1 for positive feedback (the sign is optional for
negative feedback).
Page 33
To create a block diagram in Python, we can utilize the Control Systems Library. The
‘interconnect‘ function is used to establish connections between all the individual blocks.
Additionally, the ‘summing junction‘ function can be employed to define a summing block. It
is imperative to clearly define the inputs and outputs for each block so that the ‘interconnect‘
function can effectively connect them. In Figure (4.5) you can find an example block diagram
along with the corresponding Python code below.
4.4 Practical
4.4.1 Pre-Lab Tasks
Write code to solve the following problems using SIMULINK or Python. Additionally, display
the results of the code. Consider G1 (s) = 1s , G2 (s) = 5s+1
1 1
, H1 (s) = s+1 1
, and H2 (s) = s+2 .
Implement the following block diagrams in Simulink/Python and obtain the overall transfer
function C(s)
R(s)
.
Page 34
Figure 4.6: Task 1
Page 35
Figure 4.9: Task 4
Page 36
4.4.2 Lab Tasks
1. Consider the block diagram.
Page 37
3. Find out the transfer function of the circuit YU (s)
(s)
in Figure (4.12). Perform stability
analysis on the transfer function and determine the type of response the system has
to a step input. Finally, apply the step input on MATLAB/Python, obtain the step
response, and verify your analysis.
2.
ẋ1 (t) 0 1 x1 (t) 0
= −9 −6 + 1 u(t)
ẋ2 (t) x2 (t)
(4.3)
x 1 (t)
y(t) = (1 0)
x2 (t)
Page 38
3.
ẋ1 (t) 0 1 x1 (t) 1
ẋ2 (t) = −5 −6 x2 (t) + 0 u(t)
(4.4)
x1 (t)
y(t) = (0 1) x (t)
2
4.
ẋ1 (t) x1 (t)
" # !" # !
0 1 0 0
0
ẋ2 (t) = 0 1 x2 (t) + 0 u(t)
ẋ3 (t)−6 −11 −6 x3 (t) 1
(4.5)
x1 (t)
" #
y(t) = (1 0 0) x2 (t)
x3 (t)
4.5 Conclusion
Page 39
Lab No. 05: Stability using Root Locus
Objective:
To analyze the stability of a closed loop system using the root locus method, based on
the positions of the system’s poles and zeros on the s-plane. Additionally, the goal is to
design a root locus controller that can achieve the desired system response using MATLAB,
SIMULINK, or Python.
5.1 Theory
5.1.1 Fast Conversion Between the LTI Transfer Function and State Space
Case 1: If the transfer function has a numerator polynomial with a constant. The generic
transfer function is shown below:
b0
(5.1)
a0 sn + a1 sn−1 + a2 sn−2 + · · · + an−2 s2 + an−1 s + an
For this type of transfer function, the generic CCF state space model is shown below:
0 1 0 ··· ··· 0
0
0 0 1 0 ··· 0 0
.. .. .. .. .
. . . . ..
ẋ(t) =
.. .. .. .. .. u(t)
x(t) +
. . . .
. (5.2)
0 ··· ··· 1 0
− aan0 − an−1a0
− an−2
a0
· · · − aa20 − aa01 b0
y(t) = (1 0 0 · · · · · · 0) x(t)
Case 2: If the transfer function has a numerator polynomial with a degree one less than
that of the denominator polynomial. The generic transfer function is shown below:
b0 sn−1 + b1 sn−2 + b2 sn−3 + · · · + bn−3 s2 + bn−2 s + bn−1
(5.3)
a0 sn + a1 sn−1 + a2 sn−2 + · · · + an−2 s2 + an−1 s + an
For this type of transfer function, the generic CCF state space model is shown below:
0 1 0 ··· ··· 0
0
0 0 1 0 ··· 0 0
.. .. .. .. .
. . . . ..
ẋ(t) = .
.. ... .. x(t) + u(t)
..
. . . . . (5.4)
0 ··· ··· 1 0
− aan0 − an−1a0
− an−2
a0
· · · − a2
a0
− a1
a0 1
y(t) = (bn−1 bn−2 · · · b2 b1 b0 ) x(t)
Case 3: If the transfer function has a numerator polynomial with a degree equal to the
denominator polynomial. The generic transfer function is shown below:
b0 sn + b1 sn−1 + b2 sn−2 + · · · + bn−2 s2 + bn−1 s + bn
(5.5)
a0 sn + a1 sn−1 + a2 sn−2 + · · · + an−2 s2 + an−1 s + an
For this type of transfer function, the generic CCF state space model is shown below:
Page 40
0 1 0 ··· ··· 0
0
0 0 1 0 ··· 0 0
.. .. .. .. .
. . . . ..
ẋ(t) =
.. .. ... .. x(t) + .. u(t)
. . . . (5.6)
0 ··· ··· 1 0
an an−1 an−2 a2 a1
− a0 − a0 − a0 · · · − a0 − a0 1
y(t) = (bn − an b0 bn−1 − an−1 b0 · · · b2 − a2 b0 b1 − a1 b0 ) x(t) + b0 u(t)
Note the addition of the feedforward term in the state-space system due to improper transfer
function in the equation above. To convert from the controllable canonical form (CCF) state
space system to the transfer function, you essentially reverse the process mentioned earlier.
It is also feasible to convert the CCF state-space system to the observable canonical form
(OCF) state-space system. To do this, you transpose the CCF A matrix to get the OCF A
matrix, transpose the CCF B matrix to obtain the OCF C matrix, and transpose the CCF
C matrix to derive the OCF B matrix.
180◦ + (l − 1)360◦
ϕα = , α = 1, 2, · · · , P − Z
P −Z (5.8)
Re(ΣP − ΣZ)
α=
P −Z
where ΣP is the sum of all the locations of the poles, ΣZ is the sum of all the locations
of the explicit zeros and Re() denotes that we are only interested in the real part.
4. Find the break-away and break-in points. Write K in terms of s from the characteristic
equation 1 + G(s)H(s) = 0. Differentiate K with respect to s and make it equal to
zero. Substitute these values of s in the above equation. The values of s for which the
K value is positive are the break points.
Page 41
5. Find the angle of departure (ϕd ) and the angle of arrival (ϕa ).
ϕd = 180◦ − ϕ
ϕa = 180◦ + ϕ (5.9)
ϕ = ΣϕP − ΣϕZ
The block diagram in Figure (5.1) is a generic block diagram of a root locus controller with
P (s) as the transfer function of the plant that needs to be controlled, H(s) is the transfer
function of the feedback path, and K is the gain of the root locus controller.
5.2 MATLAB
To design the root locus controller in MATLAB, you need the plant’s transfer function and
consider the feedback path to have a unity gain. Then, use a command to plot the root locus
plot.
1 rlocus ( P ) ;
This plot will display the open-loop poles and the possible path for the closed-loop poles.
Use the command to establish the necessary conditions for designing a root locus controller.
1 sgrid ( zeta , wn ) ;
Where zeta is the damping ratio and wn is the undamped natural frequency of your desired
response. This command will add grid lines to show where your ζ and ωn intersect with your
locus lines. The point where all three lines intersect is your desired point. Then you can find
that point using the command.
1 [K , p ] = rlocfind ( P )
Where K will be the gain of your root locus controller needed to achieve the desired response,
and p will be a vector containing all your closed-loop poles of your complete control system.
5.3 Python
When designing a root locus controller in Python, you can utilize the ’root locus’ method
available in the Control Systems Library. This method allows you to create a visual represen-
tation of the root locus plot, which is a valuable tool for analyzing the behavior of a control
system. By leveraging the ’root locus’ method, you can gain insights into how the system’s
closed-loop poles vary with controller gain, ultimately aiding in the design and tuning of
your controller.
1 control . root_locus (G , plot = True )
Page 42
When the ’plot’ argument is set to true, it generates a root locus plot of the system. On the
other hand, if the ’plot’ argument is set to false, the root locus plot is not generated. The
root locus plot is an interactive graph that allows users to click on the locus points to display
the corresponding gain K required to achieve the desired damping ratio, which is also shown
on the plot. The dominant desired pole location can be obtained by using the values of ζ
and ωn and the equation:
p
Desired Pole = −ζωn ± jωn 1 − ζ 2 (5.10)
When analyzing a control system, it’s crucial to consider the dominant desired poles, which
are plotted onto the root locus plot. By identifying the intersection point between the dom-
inant desired pole and the root locus line, we can determine the gain K required to achieve
the desired system conditions. This process of evaluating pole placement and gain settings
allows us to effectively tune the control system to meet specific performance objectives.
5.4 Practical
5.4.1 Pre-Lab Tasks
Write code to solve the following problems using MATLAB, SIMULINK, or Python. Addi-
tionally, display the results of the code. The task involves plotting the root loci, determining
the desired conditions, and analyzing the transfer functions. For each transfer function, you
need to determine its order, identify the type of step response, and calculate the relevant
parameters required to describe the step response fully.
1
1. G(s) = s(s+2)
. Achieve ζ = 0.7 and ωn = 1.5 rad/s.
10
2. G(s) = s2 +4s+10
. Achieve ζ = 0.5 and ωn = 3 rad/s.
25
3. G(s) = s2 +4s+25
. Achieve ζ = 0.4 and ωn = 5 rad/s.
Page 43
64
4. G(s) = s2 +9.6s+64
. Achieve ζ = 0.6 and ωn = 8 rad/s.
4
5. G(s) = s2 +2s+4
. Achieve ζ = 0.3 and ωn = 2.5 rad/s.
1
P (s) = (5.11)
s(s + 7)(s + 11)
s2 − 4s + 20
P (s) = (5.12)
(s + 2)(s + 4)
Design a root locus controller on MATLAB/Python for the above plant. Using a unit
step input achieve a response with ζ ≈ 0.45 and ωn ≈ 3.4 rad/s.
Page 44
3. Consider the system having the following transfer function.
22624
P (s) = (5.13)
(s4 + 55s3 + 1076s2 + 8650s + 22600
Design a root locus controller on SIMULINK/Python for the above plant. Using a unit
step input achieve a response with ζ ≈ 1 and ωn ≈ 10 rad/s.
1. Convert the transfer function to its equivalent CCF state space representation:
s3 + 2s2 + 3s + 4
G(s) = (5.14)
s5 + 4s4 + 6s3 + 4s2 + 2s + 1
2. Convert the transfer function to its equivalent OCF state space representation:
3(s + 2)
G(s) = (5.15)
(s2 + 2s + 1)(s + 1)2
Page 45
3. Convert the CCF state space representation to its equivalent transfer function.
! !
0 1 0 0
ẋ(t) = 0 0 1 x(t) + 0 u(t)
−6 1 −4 1 (5.16)
y(t) = (1 0 −4) x(t)
4. Convert the OCF state space representation to its equivalent transfer function.
−4
! !
0 0 4
ẋ(t) = 1 0 −6 x(t) + 6 u(t)
0 1 −4 4 (5.17)
y(t) = (0 0 1) x(t)
5.5 Conclusion
Page 46
Lab No. 06: Frequency Response
Objective:
To utilize MATLAB, SIMULINK, or Python to generate frequency response plots, such as
Bode and Nyquist plots, for the system. Analyze stability by examining gain and phase
margins with Bode plots and assess the number of unstable closed-loop poles using the
Nyquist Stability Criterion with Nyquist plots.
6.1 Theory
6.1.1 Bode Plots
A Bode plot provides a graphical representation of the frequency response of a system. This
plot encompasses a Bode magnitude plot, which illustrates the magnitude in decibels (dB)
of the frequency response, and a Bode phase plot, which depicts the phase shift. In the
case of an LTI system with transfer function G(s), the Bode plot comprises a magnitude
plot, represented as |G(s = jω)| as a function of frequency ω, and a phase plot, depicted
as arg(G(s = jω)) as a function of frequency ω. Notably, the frequency ω is plotted on a
logarithmic scale on both plots, while the magnitude is displayed in dB and the phase is
indicated on a linear scale. This visual representation of the frequency response provides
valuable insights into the behavior of the system across a range of frequencies.
Page 47
behavior of feedback systems across different frequencies, making them an essential tool for
engineers working on control system design and analysis.
6.2 MATLAB
The command ’bode’ computes magnitudes and phase angles of the frequency response of
continuous-time, linear, time-invariant systems. When the command ’bode’ (without left-
hand arguments) is entered into the computer, MATLAB produces a Bode plot on the screen.
The most commonly used bode commands are
1 bode ( num , den )
2 bode ( num , den , w )
3 bode (A , B , C , D )
4 bode (A , B , C , D , w )
5 bode ( sys )
When invoked with left-hand arguments, such as [mag, phase, w] = bode(num, den, w) re-
turns the frequency response of the system in matrices mag, phase, and w. No plot is drawn
on the screen. The matrices mag and phase contain magnitudes and phase angles of the
frequency response of the system, evaluated at user-specified frequency points. The phase
angle is returned in degrees. The magnitude can be converted to decibels with the statement
magdB = 20 ∗ log10(mag). Other Bode commands with left-hand arguments are
1 [ mag , phase , w] = bode ( num , den )
2 [ mag , phase , w] = bode ( num , den , w )
3 [ mag , phase , w] = bode (A , B , C , D )
4 [ mag , phase , w] = bode (A , B . C , D , w )
5 [ mag , phase , w] = bode ( sys )
The MATLAB command ’nyquist’ computes the frequency response for continuous-time, lin-
ear, time-invariant systems. When invoked without left-hand arguments, ’nyquist’ produces
a Nyquist plot on the screen. The command
1 nyquist ( num , den )
draws the Nyquist plot of the transfer function where num and den contain the polynomial
coefficients in descending powers of s. Other commonly used Nyquist commands are
Page 48
1 nyquist ( num , den , w )
2 nyquist (A , B , C , D )
3 nyquist (A , B , C , D , w )
4 nyquist ( sys )
The command involving the user-specified frequency vector w, such as nyquist(num, den, w)
calculates the frequency response at the specified frequency points in radians per second.
When invoked with left-hand arguments such as
1 [ re , im , w] = nyquist ( num , den )
2 [ re , im , w] = nyquist ( num , den , w )
3 [ re , im , w] = nyquist (A , B , C , D )
4 [ re , im , w] = nyquist (A , B , C , D , w )
5 [ re , im , w] = nyquist ( sys )
MATLAB returns the frequency response of the system in the matrices re, im, and w. No
plot is drawn on the screen. The matrices re and im contain the real and imaginary parts
of the frequency response of the system, evaluated at the frequency points specified in the
vector w. Note that re and im have as many columns as outputs and one row for each
element in w.
6.3 Python
In Python, the Bode plot can be plotted using the Control Systems Library.
1 mag , phase , omega = control . bode_plot (G , plot = True , dB = Talse , deg = True
)
The ’plot = T rue’ parameter is useful for returning the magnitude, phase, and frequencies. If
they are not required, then it can be skipped. The gain and phase margins can be calculated
as follows:
1 wgc = np . interp (1 , np . flipud ( mag ) , np . flipud ( omega ) )
2 wpc = np . interp ( - np . pi , np . flipud ( phase ) , np . flipud ( omega ) )
3 PM = ( np . interp ( wgc , omega , phase ) - ( - np . pi ) ) # rad
4 GM = -20 * np . log10 ( np . interp ( wpc , omega , mag ) ) # dB
The linear interpolation function is used to find the points for the crossover frequencies and
the gain and phase margin. In Python, the Nyquist plot can be plotted using the control
systems library. The count for the encirclements about the critical point can also be obtained
using the ’nyquist response’ function, if not needed then the plot can simply be obtained by
the ’nyquist plot’ function.
1 response = control . nyquist_response ( G )
2 count = response . count
3 print ( ’ Encirclements about -1 = ’ , count , ’\ n ’)
4 control . nyquist_plot ( response )
6.4 Practical
6.4.1 Pre-Lab Tasks
Write code to solve the following problems using MATLAB, SIMULINK, or Python. Addi-
tionally, display the results of the code. Plot the Bode and Nyquist plots and analyze the
stability of the individual systems provided below.
Page 49
1.
14
G(s) = (6.4)
s2 + 2s + 5
2.
2
G(s) = (6.5)
(s + 1)(s + 2)(s + 3)
3.
1 2 0
ẋ(t) = 0 1 x(t) + 1 u(t) (6.6)
y(t) = (1 0) x(t)
4. ! !
0 1 0 0
ẋ(t) = 0 0 1 x(t) + 0 u(t)
1 −2 3 1 (6.7)
y(t) = (1 0 0) x(t)
Page 50
5.
1
G(s) = (6.8)
(s2 + 1)2
9(s2 + 0.2s + 1)
P (s) = (6.9)
s(s2 + 1.2s + 9)
1
P (s) = (6.10)
s2 + 0.8s + 1
Plot a Nyquist plot for this transfer function on MATLAB/Python. Also analyze
whether the transfer function is stable, marginally stable, or unstable.
Page 51
Plot a Bode diagram and Nyquist plot for this state space on MATLAB/Python. Then
analyze whether the transfer function is stable, marginally stable, or unstable.
Page 52
Figure 6.3: Task 3
6.5 Conclusion
Page 53
Lab No. 07: PID Controller Design
Objective:
To gain proficiency in designing PID controllers for LTI systems and effectively implementing
them using MATLAB, Python, and hardware.
7.1 Theory
7.1.1 Proportional Control Action
Proportional control action in a PID controller is a fundamental mechanism to correct errors
in a control system by adjusting the output proportionally to the error signal. The error
signal is the difference between the desired setpoint and the measured process variable. In
proportional control, the controller produces an output directly proportional to this error,
meaning that as the error increases, the control output increases proportionally. This ap-
proach helps to reduce the overall error and improve the system’s responsiveness. However,
while proportional control can effectively decrease the magnitude of the error, it may not
eliminate it, often resulting in a steady-state error known as offset. The time domain equation
and transfer function are provided below for reference.
u(t) = KP e(t)
(7.1)
U (s) = KP E(s)
Page 54
carefully tuned. The time domain equation and transfer function are provided below for
reference.
d
u(t) = KD e(t)
dt (7.3)
U (s) = sKD E(s)
1. P-only Controller
2. PI Controller
3. PD Controller
4. PID Controller
Page 55
2. Ziegler-Nichols Method: The Ziegler-Nichols method is a popular empirical tech-
nique for tuning PID controllers that involves determining the optimal controller pa-
rameters through systematic experimentation. The process begins with setting the
integral and derivative gains to zero and gradually increasing the proportional gain KP
until the system reaches the point of sustained oscillation, known as the ultimate gain
KU . The oscillation period at this gain is recorded as the ultimate period TU . Using
these values, the PID gains are then calculated based on established empirical formu-
las. For a classic PID controller, the Ziegler-Nichols tuning rules are KP = 0.6KU ,
KI = 2K TU
P
, and KD = KP8TU . This method provides a straightforward approach to
achieving a good initial set of PID parameters that can be fine-tuned further based on
the specific needs of the system. It is particularly useful in systems where the dynamics
are well understood and a quick, practical tuning solution is desired.
7.2 MATLAB
In MATLAB, the ’pid’ function is used to create and configure a PID (Proportional-Integral-
Derivative) controller object, which can be utilized in control system design and simulation.
The function allows you to specify the proportional, integral, and derivative gains for the
PID controller, and it can also be customized with additional parameters such as the filter
coefficient for the derivative term, which helps to manage noise sensitivity.
1 C = pid ( Kp , Ki , Kd )
7.3 Practical
7.3.1 Pre-Lab Tasks
Complete the following multiple-choice questions on paper.
1. In a PID controller, which term helps to reduce overshoot and improve stability?
(a) Integral
(b) Proportional
(c) Derivative
(d) Feedforward
2. Which of the following tuning methods involves adjusting gains to reach the point of
oscillation?
3. What effect does increasing the derivative gain have on the PID controller’s perfor-
mance?
Page 56
4. Which component of a PID controller is responsible for eliminating steady-state error?
(a) Integral
(b) Proportional
(c) Derivative
(d) Feedback
6. When tuning a PID controller manually, what is the usual first step?
(a) Set all gains to zero and adjust the proportional gain
(b) Adjust the integral gain
(c) Increase the derivative gain
(d) Use a software tool for automatic tuning
(a) Proportional
(b) Predictive
(c) Proactive
(d) Phase
8. In the PID controller, what is the primary role of the derivative term?
(a) Interactive
(b) Input
(c) Integral
(d) Initial
10. What is the standard formula for the derivative gain in the Ziegler-Nichols tuning
method?
Kp Tu
(a) Kd = 8
0.5Ku
(b) Kd = Tu
2Kp
(c) Kd = Tu
Kp Tu
(d) Kd = 4
Page 57
7.3.2 Lab Tasks
1. Design a PD controller for a plant, GP = s21+1 , on MATLAB/Python. Analyze and list
the deficiencies in the step response of the plant. The resulting unit step response should
be overdamped having an approximate settling time of 0.1 sec and an approximate rise
time of 0.03 sec. Show the step response with settling time and rise time labels on
them.
2. Design a PID controller for a plant, having poles at s = −2±7j and having a numerator
coefficient of 1, on MATLAB/Python. Analyze and list the deficiencies in the step
response of the plant. The resulting unit step response should be underdamped with
an approximate maximum overshoot of 5.6% and an approximate rise time of 0.02 sec.
Show the step response with labels of maximum overshoot, settling time, and rise time
on them.
K
GP = (7.4)
τs + 1
Page 58
where K is the second last digit of your registration number and τ in seconds is the
last digit of your registration number. Assuming the input and output to the system
is voltage, design and implement a suitable P-only controller on hardware.
2. Design and implement a suitable PI controller for a series RC circuit in which the
output is the voltage across the capacitor. Use R = 1 KΩ and C = 1 µF . Simulate
the circuit using either Proteus or Multisim and provide the circuit diagram with values.
Page 59
3. Design and implement a suitable PD controller for a series RL circuit in which the
output is the voltage across the inductor. Use R = 1 KΩ and L = 1 H. Simulate the
circuit using either Proteus or Multisim and provide the circuit diagram with values.
4. Design and implement a suitable PID controller for a series RL circuit in which the
output is the voltage across the inductor. Use R = 1 KΩ and L = 1 mH. Simulate the
circuit using either Proteus or Multisim and provide the circuit diagram with values.
7.4 Conclusion
Page 60
Lab No. 08: Phase Lead Lag Design
Objective:
To enhance the performance of a root locus controller by incorporating a lead-lag compen-
sator, and utilize MATLAB or Python to design the lead-lag compensator.
8.1 Theory
8.1.1 Lead Compensator using Root Locus
When designing a lead compensator using root locus, the primary objective is to improve the
stability and transient response of a control system. Start by analyzing the root locus plot
of your open-loop system, which illustrates how the poles of the system move as you change
the gain. To enhance system performance, introduce a lead compensator, which consists of
a zero and a pole. The zero is placed at a higher frequency than the pole, creating a phase
lead that helps to increase the phase margin of the system. This phase lead moves the root
locus plot, shifting the poles of the closed-loop system to positions that enhance stability
and speed up the response. For example, if the original poles are too close to the imaginary
axis, the lead compensator can push them further to the left, resulting in a faster and more
stable response.
s − z0
C(s) = KC (8.1)
s − p0
Where the magnitude of z0 is less than the magnitude of p0 .To design the lead compensator
effectively, follow these steps:
1. First, determine the desired position of the closed-loop poles to achieve the desired
performance, such as increased stability or reduced overshoot.
2. Place the zero of the compensator strategically to provide the required phase lead.
3. Position the pole of the compensator to the left of the zero further away from the origin
to maximize the phase lead while maintaining control over the system dynamics.
4. Use simulation tools like MATLAB/Python to plot the modified root locus and verify
that the closed-loop poles meet the design specifications.
5. Through an iterative process of adjusting the compensator parameters and observing
the effects on the root locus, fine-tune the compensator to achieve an optimal balance
between stability and transient response.
Page 61
where ω is the frequency, ωz is the zero frequency, and ωp is the pole frequency. The com-
pensator should be designed to increase the phase plot by at least 30◦ at the gain crossover
frequency. Simulate the system once you add the compensator to check if the phase margin
meets the design requirements. Adjust the zero and pole locations iteratively until the de-
sired performance is achieved. Here’s an illustrative example of a Bode plot with and without
the lead compensator to visualize the effect:
1. Analyze the Open-Loop System: Plot the root locus of the open-loop transfer function
G(s)H(s), where G(s) is the plant and H(s) is the feedback path. Identify the dominant
poles and zeros.
2. Add a Lag Compensator: Choose p0 and z0 such that the pole is placed closer to the
real axis compared to the zero. This will effectively slow down the system response
but improve steady-state accuracy. The compensator should shift the root locus so
that the closed-loop poles move to desired locations with improved stability margins.
Check your design by verifying the root locus of the compensated system and ensuring
it meets performance criteria.
Page 62
the low-frequency gain to reduce steady-state error. The compensator has a zero and a pole,
with the pole positioned at a lower frequency than the zero, creating a low-pass filter effect.
To design the lag compensator, begin by plotting the open-loop frequency response using
a Bode plot, which includes both the magnitude and phase plots. Your goal is to increase
the low-frequency gain to reduce steady-state error without significantly altering the phase
margin or transient response. The formula to calculate the gain adjustment provided by the
lag compensator is:
ω ω
Phase Lag = tan−1 ( ) − tan−1 ( ) (8.4)
ωz ωp
where ω is the frequency, ωz is the zero frequency, and ωp is the pole frequency. Ensure
the compensator is designed to increase the gain at low frequencies while the phase shift
remains within acceptable limits to maintain system stability. Simulate the system with the
lag compensator verify the improvements in steady-state performance and confirm that the
phase margin remains stable. Adjust the compensator parameters iteratively to achieve the
desired performance. Below is an illustrative Bode plot showing the effect of adding a lag
compensator:
Page 63
5
G(s) = (8.6)
s2
+ 20s
To achieve a settling time of 0.04 s a maximum overshoot of 5% for a step input, and a
steady-state error of 0.001 for a unity ramp input.
The first step is to find the desired poles of the closed-loop system. They can be found as
follows:
r
ln2 0.05
ζ= = 0.69
π 2 + ln2 0.05
4 (8.7)
ωn = = 144.9 rad/s
0.69 × 0.04 p
Desired Pole = −ζωn ± jωn 1 − ζ 2 = −100 ± 105j
The gain K of the root locus controller can be found using the root locus command on
MATLAB/Python, which is approximately 3821.4. Using the above results we can design a
lead compensator to achieve the desired settling time and maximum overshoot. The equation
for the root locus controller with lead compensator is given below.
s − z0
C(s) = K (8.8)
s − p0
Where z0 and p0 are the zero and pole of the lead compensator. A lead compensator shifts the
root locus to the left, so the pole-zero pair must be in the left half of the s-plane. The open-
loop poles are located at s = 0 and s = 20. To effectively cancel the pole-zero pair, another
way to place the zero is on top of the pole. Therefore, the zero of the lead compensator can
be placed at s = −20 for pole-zero cancellation. Calculations to find the location of p0 are
shown below in the diagram.
X X
θz − θp = −180◦
θz0 =−20 − θp=−20 − θp=0 − θp0 = −180◦
104.8
θp0 = 180◦ − θp=0 = 180◦ − tan( ) ≈ 133.6◦ (8.9)
100
104.8
tan(133.6◦ ) = ⇒ x ≈ −99
x
p0 = −99 − 100 ≈ −200
Page 64
The designed root locus controller with the lead compensator will now achieve the desired
settling time and maximum overshoot. To achieve the steady-state error we add the lag
compensator. To find out the steady-state error we can use the table below.
A lag compensator shifts the root locus to the right, so the pole-zero pair must be in the
left half of the s-plane closer to the origin. The equation for the root locus controller with
lead-lag compensator is given below.
s + 20 s − z1
C(s) = 3821.4 (8.10)
s + 200 s − p1
Where z1 and p1 are the zero and pole of the lag compensator. In the case of the lead
compensator, the zero is placed first. In the case of the lag compensator, the pole is placed
first. The pole is placed near the origin in the left half of the s-plane. Placing the pole as
−0.1. Then the steady-state error is and the zero location can be calculated as follows.
s + 20 5
kv = lim s(3821.4 )
x→0 s + 200 s(s + 20)
1
kv = 95.535 ⇒ Ess = = 0.01
kv (8.11)
Ess z pEss
= ⇒z=
DEss p DEss
−0.1 × 0.01
z= ⇒ z = −1
0.001
The transfer function of the root locus controller with lead-lag compensator is given below
and approximately achieves all the desired conditions.
s + 20 s + 1
C(s) = 3821.4 (8.12)
s + 200 s + 0.1
8.3 Practical
8.3.1 Pre-Lab Tasks
Complete the following multiple-choice questions on paper.
1. Which of the following compensators can increase the phase margin while also increas-
ing the low-frequency gain to reduce steady-state error?
Page 65
(c) Increase system oscillations
(d) Stabilize an unstable system
(a) It introduces a pole and zero close to each other on the left-hand side of the s-plane
(b) It provides phase lag to increase stability
(c) It provides phase lead and improves the phase margin
(d) It reduces the speed of the system response
5. When designing a lead compensator using root locus, the compensator’s zero should
be placed:
8. Which of the following compensators is typically used to improve both the transient
response and the steady-state error of a system?
Page 66
(b) Pull the root locus towards the right half-plane
(c) Shift the entire root locus downward
(d) Make the system marginally stable
(a) It reduces the phase margin while improving the transient response
(b) It only affects the steady-state error of the system
(c) It provides phase lead at high frequencies and phase lag at low frequencies
(d) It always increases the system bandwidth
Page 67
5
2. Design a lead-lag compensator for a plant with the transfer function G(s) = s2 +4s+5
to achieve a ωn of 6 second and a damping ratio of 0.6. Also, reduce the steady-state
error of a step response to 0.1.
10
3. Design a lead compensator for a plant with the transfer function G(s) = (s−1)(s+3) to
achieve a ωn of 4 second and a damping ratio of 0.8. Also, reduce the steady-state error
of a step response to 0.1.
8.4 Conclusion
Page 68
Lab No. 09: On-Off Controller on PID Trainers
Objective:
To implement an on-off controller on SIMULINK, Python, and hardware.
9.1 Theory
Sometimes, the control element can only be in one of two positions: fully closed or fully open.
It does not operate at any intermediate position, such as partly open or partly closed. The
control system designed to manage such elements is known as an on-off controller. In this
system, when the process variable changes and exceeds a certain preset level, the system’s
output instantly switches to fully open, providing 100% output.
In a typical on-off control system, the output leads to a change in the process variable. This
means that the process variable begins to change in the opposite direction due to the output.
When the process variable crosses a predetermined level again, the output value of the system
is immediately closed, reducing the output to 0%.
With no output, the process variable continues to change in its normal direction. Once
it crosses the preset level again, the output valve of the system reopens, providing 100%
output. This cycle of closing and opening the output valve continues as long as the on-off
control system is in operation. The block diagram below illustrates the closed-loop feedback
temperature control system managed by an on-off controller.
Page 69
Figure 9.2: Response of an On-Off Controlled System
infinite, causing the output response to saturate either at the positive or negative supply
voltage, depending on the difference between its input signals.
The output from the comparator can be utilized to control a relay, serving as an on-off
controller in the hardware setup. This relay plays a crucial role by directly linking the power
supply to the plant. When the relay is activated (turned on), it establishes a connection that
allows the plant to receive power. Conversely, when the relay is deactivated (turned off), it
disconnects the plant from the power source.
Page 70
9.2 Practical
9.2.1 Pre-Lab Tasks
Complete the following multiple-choice questions on paper.
1. What is hysteresis in an On-Off controller?
5. What is the term for the undesired rapid switching in On-Off controllers?
(a) Overshoot
(b) Hysteresis
(c) Cycling
(d) Chattering
Page 71
(b) A refrigerator thermostat
(c) An industrial robotic arm
(d) A PID-controlled motor
8. In an On-Off controller, the control output is ON when:
(a) The error is below the setpoint
(b) The error is above the setpoint
(c) The error exceeds the hysteresis band
(d) The error is within the hysteresis band
9. What is the primary characteristic of an On-Off controller?
(a) Continuous control of the output
(b) Proportional control of the output
(c) Discrete switching between two states
(d) Control based on derivative action
10. What is the primary disadvantage of an On-Off controller?
(a) It is too complex to implement
(b) It requires high computational power
(c) It can result in frequent switching and wear on actuators
(d) It does not work in closed-loop systems
1
G(s) = (9.1)
(s + 7)(s + 11)
Design an on-off controller on SIMULINK to achieve a constant output level of 5.
Page 72
3. Design and implement an on-off controlled water level system on Proteus or Multisim.
Design to turn on a water pump if the water level falls below the threshold.
9.3 Conclusion
Page 73
Lab No. 10: Digital Servo–Control Experiments
Objective:
Implement a servo motor control system using the ATmega16 microcontroller on a micro-
processor trainer. This involves developing a robust program that facilitates precise control
of the servo motor’s position and speed, enabling various applications such as robotic arms,
automated systems, and modeling tasks.
10.1 Theory
A servo motor is an electric device used for precise control of angular rotation. It is used
where precise control is required, like in the case of control of a robotic arm.
It consists of a suitable motor with control circuitry for precise position control of the motor
shaft. It is a closed-loop system. The rotation angle of the servo motor is controlled by
applying a PWM signal to it. By varying the width of the PWM signal, we can change the
rotation angle and direction of the motor.
Listing 10.1: AVR Code
1 # define F_CPU 8000000 UL /* Define CPU Frequency 8 MHz */
2 # include < avr / io .h > /* Include AVR std . library file */
3 # include < stdio .h > /* Include std . library file */
4 # include < util / delay .h > /* Include Delay header file */
5
6 int main ( void )
7 {
8 DDRD |= (1 < < PD5 ) ; /* Make OC1A pin as output */
9 TCNT1 = 0; /* Set timer1 count zero */
10 ICR1 = 2499; /* Set TOP count for timer1 in ICR1 register */
11
12 /* Set Fast PWM , TOP in ICR1 , Clear OC1A on compare match , clk /64 */
13 TCCR1A = (1 < < WGM11 ) |(1 < < COM1A1 ) ;
14 TCCR1B = (1 < < WGM12 ) |(1 < < WGM13 ) |(1 < < CS10 ) |(1 < < CS11 ) ;
15 while (1)
16 {
17 OCR1A = 65; /* Set servo shaft at -90 position */
18 _delay_ms (1500) ;
19 OCR1A = 175; /* Set servo shaft at 0 position */
20 _delay_ms (1500) ;
21 OCR1A = 300; /* Set servo at +90 position */
22 _delay_ms (1500) ;
23 }
24 }
Page 74
10.2 Practical
1. Start by entering the program, then assemble or compile it to create the object file and
hex file. Next, download the hex file into the microcontroller’s code memory. Use the
trainer to run the program and check the results. Afterward, modify the code so that
the servo motor moves in accordance with the position of a potentiometer. Finally,
document the complete working code.
10.3 Conclusion
Page 75
Lab No. 11: Motor Control Trainer
Objective:
To implement a physical model of a system in SIMULINK using Simscape. Then obtain a
mathematical model of the physical system.
11.1 Theory
Simscape enables you to rapidly create models of physical systems within the SIMULINK
environment. With Simscape, you build physical component models based on physical con-
nections that directly integrate with block diagrams and other modeling paradigms. You
model systems such as electric motors, bridge rectifiers, hydraulic actuators, and refriger-
ation systems, by assembling fundamental components into a schematic. Simscape add-on
products provide more complex components and analysis capabilities.
Simscape helps you develop control systems and test system-level performance. You can
create custom component models using the MATLAB-based Simscape language, which en-
ables text-based authoring of physical modeling components, domains, and libraries. You
can parameterize your models using MATLAB variables and expressions, and design control
systems for your physical system in SIMULINK. To deploy your models to other simulation
environments, including hardware-in-the-loop (HIL) systems, Simscape supports C-code gen-
eration.
Consider the spring mass damper system shown in the figure above. To implement this
physical model in Simscape, add the following components to your model:
Page 76
4. Simscape → Foundation Library → Mechanical → Translational Elements → Transla-
tional Spring for spring ‘k’.
5. Simscape → Foundation Library → Mechanical → Translational Elements → Mechan-
ical Translational Reference to provide reference to the system.
6. Simscape → Foundation Library → Mechanical → Mechanical Sensors → Ideal Trans-
lational Motion Sensor to output position ‘x’.
7. Simscape → Utilities → Solver Configuration.
Once all the elements are added to your model then connect them in the configuration shown
in the figure below.
Once this is done then your physical model is ready for simulation. But before proceeding
this model requires an input and a graph to display the position output. To achieve that we
must convert a SIMULINK signal to a physical signal for input and vice versa for the output.
For that, we will use Simscape → Utilities → Simulink-PS Converter to convert a SIMULINK
signal to a physical signal, and Simscape → Utilities → PS-Simulink Converter to convert
a physical signal to SIMULINK signal. Finally, we will add a step source from SIMULINK
Sources and scope from Sinks. Then connect in the configuration shown in Figure (11.3).
Now you can simulate to view the step response of the spring mass damper system.
Now to find out the mathematical model of the system you first have to specify the input
and output of the model. For that click on the connection of the step source go in Linear
Analysis Points then select Input Perturbation to specify this as an input to the model.
Next, click on the connection of the scope go into Linear Analysis Points then select Output
Measurement to specify this as an output to the model. Next in the apps tab above select
the Model Linearizer app. You will see a window shown in Figure (11.4).
In the Linearize tool select the Step to obtain a mathematical model of your system, this
will also plot the open loop step response of your system, which you can verify from your
SIMULINK scope. Once it is finished working a new variable in the Linear Analysis Workspace
is created of the name ‘linsys1’.Drag this variable to the MATLAB Workspace. This variable
holds the state space model of your system, which you can convert to a transfer function as
well.
Page 77
Figure 11.3: Block Diagram of a Spring-Mass Damper System in SIMULINK
Page 78
Figure 11.5: Electronic Circuit Block Diagram in SIMULINK
11.2 Practical
1. Design and implement a root locus controller on the motor speed plant above on
SIMULINK.
11.3 Conclusion
Page 79
Lab No. 12: Controller Design using Bode Design GUI
(Graphical User Interface)
Objective:
To use the Control System Designer app on MATLAB to design a controller.
12.1 Theory
Using the Control System Designer app, you can:
1. Define control design requirements on time, frequency, and pole/zero response plots.
2. Tune compensators using:
(a) Automated design methods, such as PID tuning, IMC, and LQG.
(b) Graphically tune poles and zeros on design plots, such as Bode and root locus.
(c) Optimization-based control design to meet time-domain and frequency-domain
requirements using SIMULINK Design Optimization.
3. Visualize closed-loop and open-loop responses that dynamically update to display the
control system performance.
The image above shows the Control System Designer window. The first two options on the
toolbar are for the session, the first one to open a previous session and the second one to save
the current session. The next option is to edit the architecture. This holds multiple kinds
of block diagrams that are used in control systems. The next option is used to select the
tuning method for designing the control system. This function holds many different options
to tune your controller. The next option is used to display a new plot to perform analysis
and monitor different requirements.
Page 80
12.1.1 Worked Example
For this example, consider a plant:
1
G(s) = (12.1)
s+1
With the following design conditions:
First store the transfer function in G in MATLAB and open the edit architecture option to
load that transfer function to the app.
Press the import button next to the G and import the transfer function from MATLAB as
shown in the figure above. Adding the plant transfer function will update the Bode plot,
Step Response, and the Root Locus of the plant. After adding the plant transfer function
we have to add design requirements.
The step design requirements are to be added to the step plot labeled from r to y. This is
the step plot for the output y with respect to the reference step input. Right click on that
step response and add a new design requirement.
Enter the design requirements as shown in Figure (12.3) below and then press Ok. Now your
step response should show two regions; one is white representing the allowed region, and the
second is yellow representing the disallowed region. So, keeping your step response in the
white region means that the required conditions are met. To add the design requirement for
crossover frequency, right click on the bode plot and add a new design requirement.
Enter the design requirements as shown in Figure (12.4) below. To meet the zero steady-
state error design requirement, add an integrator to the compensator. Right click the Root
Locus Editor plot area and select Add Pole or Zero → Integrator. To create a desirable
shape for the root locus plot, add a real zero near −2. Right-click the root locus plot area
Page 81
Figure 12.3: New Design Requirement Window in Step Response
and select Add Pole or Zero → Real Zero. In the root locus plot, left click the real axis near
−2. To create a faster response by increasing the compensator gain, in the Bode Editor,
drag the magnitude response upward. To satisfy the crossover frequency requirement, keep
the response below the exclusion region in the Bode editor.
Finally, when you are done with the changes press store on the toolbar to create a final
design. And then you can export the design back to either MATLAB or SIMULINK.
12.2 Practical
1. Consider a plant having the following transfer function.
461.63
G(s) = (12.2)
s3 + 1021s2 + 4845s
Design a controller using the Control System Designer app with the following design
requirements:
Page 82
• Bandwidth greater than 5 rad/s.
12.3 Conclusion
Page 83