0% found this document useful (0 votes)
1 views

EE-371 Linear Control System Lab Manual

The document is a lab manual for the Linear Control Systems course at PNEC NUST, detailing the curriculum and experiments related to MATLAB and Python programming. It includes sections on lab rubrics, assessment records, and detailed experiment sheets, focusing on programming basics, matrix operations, plotting, and solving equations. The manual aims to familiarize students with essential tools and techniques for analyzing linear control systems.

Uploaded by

rayemma6868
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

EE-371 Linear Control System Lab Manual

The document is a lab manual for the Linear Control Systems course at PNEC NUST, detailing the curriculum and experiments related to MATLAB and Python programming. It includes sections on lab rubrics, assessment records, and detailed experiment sheets, focusing on programming basics, matrix operations, plotting, and solving equations. The manual aims to familiarize students with essential tools and techniques for analyzing linear control systems.

Uploaded by

rayemma6868
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

PAKISTAN NAVY ENGINEERING COLLEGE, NATIONAL UNIVERSITY

OF SCIENCES AND TECHNOLOGY, KARACHI


PNEC NUST

Student Lab Manual

Linear Control Systems


EE-371

Name:
CMS ID: Class: Section:
Batch: Semester:
Department:

EE UG Revised Curricula 2020


DEPARTMENT OF ELECTRONICS & POWER ENGINEERING
Lab Manual Contents
1. Lab Rubrics with Marks Distribution
2. List of Experiments
3. Lab Assessment Record
4. Detailed Experiment Sheets
National University of Sciences & Technology-
Pakistan Navy Engineering College
(Group-1): Engineering Lab Rubric
List of Experiments
Lab Assessment Record

Course Title CMS ID Student Name Department


Linear Control Systems EE
Lab No. 01: Introduction to MATLAB/SIMULINK
Programming and Simulation

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.

1.1.1 The Basics


Calculator functions work as you would expect:
1 (1 + 4) * 3
+ is addition, − is subtraction, / is division, ∗ is multiplication, and ∧ is an exponent.
Everything in MATLAB is a matrix. (If it’s a scalar, it’s a 1 × 1 matrix, and if it’s a vector,
it’s an N × 1 or 1 × N matrix.)
1 a = 3
To create a vector is similar. Spaces separate each element; the whole vector is in square
brackets:
1 v = [1 3 6 8 9]
To create a vector of values going in even steps from one value to another value,
1 b = 1:0.5:10
This goes from 1 to 10 in increments of 0.5, any increment, positive or negative can be used.
To turn a row vector into a column vector, just put (′ ) at the end of it. (This is also how to
get the transpose of a matrix.) To create a matrix, you could do something like:
1 c = [1 3 6; 2 7 9; 4 3 1]
The semicolons indicate the end of a row. All rows must be the same length. Whenever you
assign a value in MATLAB, it will print out the entire value you have just assigned. If you
put a semicolon at the end, it will not print it out, which is much faster.

1.1.2 Dealing with Matrices


Once you have a matrix, you can refer to specific elements in it. MATLAB indexes matrices
by row and column. c(3, 1) is the element in the 3rd row, 1st column, which is 4. c(2 : 3, 1 : 2)
gives you the elements in rows 2 − 3, and columns 1 − 2, so you get
1 2 7
2 4 3
As a result. c(1 : 3, 2) gives you the elements in rows 1 − 3, and the second column, that is,
the entire second column. You can shortcut this to:
1 c (: , 2)
Telling MATLAB to use all the rows in the second column. You can get a whole row of a
matrix with
1 c (1 , :)

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.3 Useful Functions


MATLAB has a lot of built-in functions. To use a function, just type function-name (argu-
ments) with the appropriate name and arguments. If you create a time vector t = 1 : 0.25 : 6;
you can get standard functions like
1 x = sin ( t )
Which returns a vector the same size as t, with values for the sin of t at all points. You can
also do things like
1 s = sum ( c )
Which sums all the columns in a matrix c and returns a row vector of the sums. The function
1 d = det ( c )
It takes a matrix c and returns the determinant of it.

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 )

1.1.7 Solution of Equations using Symbolic Toolbox


The symbolic toolbox in MATLAB can solve many types of equations, including non-linear
ones and several simultaneous equations.
Example 1: Find the solutions to an algebraic simultaneous equation:
x2 y 2 = 0
x−y (1.1)
=a
2
1 syms x y a ;
2 eq1 = ( x ^ 2) * ( y ^ 2) == 0;
3 eq2 = x - y / 2 == a ;
4 [ solx , soly ] = solve ( eq1 , eq2 )
We can control the precision with which MATLAB performs calculations involving irrational
numbers. VPA (Variable Precision Arithmetic) is used to find numerical solutions.
Example 2: Find all the solutions to the function f (x) = 6x7 − 2x6 + 3x3 − 8.
1 syms f ( x ) ;
2 f ( x ) = 6 * x ^ 7 - 2 * x ^ 6 + 3 * x ^ 3 - 8;
3 sol = vpasolve ( f )

1.1.8 Using MATLAB for Laplace Transforms


Example 1: You can compute the Laplace transform using the symbolic toolbox of MATLAB.
Computing Laplace transform of f = t.
1 syms f t
2 f = t;
3 laplace ( f )
Where f and t are the symbolic variables, f is the function, and t is the time variable. The
inverse transform can also be computed using MATLAB. If you want to compute the inverse
24
Laplace transform of F (s) = s(s+8) ;
1 syms F s
2 F = 24 / ( s * ( s + 8) ) ;
3 ilaplace ( F )

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 )

N (s) A(1) A(2) A(n)


=K+ + + ··· + (1.2)
D(s) s − p(1) s − p(2) s − p(n)

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.

1.2.1 The Basics


Variable assignment works as follows:
1 a = 3
Calculator functions work as you would expect:
1 a = (1 + 4) * 3
+ is addition, − is subtraction, / is division, ∗ is multiplication, and ∧ is an exponent. To
create a vector in Python the numpy library needs to be imported.
1 import numpy as np
Using the ’array’ method in the numpy library a vector can be created. Commas separate
each element; the whole vector is in square brackets:
1 v = np . array ([1 , 3 , 6 , 8 , 9])
To create a vector of values going in even steps from one value to another value the method
of ’arange’ can be used in the numpy library.
1 v = np . arange (1 , 10.5 , 0.5)
This goes from 1 to 10 in increments of 0.5, any increment, positive or negative can be used.
To create a matrix, the ’array’ method in numpy can be used:
1 c = np . array ([[1 , 3 , 6] , [2 , 7 , 9] , [4 , 3 , 1]])
The square braces indicate the end of a row. All rows must be the same length.

1.2.2 Dealing with Matrices


Once you have a matrix, you can refer to specific elements in it. Python indexes matrices by
row and column. c[2, 0] is the element in the 3rd row, 1st column, which is 4. c[1 : 3, 0 : 2])
gives you the elements in rows 2 − 3, and columns 1 − 2, so you get
1 2 7
2 4 3

If you want to access all the elements in the 2nd column:


1 c [: , 1]

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.2.6 Using Python for Laplace Transforms


Example 1: You can compute the Laplace transform using the symbolic library of Python.
Computing Laplace transform of f=t.
1 t , s = syms . symbols ( ’t , s ’)
2 f = t
3 sol = syms . l aplace _trans form (f , t , s )
4 print ( " Laplace Transform = " + str ( sol ) )
Where f and t are the symbolic variables, f is the function, and t is the time variable. The
inverse transform can also be computed using Python. If you want to compute the inverse
24
Laplace transform of F (s) = s(s+8) ;
1 t , s = syms . symbols ( ’t , s ’)
2 F = 24 / ( s * ( s + 8) )
3 sol = syms . i n v e r s e _ l a p l a c e _ t r a n s f o r m (F , s , t )
4 print ( " Inverse Laplace Transform = " + str ( sol ) )

1.2.7 Partial Fractions using Python


You define the transfer function as a symbolic expression and then calculate the partial
fraction expansion using the ’apart’ function in the ’sympy’ library.
1 s = syms . symbols ( ’s ’)
2 F = (4 * s * s + 4 * s + 4) / ( s * s * ( s * s + 3 * s + 2) )
3 sol = syms . apart ( F )
4 print ( " Partial Fractions = " + str ( sol ) + " \ n \ n " )

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

Perform the following operations on the matrix above:


(a) Print the diagonal elements in the matrix.
(b) Print a submatrix that contains elements of the 2nd and 3rd rows and 2nd , 3rd , and
4th columns.
(c) Print the 1st column vector.
(d) Print the determinant of the matrix.

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.

3. Create a polynomial q = x3 + 2x2 − 5x + 7. Perform the following operations on the


polynomial:
(a) Print the value of the polynomial in the domain −10 ≤ x ≤ 10.
(b) Print the roots of the polynomial.

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)
.

1.3.2 Lab Task


4s2 +4s+4
1. Write the partial fraction expansion of the transfer function s2 (s2 +3s+2)
. Then use
MATLAB/Python to verify your result.

1.3.3 Post-Lab Tasks


Answer the following short questions.

1. How does MATLAB/Python represent scalars, vectors, and matrices?

Page 8
2. How does MATLAB/Python handle trigonometric functions like sin() when applied to
arrays or vectors?

3. Describe the process of plotting a graph in MATLAB/Python. Include essential syntax


elements.

4. Explain the purpose of the subplot() function in MATLAB/Python. Provide an exam-


ple.

5. Explain how MATLAB/Python represents polynomials using vectors. Provide an ex-


ample.

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.

2.1.1 Conversion of LTI Differential Equation to Transfer Function


Consider the following differential equation:
′′ ′
3y (t) + 5y (t) + 2y(t) = 4u(t) (2.1)
Where y(t) is the output and u(t) is the input. Applying the Laplace transform to both sides
of the differential equation. The Laplace transform of the derivatives is given by:
dn y(t) ′
L{ n
} = sn Y (s) − s(n−1) y(0) − s(n−2) y (0) − · · · − y (n−1) (0) (2.2)
dt
Where Y (s) is the Laplace transform of y(t), s is the complex frequency variable, and y(0),

y (0), . . . are initial conditions. Assuming the initial conditions are zero, meaning the LTI
system is initially at rest, we apply the Laplace transform to each term:
3s2 Y (s) + 5sY (s) + 2Y (s) = 4U (s) (2.3)
Y (s)
Rearranging the above equation to obtain U (s)
, the transfer function:
(3s2 + 5s + 2)Y (s) = 4U (s)
Y (s) 4 (2.4)
G(s) = = 2
U (s) 3s + 5s + 2

2.1.2 Conversion of LTI Differential Equation to State Space


Considering the same differential equation from above in Equation (2.1). In the first step,
we introduce the state variables that capture the essential dynamic variables of the system.
The number of state variables required is equal to the order of the differential equation or
the highest-order derivative. Hence, the state variables assumed for the above differential
equation are:

x1 (t) = y(t), ẋ1 (t) = y (t) ⇒ ẋ1 (t) = x2 (t)

′ ′′ −2y(t) − 5y (t) + 4u(t)
x2 (t) = y (t), ẋ2 (t) = y (t) ⇒ ẋ2 (t) = (2.5)
3
−2x1 (t) − 5x2 (t) + 4u(t)
ẋ2 (t) =
3

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.

Figure 2.1: MATLAB Desktop Main Menu and SIMULINK Icon


A SIMULINK Library Browser, in Figure (2.2) appears which displays a tree-structured view
of the SIMULINK block libraries. It contains several nodes; each of these nodes represents
a library of subsystem blocks that is used to construct simulation block diagrams. You can
expand/collapse the tree by clicking on the +/− boxes beside each node and block in the
block set pan.

Figure 2.2: SIMULINK Library Browser


Expand the node labeled SIMULINK. Sub-nodes of this node (Commonly Used Blocks,
Continuous, Discontinuities, Discrete, Logic and Bit Operations, etc.) are displayed. Now,

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).

Figure 2.3: SIMULINK Library Blocks

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.

Figure 2.4: Untitled Workspace

Let us take a simple example. The block diagram of a DC motor (armature-controlled)


system is shown in Figure (2.5).

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.

• J is the inertia seen by the motor = 30 ∗ 10( − 4) kg.m2 .


• B is the mechanical damping coefficient = 5 ∗ 10−3 N m/(rad/sec).
• Ea is the applied voltage = 5 V olts.
We will implement the model shown in Figure (2.5) in the untitled workspace in Figure
(2.4). Let us first identify the SIMULINK blocks required to implement the block diagram
of Figure (2.5). This is given in Figure (2.6).

Figure 2.6: SIMULINK Blocks Required for Implementation

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

Figure 2.8: Unconnected Blocks in Workspace

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.

Figure 2.10: Finished Block Diagram

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.

1. Define the transfer function G(s) = s3(s+1)(s+3)


+3s2 +s−0.5
. Calculate and print out the poles and
zeros of G(s). Also, plot them on the pole-zero plot.

(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

Compute and print the eigenvalues of the matrix A.

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.

2.5.2 Lab Tasks

1. Find the transfer function YU (s)


(s)
and state space representation of a system having the
following differential equation and enter it in MATLAB/Python.

Page 19
mv̇(t) + bv(t) = u(t) (2.9)
Where

• m is the vehicle mass of 1000 kg.


• b is the damping coefficient 50 N.s/m.

2. Obtain the transfer function VU (s)


(s)
and state space representation of the system in Figure
(2.5) and implement it in MATLAB/Python.

3. Consider a dynamic system consisting of a single output y, and two inputs r and w:

Y (s) = G(s)R(s) + N (s)W (s)


Where,
2s
G(s) = (process) (2.10)
2
50s + 15s + 1
0.3s
N (s) = (disturbance)
15s + 1
Model the system in SIMULINK. Use step inputs for both r and w. Display the output
signal on the scope.

4. Find the transfer function Vθ(s)


(s)
and state space representation of a system having the
following differential equations and enter it on MATLAB/Python.

Page 20
J θ̈(t) + bθ̇(t) = Kt i(t)
d (2.11)
L i(t) + Ri(t) = V (t) − Kb θ̇(t)
dt
Where

• J is the moment of inertia of the rotor 3.2284 ∗ 10−6 Kg.m2 .


• b is the motor viscous friction constant 3.5077 ∗ 10−6 N.m.s.
• Kb is the electromotive force constant 0.0274 V /rad/s.
• Kt is the motor torque constant 0.0274 N.m/A.
• R is the electrical resistance 4 Ω.
• L is the electric inductance 2.75 ∗ 10−6 H.

2.5.3 Post-Lab Tasks


Work through the following problems on paper: determine the transfer function and the
state space representation for the specified LTI differential equations. You can verify your
answers using MATLAB, SIMULINK, or Python.

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.

3.1.1 Generic First-Order Transfer Function


K
G(s) = (3.1)
τs + 1
The above expression represents a generic form of the first-order transfer function, where
K is the system gain or DC gain, and τ is the time constant of the system. With the help
of these parameters, the step response of the system can be accurately predicted. The step
response of the transfer function is illustrated below.

Figure 3.1: First-Order Step Response

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.

3.1.2 Generic Second-Order Transfer Function


ωn2
G(s) = 2 (3.2)
s + 2ζωn s + ωn2
The above expression represents a generic form of the second-order transfer function, where
ζ is the damping ratio, and ωn is the undamped natural frequency of the system. With the

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.

Figure 3.2: Second-Order Step Response

Where:-

• td is the delay time,


• tr is the rise time,
• tp is the peak time,
• ts is the settling time, and
• Mp is the percentage maximum overshoot.

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

1. Obtain and plot the unit step response of G(s).

2. Obtain and plot the unit impulse response of G(s).

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.

3.4.2 Lab Tasks


1. Find the rise time, maximum overshoot, settling time, and steady-state value of a
system having the following differential equation using its unit step response on MAT-
LAB/Python.

mv̇(t) + bv(t) = u(t) (3.4)


Where

• m is the vehicle mass of 1000 kg.


• b is the damping coefficient 50 N.s/m.

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

4. Consider R = 1 KΩ and C = 1 nF . Find out the transfer function of the circuit


( VVout
in
) in Figure (3.3). Plot the unit step and ramp response of the system on MAT-
LAB/Python.

Figure 3.4: Series RL 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.

3.4.3 Post-Lab Tasks


Analyze the provided transfer functions according to Section (3.1) without using MATLAB
or Python. For each transfer function, determine its order, identify the type of step response,
and calculate the necessary parameters to describe the step response fully.
10
1. G(s) = s+2

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.1: 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.

4.1.2 Converting State Space Systems to Equivalent Hardware


Consider the following state space system example:
      
ẋ1 (t) 0 1 x1 (t) 0
= −1 −2 + 1 u(t)
ẋ2 (t) x2 (t)
  (4.1)
x 1 (t)
y(t) = (1 0)
x2 (t)
From the above three equations can be extracted: ẋ1 (t) = x2 (t), ẋ2 (t) = u(t) − x1 (t) − 2x2 (t),
and y(t) = x1 (t). These three equations will be used to form the block diagram of the state
space system. The block diagram is shown below.

Figure 4.3: Block Diagram of Equation (4.1)

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.

Figure 4.4: Equivalent Hardware Diagram of Equation (4.1)

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.

Figure 4.5: Example Block Diagram

1 G = control . tf (1 , np . array ([1 , 1]) , inputs = ’e ’ , outputs = ’ y1 ’ , name = ’P ’


)
2 H1 = control . tf (1 , np . array ([2 , 1]) , inputs = ’e ’ , outputs = ’ y2 ’ , name = ’
FF ’)
3 H2 = control . tf (1 , np . array ([3 , 1]) , inputs = ’ y1 ’ , outputs = ’ y3 ’ , name = ’
FB ’)
4 sum1 = control . summing_junction ( inputs =[ ’r ’ , ’ - y3 ’] , output = ’e ’)
5 sum2 = control . summing_junction ( inputs =[ ’ y1 ’ , ’ y2 ’] , output = ’c ’)
6 System = control . interconnect ([ G , H1 , H2 , sum1 , sum2 ] , inputs = ’r ’ ,
outputs = ’c ’)
7 control . connection_table ( System , show_names = True )

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

Figure 4.7: Task 2

Figure 4.8: Task 3

Page 35
Figure 4.9: Task 4

Figure 4.10: Task 5

Page 36
4.4.2 Lab Tasks
1. Consider the block diagram.

Figure 4.11: Block Diagram of Lab Task 1


5000 1
For a value of gain KA = 80, G1 (s) = s+1000 , and G2 (s) = s(s+20) obtain the output of
this system on SIMULINK/Python when the reference input R(s) is a unit step input
and the disturbance signal W (s) is a Gaussian noise input.

2. The block diagram in 1. can also be implemented on MATLAB/Python using the


following code. What is the difference between the SIMULINK model in 1. and the
MATLAB/Python code?
1 % Step response with respect to R ( s )
2 s = tf ( ’s ’) ;
3 KA = 80;
4 G1 = 5000/( s +1000) ;
5 G2 = 1/( s *( s +20) ) ;
6 M = feedback ( series ( KA * G1 , G2 ) ,1)
7 step ( M ) ;
8

1 % Step response with respect to W ( s )


2 s = tf ( ’s ’) ;
3 KA = 80;
4 G1 = 5000/( s +1000) ;
5 G2 = 1/( s *( s +20) ) ;
6 Mw = ( -1) * feedback ( G2 , KA * G1 )
7 step ( Mw ) ;
8

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.

Figure 4.12: Hardware Diagram of Lab Task 3

4.4.3 Post-Lab Tasks


Convert the following state space systems to their equivalent hardware diagrams using Section
(4.1) on paper without using MATLAB, SIMULINK, or Python.
1.       
ẋ1 (t) 0 1 x1 (t) 0
= −4 −2 + 1 u(t)
ẋ2 (t) x2 (t)
  (4.2)
x (t)
y(t) = (1 0) 1
x2 (t)

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.

5.1.2 Root Locus


Root locus analysis is a graphical method for examining how the roots of a system change
with variation of a certain system parameter, commonly a gain within a feedback system.
This is a technique used as a stability criterion in the field of classical control theory, which
can determine the stability of the system. The root locus plots the poles of the closed loop
transfer function in the s-plane as a function of a gain parameter.

Sketching Root Locus


Using a few basic rules, the root locus method can plot the overall shape of the path (locus)
traversed by the roots as the value of K varies. The plot of the root locus then gives an idea
of the stability and dynamics of this feedback system for different values of K. The rules are
the following:

1. Mark open-loop poles and zeros.


2. Mark the real axis portion to the left of an odd number of poles and zeros.
3. Find asymptotes. Let P be the number of poles and Z be the number of zeros:

P − Z = number of asymptotes (5.7)


The asymptotes intersect the real axis at α (which is called the centroid) and depart
at angle ϕ given by:

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

5.1.3 Root Locus Controller

Figure 5.1: Block Diagram of a Root Locus Controller

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.

5.4.2 Lab Tasks


1. Consider the system having the following transfer function.

1
P (s) = (5.11)
s(s + 7)(s + 11)

Plot the root locus of the plant above on MATLAB/Python.

2. Consider the system having the following transfer function.

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.

5.4.3 Post-Lab Tasks


Answer the following questions using Section (5.1) on paper without using MATLAB, SIMULINK,
or Python.

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.

6.1.2 Stability Analysis Using Gain and Phase Margins


System stability can be analyzed using gain and phase margins. A higher gain margin indi-
cates a more stable system, as it suggests a greater tolerance for variations in system gain.
Similarly, a larger phase margin indicates a more stable system, as it reflects a greater al-
lowance for phase shift. Gain and phase margins can be calculated using gain and phase
crossover frequencies derived from the system’s Bode plot. These crossover frequencies rep-
resent the points at which the gain and phase plots intersect, providing valuable insight into
the stability characteristics of the system.
Phase Crossover Frequency (ωpc ): The frequency at which the Bode Phase plot intersects
the phase angle of -180◦ is known as the phase crossover frequency.
Gain Crossover Frequency (ωgc ): The gain crossover frequency is the frequency at which
the Bode Magnitude plot intersects the 0 dB magnitude.
Gain Margin: The gain margin is calculated by determining the magnitude of the phase
crossover frequency.
GM (dB) = 0 − Mpc (6.1)
Phase Margin: The phase margin is calculated by determining the phase shift of the
magnitude crossover frequency.

P M = Pgc − 180◦ (6.2)

6.1.3 Nyquist Plots


A Nyquist plot is a graphical representation of a system’s frequency response, commonly
used in the fields of automatic control and signal processing. It allows engineers to assess
the stability and performance of a system with feedback. When creating a Nyquist plot,
the frequency is varied as a parameter, resulting in a plot for each frequency. These plots
are depicted using polar coordinates, where the gain of the system’s transfer function is
represented by the radial coordinate, and the phase of the transfer function is indicated
by the corresponding angular coordinate. Nyquist plots provide valuable insights into the

Page 47
behavior of feedback systems across different frequencies, making them an essential tool for
engineers working on control system design and analysis.

6.1.4 Stability Analysis Using Nyquist Stability Criterion


When assessing the stability of a closed-loop control system, one of the methods involves
examining the frequency response of the open-loop transfer function. This criterion is based
on the Nyquist plot, which is a graphical representation of the open-loop transfer function
G(s)H(s) (where G(s) is the plant and H(s) is the feedback transfer function) in the complex
plane as the frequency ω varies from 0 to ∞. The procedure involves plotting the Nyquist
diagram by representing the open-loop transfer function G(jω)H(jω) on the complex plane
as ω ranges from 0 to ∞, and including the point at ω = ∞. Additionally, the Nyquist plot
is used to encircle the point −1 + j0 and count the number of encirclements of the critical
point, −1, in the complex plane, which ultimately helps in determining the stability of the
closed-loop system.
N is the number of encirclements of −1 in the clockwise direction by the Nyquist plot. P is
the number of poles of the open-loop transfer function G(s)H(s) in the right half s-plane. Z
is the number of closed-loop poles in the right half s-plane. Calculated by:
Z =N −P (6.3)
If Z is equal to zero then the closed-loop system is stable, otherwise, the system is unstable
with |Z| indicating the number of unstable closed-loop poles.

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

6.4.2 Lab Tasks


1. Consider the system having the following transfer function.

9(s2 + 0.2s + 1)
P (s) = (6.9)
s(s2 + 1.2s + 9)

Plot a Bode diagram for this transfer function on MATLAB/Python.

2. Consider the system having the following transfer function.

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.

3. Consider the system having the following state-space system.


   
0 1 0
ẋ(t) = −25 −4 x(t) + 25 u(t) (6.11)
y(t) = (1 0) x(t)

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.

6.4.3 Post-Lab Tasks


Answer the following questions on paper without using MATLAB, SIMULINK, or Python.
Provide the state space representation and transfer function for the hardware diagrams below.

Figure 6.1: Task 1

Figure 6.2: Task 2

Page 52
Figure 6.3: Task 3

Figure 6.4: Task 4

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)

7.1.2 Integral Control Action


Integral control action in a PID controller addresses the accumulated past errors by integrat-
ing the error over time. This action aims to eliminate the steady-state error or offset that
proportional control alone cannot correct. The integral component sums the error values
over time, and the control output is adjusted based on this accumulated sum. By doing so,
the integral action ensures that even small, persistent errors are gradually corrected, push-
ing the system toward the setpoint more precisely. However, this approach can introduce
some lag and overshoot, as the system may become too responsive to accumulated errors,
potentially causing instability if not properly tuned. Integrating the error helps achieve zero
steady-state error and ensures long-term accuracy in the control system. The time domain
equation and transfer function are provided below for reference.
Z t
u(t) = KI e(τ ) dτ
0 (7.2)
KI
U (s) = E(s)
s

7.1.3 Derivative Control Action


Derivative control action in a PID controller is designed to improve the system’s stability and
response time by predicting future errors based on the rate of change of the current error. It
works by computing the derivative of the error signal with respect to time, which provides
insight into how quickly the error is changing. The control output is then adjusted based
on this rate of change, which helps to dampen oscillations and reduce overshoot by coun-
teracting rapid changes in the error. Essentially, the derivative action acts as a ”predictive”
component that anticipates future error trends and adjusts the control output accordingly,
thus enhancing the system’s stability and ensuring smoother control dynamics. However,
it is sensitive to noise in the error signal, which can lead to erratic control behavior if not

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)

Figure 7.1: Block Diagram of a PID Controlled System

7.1.4 Types of PID Controller


There are only 4 types of PID controllers:

1. P-only Controller
2. PI Controller
3. PD Controller
4. PID Controller

7.1.5 Methods for Tuning PID Controllers


1. Manual Tuning Method: Manual tuning of PID controllers involves a hands-on
approach to adjust the proportional, integral, and derivative gains to achieve optimal
system performance. This method typically begins with setting the integral and deriva-
tive gains to zero, then incrementally adjusting the proportional gain KP to determine
the point where the system begins to oscillate or exhibit significant response. Once an
appropriate KP is established, the integral gain KI is introduced to eliminate steady-
state error, with adjustments made to balance responsiveness and stability. Finally,
the derivative gain KD is tuned to improve system damping and reduce overshoot.
Throughout the process, the controller’s performance is observed in response to test
inputs or disturbances, and gains are iteratively adjusted to refine the system’s sta-
bility, responsiveness, and accuracy. This trial-and-error approach requires careful
observation and patience to achieve the desired control characteristics, as it relies on
the operator’s experience and understanding of the system dynamics. The table below
lists the effects of increasing an individual parameter of a PID controller.

Parameter Rise Time Maximum Overshoot Settling Time Steady-State Error


KP Decrease Increase S.C. Decrease
KI Decrease Increase Increase Eliminate
KD S.C. Decrease Decrease S.C.

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?

(a) Manual Tuning


(b) Ziegler-Nichols Method
(c) Cohen-Coon Method
(d) Bode Plot Method

3. What effect does increasing the derivative gain have on the PID controller’s perfor-
mance?

(a) It increases the system’s steady-state error


(b) It enhances the system’s responsiveness and reduces overshoot
(c) It decreases the system’s stability
(d) It makes the controller less responsive

Page 56
4. Which component of a PID controller is responsible for eliminating steady-state error?

(a) Integral
(b) Proportional
(c) Derivative
(d) Feedback

5. What does the integral action in a PID controller specifically address?

(a) Immediate response to error


(b) Accumulation of past errors
(c) Future error prediction
(d) System noise

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

7. What does the ‘P’ in the PID controller stand for?

(a) Proportional
(b) Predictive
(c) Proactive
(d) Phase

8. In the PID controller, what is the primary role of the derivative term?

(a) To react to the error


(b) To eliminate steady-state error
(c) To predict future error based on its rate of change
(d) To adjust for disturbances

9. What does the ‘I’ in PID controller stand for?

(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.

3. Consider a plant having the following first-order transfer function:

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.

7.3.3 Post-Lab Tasks


1. Design and implement a suitable P-only controller for a series RC circuit in which the
output is the voltage across the capacitor. Use R = 1 KΩ and C = 1 mF . Simulate
the circuit using either Proteus or Multisim and provide the circuit diagram with values.

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.

8.1.2 Lead Compensator using Frequency Response


When designing a lead compensator, our goal is to increase system stability and transient
response by boosting the phase margin. The compensator includes a zero and a pole, with
the zero at a higher frequency than the pole.
To design the compensator, start by plotting the open-loop frequency response using a Bode
plot, which includes magnitude and phase plots. The aim is to shift the phase plot upward at
the crossover frequency to enhance stability by increasing the phase margin. To achieve this,
place the zero of the lead compensator to introduce an additional phase lead. The formula
calculates this phase lead:
ω ω
Phase Lead = tan−1 ( ) − tan−1 ( ) (8.2)
ωz ωp

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:

Figure 8.1: Bode Plot of a Phase-Lead Compensator

8.1.3 Lag Compensator using Root Locus


Designing a lag compensator using the root locus involves modifying the root locus plot of
a control system to improve its transient response and stability. To start, recall that the
root locus method is used to analyze how the roots of the characteristic equation change
with varying values of a gain parameter K. A lag compensator is typically used to increase
the system’s stability margin while improving steady-state accuracy, without significantly
altering the transient response. The compensator can be expressed as
s − z0
C(s) = (8.3)
s − p0
To design this compensator, you first need to select appropriate values for z0 and p0 that place
the closed-loop poles in desired locations on the root locus plot. To design the compensator,
follow these steps:

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.

8.1.4 Lag Compensator using Frequency Response


When designing a lag compensator, our primary objective is to improve the steady-state
accuracy of the system while minimally affecting its transient response and stability. Unlike
a lead compensator, which adds phase lead to improve stability, a lag compensator enhances

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:

Figure 8.2: Bode Plot of a Phase-Lag Compensator

8.1.5 Lead-Lag Compensator


A lead-lag compensator is a type of compensator that combines the effects of both lead
and lag compensators to improve a system’s performance across multiple aspects. The lead
part of the compensator enhances the system’s stability and transient response by increasing
the phase margin, while the lag part improves steady-state accuracy by increasing the low-
frequency gain. The overall compensator is represented as
s − z0 s − z1
C(s) = K (8.5)
s − p0 s − p1
where z0 and p0 correspond to the lead compensator and z1 and p1 to the lag compensator.
By carefully selecting the locations of zeros and poles, the lead-lag compensator provides
a balanced improvement in transient response and steady-state performance, making it a
versatile tool for achieving desired system characteristics.

8.2 Worked Example


Designing a root locus controller with a lead-lag compensator for a plant that has the fol-
lowing transfer function:

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.

Figure 8.3: S-Plane for the Worked Example

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.

System Type Step Input Ramp Input Parabolic Input


1
0 1+kp
, kp = lims→0 G(s) ∞ ∞
1
1 0 kv
, kv = lims→0 sG(s) ∞
1
2 0 0 ka
, ka = lims→0 s2 G(s)

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?

(a) Lead Compensator


(b) Lag Compensator
(c) PD Controller
(d) Lead-Lag Compensator

2. The primary function of a lag compensator is to:

(a) Improve the transient response


(b) Reduce steady-state error

Page 65
(c) Increase system oscillations
(d) Stabilize an unstable system

3. In a lead compensator, the compensating zero is typically placed:

(a) Farther from the origin than the pole


(b) Closer to the origin than the pole
(c) On the imaginary axis
(d) Farther to the right of the pole

4. Which of the following is a key characteristic of a lead compensator?

(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:

(a) To the right of the system’s dominant poles


(b) To the left of the system’s dominant poles
(c) On the imaginary axis
(d) On the right-half plane

6. What is the primary purpose of a lead compensator in control design?

(a) Increase the system’s DC gain


(b) Improve transient response
(c) Reduce steady-state error
(d) Decrease the natural frequency

7. In a lag compensator design, the compensator pole is placed:

(a) Closer to the origin than the zero


(b) Farther from the origin than the zero
(c) On the imaginary axis
(d) To the right of the imaginary axis

8. Which of the following compensators is typically used to improve both the transient
response and the steady-state error of a system?

(a) Lead compensator


(b) Lag compensator
(c) P-only controller
(d) Lead-lag compensator

9. The effect of adding a lead compensator on the root locus is to:

(a) Pull the root locus towards the left half-plane

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

10. Which of the following is true about a lead-lag compensator?

(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

8.3.2 Lab Task


54
1. Design a lead compensator for a plant with the transfer function G(s) = s(s+6) to
achieve a 2% settling time for the step response of 1 second and a damping ratio of
0.707. After that, find the steady-state error for the plant with the lead compensator
for a unit ramp input. Finally, add a lag compensator to the earlier design to reduce
the steady-state error by 5 times.

8.3.3 Post-Lab Tasks


1
1. Design a lead compensator for a plant with the transfer function G(s) = s(s+2)
to
achieve a ωn of 5 second and a damping ratio of 0.7.

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.

Figure 9.1: Block Diagram of a Temperature Control System Controlled by an On-Off


Controller
The on-off controller functions based on the error signal. The error at any given moment
can be calculated using the formula e(t) = r(t) − y(t), where r(t) is the reference value at
that instant and y(t) is the output value at that instant. The response observed on the
oscilloscope is shown below in Figure (9.2).
Theoretically, we assume there is no lag in the control equipment, meaning there is no time
delay for the on-off operation of the control system. With this assumption, if we plot a
series of operations from an ideal on-off control system, we will obtain the graph shown
in the bottom right corner in Figure (9.2). However, in practical on-off control systems,
there is always a time delay associated with the closing and opening actions of the controller
elements. This time delay is referred to as dead time. As a result of this delay, the actual
response curve differs from the ideal response curve. The ideal response curve is illustrated
in the top right corner of the figure, while the actual response curve is shown on the left side.
An operational amplifier can be used as a comparator to compare the process value with the
reference value in hardware. When an op-amp operates in open-loop mode, its gain is ideally

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.

Figure 9.3: Op-Amp as a Comparator

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.

Figure 9.4: Circuit Diagram of a Temperature Control System Controlled by an On-Off


Controller

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?

(a) A proportional term added to reduce overshoot


(b) A delay introduced in the feedback loop
(c) A band around the setpoint to prevent frequent switching
(d) An integral action to minimize steady-state error

2. Which of the following can reduce chattering in an On-Off controller?

(a) Increasing the gain


(b) Adding hysteresis
(c) Increasing the sampling rate
(d) Using derivative control

3. An On-Off controller is most suitable for:

(a) Precise temperature control applications


(b) Situations where small overshoots are critical
(c) Simple systems with slow dynamics
(d) High-speed control systems

4. The output of an On-Off controller is:

(a) A continuous variable between 0 and 1


(b) A discrete value (e.g., fully ON or OFF)
(c) Dependent on the derivative of the error signal
(d) Always proportional to the error

5. What is the term for the undesired rapid switching in On-Off controllers?

(a) Overshoot
(b) Hysteresis
(c) Cycling
(d) Chattering

6. In an On-Off controller, the control action depends on:

(a) The rate of change of the error signal


(b) The integration of the error signal
(c) Whether the error signal is above or below a threshold
(d) The magnitude of the error signal

7. What is a common example of an On-Off controller in everyday life?

(a) An air conditioning system with a variable-speed compressor

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

9.2.2 Lab Task


1. Consider a plant having the following transfer function.

1
G(s) = (9.1)
(s + 7)(s + 11)
Design an on-off controller on SIMULINK to achieve a constant output level of 5.

2. Design and implement an on-off controlled temperature system on Proteus or Multisim.


Achieve a constant temperature of 0◦ C in your system.

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.2.3 Post-Lab Task


1. Design and implement an on-off controlled temperature system on hardware using
Figure (9.4). Achieve a constant temperature of 30◦ C in your system.

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.

11.1.1 Spring-Mass Damper Model


The spring-mass damper model is one of the basic models in any mechanical system. Sim-
scape offers support to model a physical spring mass damper model and then simulate it to
different responses.

Figure 11.1: Block Diagram of a Spring-Mass Damper System

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:

1. Simscape → Foundation Library → Mechanical → Mechanical Sources → Ideal Force


Source to input force ‘F’.
2. Simscape → Foundation Library → Mechanical → Translational Elements → Mass for
mass ‘m’.
3. Simscape → Foundation Library → Mechanical → Translational Elements → Transla-
tional Damper for damper ‘b’.

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.

Figure 11.2: Connecting Blocks in SIMULINK for a Spring-Mass Damper System

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

Figure 11.4: Model Linearizer App GUI

11.1.2 Electrical Circuit Model


Like mechanical systems electrical circuits can also be modeled on Simscape and then their
mathematical model be obtained. In the figure below an integrating amplifier is implemented
on Simscape.
1
The transfer function of the figure in Figure (11.5) is G(s) = − sRC .

11.1.3 DC Motor Model


We can also model a combination of mechanical and electrical system on Simscape and then
their mathematical model be obtained. In Figure (11.6) below a DC motor speed system is
implemented on Simscape.
Note that the motor produces a rotational motion, and so we will use mechanical rotational
elements.

Page 78
Figure 11.5: Electronic Circuit Block Diagram in SIMULINK

Figure 11.6: DC Motor Model 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.

Figure 12.1: Control System Designer App GUI

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:

• Zero steady state error with respect to a step input.


• 80% rise time less than 1s.
• Settling time less than 2s.
• Maximum overshoot less than 20%.
• Open loop crossover frequency less than 5 rad/s.

First store the transfer function in G in MATLAB and open the edit architecture option to
load that transfer function to the app.

Figure 12.2: Edit Architecture Window

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

Figure 12.4: New Design Requirement Window in Bode Plot

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:

• Maximum overshoot less than 40%.


• 80% rise time less than 1s.
• Settling time less than 2s.
• Gain margin of 20 dB, phase margin of 30◦ .

Page 82
• Bandwidth greater than 5 rad/s.

12.3 Conclusion

Page 83

You might also like