0% found this document useful (0 votes)
112 views62 pages

Practical Work Book LCS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views62 pages

Practical Work Book LCS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 62

Linear Control System EE-304 Department of Electrical Engineering,

NHU NAZEER
HUSSAIN UNIVERSITY
DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

B.E Electrical Engineering Program


LAB MANUAL
For Academic Session Fall 2020
EE-304 LINEAR CONTROL SYSTEM

Name:

Roll Number:

Semester:

Batch:

Lab Instructor: Engr. Muhammad Zuhaib

1|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Course Learning Outcomes:


S.
Taxonomy
No CLO Statement Domain PLO
Level
.

Discuss various commands of MATLAB and


1. analyze the system response of different Psychomotor 2 1
inputs and systems.

Design and implement methods for


stability and to participate willingly in lab
2. discussion and respond timely to lab tasks, Psychomotor 6 3, 9
reports. Assume proper responsibility as
team member.

Design different mathematical models and


3 Psychomotor 4, 6 3
analyze the behavior of output response.

2|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Table of Contents

Synchronization with
Lab the Course
Experiment
No.
Chapter_1
1 Introduction to MATLAB
Chapter_1,2
2 Introduction to Control System Commands

3 Exploring the System Response by different inputs in Chapter_3


MATLAB Simulink.
Chapter_4
4 Verifying the Response of Closed Loop Systems.
Chapter_4,5
5 Verifying the Response of Open Loop Systems.
Implementation of the Root Locus using MATLAB with Chapter_6,7,8
6
different gain values and pole values.
Study of the Time Response of the Second Order Chapter_5,6
7
System
Chapter_7
8 Introduction to Proportional Controller
Chapter_7
9 Introduction to Proportional Integral Control.
Introduction to Proportional Derivative Control. Chapter_7
10
Chapter_7,8
11 Introduction to PID Controller
Exploring the Mathematical Modelling of Chapter_3,5,6
12 Electrical Systems.

Chapter_5,6,7
13 Exploring the DC Motor Characteristics
Verifying the Block Diagram Reduction Technique Chapter_4,5
14
Chapter_5,6,7
15 Open Ended Lab

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS
3|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

LAB SESSION 01

Introduction to MATLAB
OBJECTIVE:
To gain familiarity with MATLAB basics, learn to use help files for different
operations such as differentiation, integration, solution of simultaneous
equations, graphics, Laplace, and inverse Laplace etc.

Software:
MATLAB 7.7 Release 14

Theory:
MATLAB is a "Matrix Laboratory" program which operates as an interactive
programming environment. It is extensively used in all areas of applied
mathematics in various fields.

Toolboxes:
Toolboxes are comprehensive collection of MATLAB functions available for
control systems, neural networks, fuzzy logics, wavelets, simulation, etc.
The Basics:
Calculator functions work as you'd expect:
>>(1+4)*3
+ and - are addition, / is division, * is multiplication, ^ is an exponent. Assign
variables from the MATLAB workspace. Everything in MATLAB is a matrix.
(If it's a scalar, it's actually a 1x1 matrix, and if it's a vector, it's a Nx1 or 1xN
matrix.)
>>a = 3
To create a vector is pretty similar. Each element is separated by spaces, the
whole vectore is in square brackets:
>>v = [1 3 6 8 9]
To create a vector of values going in even steps from one value to another
value,
>>b = 1:.5:10
This goes from 1 to 10 in increments of .5, any increment, positive or negative
can be used. To turn a row vector into a column vector, just put a ' 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 c = [1 3 6; 2 7 9; 4 3 1]. The semicolons indicate the
end of a row. All rows have to 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.

4|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

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 third 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
27
43
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: c (:, 2) literally
telling MATLAB to use all the rows in the second column, i.e., the 2nd column.
You can get a whole row of a matrix with c (1, :), This literally 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. When you have a matrix or vector (anything with more than one
element) you need to do a few things to make sure all of your math does what
you want it to. You can add a constant or multiply by a constant normally
(const+c, const*c, etc.) If you have data in two matrices that correspond (for
example, a time vector and an x position vector that has x values for each point
in time), you can add and subtract those normally (it will map each element
properly.)
Useful Functions:
MATLAB has a lot of built-in functions. To use a function, just type function
name(arguments) with the appropriate name and arguments. If you create a time
vector t=1:0.25:6; you can get standard functions like, 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 s = sum(c) which sums all the columns in a matrix c and returns a
row vector of the sums. The function d = det(c) takes a matrix c and returns the
determinant of it. The MATLAB booklet has a list of many of these useful
functions.

.*
./
.^
so that MATLAB will multiply each element in the matrix instead of trying to
do matrix multiplication or division. Of course, it can also treat matrices as
actual matrices, so you can solve something like [A]x =b where A is a matrix of
coefficients, x is a column vector of the x values you want to find, and b is also
a column vector just by doing x = A\b after you define A and b. The \
represents "left division" (since to solve that equation you would have to divide
both sides by A on the *left* side, since order is significant when dealing with
matrices.). Help and other tools.
Places to get help:

5|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

 Typing "help" at the MATLAB prompt gives you a list of all the possible
directories MATLAB can find commands in (which also tells you its
"search path", or a list of the directories it is looking in for commands.).
 Typing "help directoryname" gives you a list of the commands in that
directory and a short description of them.
 Typing "help commandname" gives you help on a specific command.
 Typing "lookfor keyword" gives you a list of commands that use that
keyword. i.e.,"lookfor integral" lists commands that deal with integrals.
It's pretty slow, choose the word wisely. You can use control-c to stop
searching when you think you've found what you need.
 Typing "doc" starts up a web browser with the MATLAB on Athena
home page. This includes the entire reference manual for MATLAB, a
whole lot of other information on using MATLAB, and a pointer to the
MATLAB Primer, a good introduction to using MATLAB.
 You can get copies of "MATLAB on Athena" at Graphic Arts. You can
also get copies of the MATLAB Primer mentioned above. (There's a
small fee for copying costs on both.)
 The MATLAB manual and manuals for many of the toolboxes are
available in some clusters and can be borrowed from the consultants'
office in 11-115.
Some Useful Tools:
 If you accidentally reassign a function name to a variable (i.e., you try
saying sum = 3 and then you get errors when you try to use the sum
function because it doesn't know it's a function anymore), you can restore
it to its normal state using "clear function name". You can also use clear
to get rid of all variable values with "clear all".
 Who: will tell you all the variables you have currently defined.
 Whos: will tell you the variables, their sizes, and some other info.
 pi: is a function of that returns the value of pi. eps: is a function that
returns MATLAB’s smallest floating-point number.
 eps: is a function that returns MATLAB’s smallest floating-point number.
 format long/ format short: switch between the long and short display
format of numbers. Either way MATLAB uses the same number of digits
for its calculations, but normally (format short) it will only display the
first four digits after the decimal point.
 Typing: Type function name for any function in MATLAB’s search path
lets you see how that function is written.
Plotting:
The basic syntax to get a plot in MATLAB is:
>>plot (x1, y1).
(The x values always come before the y values, x1 and y1 represent variables
that your data is stored in.) If you type a second plot command later, it will clear
6|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

your first plot. If you type "hold on" it will hold the current plot so you can add
plots on top of one another (until you reset, it by typing "hold off").
You can plot multiple values with plot (x1, y1, x2, y2) and you can specify the
color and line type of a plot 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.
>>subplot (r, c, n)
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:
title ('This is a Title')
xlabel ('My X axis')
ylabel ('My Y axis')
legend ('First Thing Plotted’, ‘Second Thing Plotted')
legend creates a legend box (movable with the mouse) that automatically uses
the right symbols and colors and sticks the descriptions in the legend command
after them.

Polynomials and Fitting:


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.
>>p = [1 2 2 4 1] can represent the polynomial x^4 + 2x^3 + 2x^2 + 4x + 1.
There are a number of functions that use this representation of polynomials:
>>roots(p)
gives you the roots of the polynomial represented by the vector p.
>>polyval (p,4)
gives you the value of the polynomial p when x = 4. Similarly,
>>polyval (p, [1:10])
gives you the value of the polynomial evaluated at each of the points in the
vector. (It returns another vector the same size.)

MATLAB Symbolic Mathematics:


The following topics are covered:

 Differentiation
 Indefinite integrals

7|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

 Definite integrals
 Conversion to numeric (“double”) variables for subsequent numeric
calculations
 Substitution
 Plotting of equations and functions
 Solution of equations: graphical approximations, single equations,
multiple
 simultaneous equations, non-linear equations.
 Limits
 Taylor series
 Variable precision arithmetic
Differentiation: The MATLAB symbolic toolbox is very useful for checking
calculus problems. For the syntax for symbolic differentiation, see >> help
df
sym/diff. For example, to find diff_f = dx , where f =e−ax x 3 b sin cx and a, b and c
are unspecified constants, we do the following:

>> clear, syms a b c x; f=exp(-a*x) *x^(3*b) *sin(c*x), diff_f = diff (f, x)

Notice that the result is quite complex. To ask MATLAB to try to simplify it,
type:

>> diff_f_simp = simple(diff_f)

(see >> help sym/simple). MATLAB uses several algorithms for algebraic
simplification and chooses as a final answer the shortest of the results.
d2 f
MATLAB can take higher order differentials. For example, to find diff2_f=
dx 2
>> diff2_f=diff (f, x, 2) using the already defined expression for f.

Indefinite integrals: For the syntax for symbolic integration, see >> help
sym/int. Thus, for example, to find the indefinite integral int_g = ʃgdx, where
g=e−ax sin cx , we do
>> clear, syms a c x; g=exp(-a*x) *sin(c*x), int_g = int (g, x)

Check this by taking >>diff_int = diff (int_g, x). This should give back g, but
it doesn’t look the same because MATLAB doesn’t always give things in the
simplest format. In this case, we again use the simple command >>
diff_int_simp = simple(diff_int).

8|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Note that MATLAB does not add the constant of integration (“C”) customarily
shown for indefinite integrals -- this you must do by adding C after the int
command.
Sometimes MATLAB is not able to integrate an expression symbolically. For
example, try to ʃfdx (where, as before, f =e−ax x 3 b sin cx and a, b and c are
unspecified constants).
>> clear, syms a b c x; f = exp(-a*x) *x^(3*b) *sin(c*x), int (f, x)

When MATLAB cannot find a solution, it gives a warning message and repeats
the command. When this happens, you’re out of luck.
Π

Definite integrals: For the definite integral, int_def_g = ∫ gdx do


−Π

>> clear, syms a c x; g = exp(-a*x) *sin(c*x), int_def_g = int (g, x, -pi, pi)

When MATLAB is unable to find an analytical (symbolic) integral, such as


with
>>int(exp(sin(x)), x,0,1), a numerical solution can nevertheless be found using
the “quad” command, e.g. >> quad('exp(sin)',0,1). It is best to follow the steps
below:

 Create the function to be integrated in the MATLAB editor and save it to


your Current Directory, which must also be in the path (File / Set Path).
For example, for
our exp(sin(x)) function:
function out = func1(x)
out = exp(sin(x));
end
 Use either one of the following formats: >> quad('func1',0,1) or >>
quad(@func1,0,1).
Conversion to a double precision numeric variable: Often MATLAB's
symbolic engine produces a symbolic answer, as in:
>> clear, syms x; h=exp(-x) *sin(x), int_def_h=int (h, x, -pi, pi)
Where Π is retained in symbolic form (pi). Irrational numbers may also result,
e.g. 4/3 rather than 1.3333. For use in subsequent numerical calculations, you
must convert symbolic results into numeric “double” variables by the “double”
command:

>> int_def_h_doub=double(int_def_h)
Substitution: Sometimes it is desired to substitute one value or parameter for
another in an expression. This can be done using the “subs” command (see >>

9|Page
Linear Control System EE-304 Department of Electrical Engineering,
NHU

help sym/subs). For example, imagine we want a=2 and c=4 in int_def_g.
This is done by:

>> clear, syms a c x; g = exp(-a*x) *sin(c*x), int_def_g = int (g, x, -pi, pi)
>> int_sub=subs (int_def_g, {a, c}, {2,4})

Do not try to assign the values to the variables before the integration or
differentiation is performed. (Try it in the above example and see what
happens.)

Graphing equations and functions: MATLAB’s symbolic engine has


commands for plotting symbolic equations and functions, appropriately starting
with “ez.” For two dimensional graphs, see
>>helpezplot. As an example, here we use the equation for a circle of radius 2,
x + y =4.
2 2

Step 1: Move everything to the left-hand side of the equation, i.e. x 2+ y 2=4
Step 2: Clear and define x and y as symbolic.
Step 3: Define a variable equal to the left-hand side of the equation, inside
single straight1 quotation marks.
Step 4: Use ezplot, as follows:

>> clear; syms x y; lhs = 'x^2+y^2 - 4’; ezplot (lhs, [-3, 3, -2.5, 2.5])

The [-3, 3, -2, 2] tells MATLAB that the x scale is to go from -3 to +3, and the y
scale is to go from -2.5 to +2.5. Note that we have assigned x 2+ y 2=4 to the
character variable “eq” (see the Workspace window or type >> whos). You can
edit the figure in the Figure window. First save it as “circle. Fig” using
File/Save As so you can retrieve it later from the Command window, without
having to recreate it. Here are some things you can do in the Figure window:

 Click on the arrow icon and then double-click on any portion of the
figure you’d like to edit. In this way you can change the color and
thickness of the curve, add points, change the axes, and edit the title.
 Edit / Copy Figure to place it on the Windows Clipboard. Then you can
paste it into a Word document, for example.
 While in the Figure window, press the Alt and Print Screen keys at the
same time, to place the entire figure window on the clipboard. This can
also be pasted into a Word document.

Experiment with other equations.

10 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Three-dimensional plots can be created using the ezmesh and ezsurf commands.
For these commands an explicit form must be used, i.e. z = f (x, y). It is the f
(x, y) that is entered into the command. The code below illustrates some
possibilities. The lines with % are comments and are not executed by
MATLAB.

% symplot3D.m
clear,
clc
syms x y
ex1='sqrt(4-x^2-y^2)';
figure (1); ezsurf (ex1, [-2, 2, -2, 2]);
ex2='x^2-y^2';
figure (2); ezsurf(ex2);
ex3='x^2+2';
figure (3); ezmesh(ex3);
ex4='x + y';
figure (4); ezmesh(ex4);
% Some 3d plots, where z = the expressions shown
% In the figure window, click on Tools, Rotate 3D.
% Then put cursor on figure, hold down left mouse,
% Move cursor to rotate figure, notice that this gives you a better feeling for its
3D
shape.
% Have some fun and create your own shapes.

Open the excellent MATLAB editor by >> edit, cut and paste the above code
into your editor, save it on your Current Directory as symplot3D.m, make
certain the Current Directory is in MATLAB’s path (File/Set Path), and then
execute it in the Command window by >>symplot3D. Select each figure in
turn, and in the Figure window Tools / Rotate 3D. Put the cursor anywhere on
the figure, hold down the left mouse button, and move the mouse to rotate the
figure.

Solution of Equations: The symbolic toolbox in MATLAB is capable of


solving many types of equations, including non-linear ones and several
simultaneous equations. See: >> help solve. The steps in solving one or more
equations using “solve” are:

Step 1: Define the variables in the equations as symbolic using the “syms”
command.
Step 2: Define the equations (see the examples below).
11 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Step 3: Solve the equations using the “solve” command.


Step 4: If there is more than one solution, decide which is physically reasonable
and select it.
Step 5: Check the solution by substituting it back into the original equation(s).
We now look at some examples.
Example 1: Find the two solutions to the classic quadratic equation,a x 2+ bx+ c =0.
>> clear, syms x y z a b c; eq = 'a*x^2+b*x+c = 0’, [x]=solve (eq, x)

(Note that single quotation marks must be placed around an equation that is
assigned to a variable, here eq.) As expected, we obtain two solutions. Suppose
we want only the first. This is extracted by >> x1 = x (1). This should be done
manually or using a logical operator (“if” command), because MATLAB's
symbolic engine doesn't always give multiple solutions in the same order. What
is x (1) now could be x (2) in a subsequent trial.

Example 2: Find the solution to e 2 x =3 y .

>> clear, syms x y; eq = 'exp(2*x) = 3*y', [x] = solve (eq, x)


(Is the log in this solution the natural log or the log base 10? See
http://people.clarkson.edu/~wilcox/ES100/formcomp.doc)

We use a similar procedure to solve simultaneous equations. First, let us look at


a set of linear equations, and then non-linear equations.

Example 3: Find the solution to the following set of linear equations:


2x-3y+4z = 5
y+4z+x = 10
-2z+3x+4y = 0

>> clear, syms x y z;


>> eq1 = '2*x-3*y+4*z = 5'
>> eq2 = 'y+4*z+x = 10'
>> eq3 = '-2*z+3*x+4*y = 0'
>> [x, y, z] = solve (eq1, eq2, eq3, x, y, z)

Notice that we did not have to enter x, y and z in any particular order in defining
the
equation variables (unlike the numerical MATLAB method using matrices
with \ or inv). However, the variables in the output are in alphabetical order,
regardless of how they are written in the command. So, take care to list the
variables in the brackets in alphabetical order. (For example, if you use [z, x, y]
rather than [x, y, z] in the above example the result produced for z is actually x,

12 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

that for x is actually y, and that for y is actually z.). Again, the results may be
symbolic and require conversion to numeric form for subsequent calculations:

>> x_d = double(x), y_d = double(y), z_d = double(z)

Example 4: We can also solve simultaneous non-linear equations, e.g.


x 2
2 e = y , y=3−x .

>> clear, syms x y; eq1='y=2*exp(x) ', eq2='y=3-x^2', [x, y] = solve (eq1,


eq2, x, y)
Note that this gives only one solution; there are two as we see below. Again, to
convert x and y from symbolic variables to numeric double variables, use the
“double” command. (Use “whos” or look in the Workspace window to follow
this transformation.) We can obtain an approximate solution by plotting these
two equations and looking at their intersections. As above, we first move
everything to the left-hand side of the equations.

>> clear, syms x y; eq1 = 'y - 2*exp(x)’; eq2 = 'y-3+x^2';


>> ezplot(eq1), hold on; ezplot(eq2); hold off

The "hold on" command tells MATLAB to write the following plots on top of
the first one, rather than replacing it. Approximate values of the solutions
(intersections) can be obtained in the Figure window by clicking on Tools /
Zoom In, clicking on a desired intersection to enlarge that area of the graph,
clicking on Tools / Data Cursor, and then clicking on that intersection again to
give the approximate values of x and y there. Compare these results with those
found above using the solve command.

Example 5: There are equations with an infinite number of solutions, for


example sin(x) =1/2.
It is helpful to see some of these solutions by plotting y = sin(x)-1/2 and seeing
approximately where it has values of zero:

>> clear, syms x; eq='y - sin(x) + 1/2’; ezplot (eq, [-6, 6, -2, 1])
>> hold on; eq0='0'; ezplot(eq0); hold off
The "hold on" command tells MATLAB to write the following plots on top of
the first one, rather than replacing it. Plotting 0 puts a horizontal line on the
graph. Intersections of the sine wave with this line represent solutions of the
first equation. Approximate values can be obtained in the Figure window by
clicking on Tools / Zoom In, clicking on a desired intersection to enlarge that
area of the graph, clicking on Tools / Data Cursor, and then clicking on that
intersection again to give the approximate values of x and y there. Try this on
13 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

the first two intersections to the right of the origin (x > 0). Write down your
results to compare with those found below using solve commands.
The symbolic solve command finds only one of these solutions and then stops:
>> clear, syms x; eq = 'sin(x)-1/2=0’; [x] = solve (eq, x); x_doub=double(x)
But suppose we want the solution that lies between x = 2 and x = 3. This must
be done numerically.

Limits: The symbolic toolbox also contains a command for finding limits of
expressions,e.g.
sin ⁡(ax)
lim
x →0 x
>> clear, syms x a; value = limit(sin(a*x)/x, x, 0)
There are cases where the limit depends on the direction from which it is
approached.
Consider the plot of tan(x) versus x generated by:
>> ezplot('tan(x)')
Suppose we want the value of tan(x) at x = /2. We could use MATLAB's
numeric engine as follows:
>> tan(pi/2)

Does this give a correct result? Recall that tan (𝜫 /2) can be either + or - ,
depending whether we approach from the left or the right. The numeric solution
is a very large number, which might by okay for some applications but not for
others. We can use the symbolic engine to find the two correct solutions, as
follows:

>> tanhalfpiright = limit(tan(x), x, pi/2, 'right')


>> tanhalfpileft = limit(tan(x), x, pi/2, 'left')

Taylor series: Taylor series are polynomial approximations for functions that
are valid near a particular point. Differentials of increasingly higher order are
used to generate this polynomial (e.g., see your calculus test). The syntax is
Taylor (expression, order, variable, point).

Example: Expand e x .
about x = 3 to order 5:

>> clear, syms x; Tay_expx = taylor(exp(x),5, x, 3)

This is exactly correct only at x = 3. Compare this approximation at x = 2 with


the exact value:
>> approx=subs (Tay_expx, x, 2), exact=exp (2), frac_err=abs(1-
approx/exact)
14 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

The approximation improves as one adds more terms to the polynomial (order)
or moves closer to the point about which the expansion was made. This can be
illustrated by:

>> ezplot (Tay_expx), hold on, ezplot(exp(x)), hold off.

Summations: MATLAB’s symbolic engine is also capable of doing symbolic


summations, even those with infinitely many terms! The “symsum” command
n

is used (see help symsum). Let us consider ∑ f (k), where f(k) is a function of
k=m

an integer k. The syntax to calculate this Using MATLAB is syms k, symsum


(f, k, m, n). If a factorial (!) is desired, since! is also a numeric command, we
must tell MATLAB to use the symbolic form by including the term involving in
the factorial, say (1+2*k)! in sym, i.e. sym('(1+2*k)!'). Infinite sums are
particularly,
x 2 k+1

k
Interesting e.g.: ∑ (−1)
(2 k + 2)! , the solution for which is found by:
k=0

>> clear, syms k x; symsum ((-1) ^k*x^(2*k+1)/sym('(2*k+1)!'), k, 0, Inf).

1 xk
∞ ∞
As an exercise find, ∑ and ∑ , the result may surprise you.
k =1 k2 k=0 k !

Using MATLAB for Laplace Transforms:


Example:
You can compute Laplace transform using the symbolic toolbox of MATLAB.
If you want to compute the Laplace transform of x (t) = t, you can use the
following MATLAB program.
>> f=t;
>> syms f t
>> f=t;
>> laplace(f)
ans =1/s^2
where f and t are the symbolic variables, f the function, t the time variable.

The inverse transform can also be computed using MATLAB. If you want to
compute the inverse Laplace transform of F (S)=24/(s*(s+8));

.>> syms F S
>> F=24/(s*(s+8));
>> ilaplace(F)
15 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

ans = 3-3*exp(-8*t)

We can also do inverse Laplace transform using partial fraction expansion, and
MATLAB can help you with that. If you want to find the partial-fraction
expansion of
4 s 2+ 4 s+ 4
Y(s) = 2 2
s (s + 3 s+ 2)

You write the coefficients of the numerator and the denominator in separate
vectors
and MATLAB gives you the coefficients with the corresponding poles in the
expansion.

>> n= [0 0 4 4 4];
>> d= [1 3 2 0 0];
>> [r, p, k] = residue (n, d)

RESULTS AND CONCLUSION:

NAZEER HUSSAIN UNIVERSITY


16 | P a g e
DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS
Linear Control System EE-304 Department of Electrical Engineering,
NHU

LAB SESSION 02

Introduction to Control System Commands

OBJECT: - Introduction to Control System Commands


Apparatus Required: A PC with MATLAB package.

Theory: -

Control System:
A control system is an interconnection of components forming a system
configuration that will provide a desired system response. Hence, a control
system is an arrangement of physical components connected or related in such a
manner as to command, regulate, direct, or govern itself or another system. A
control system provides an output or response for a given input or stimulus.

LTI model structures:

There are three basic forms to describe linear time invariant (LTI) systems in
MATLAB.
Transfer function form:

Zero-pole-gain form:

State space model form:

1)Transfer Function:
H=tf (num, den)
H=zpk ([], [-1, -2],2)

17 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

2)RESIDUE Partial-fraction expansion: -


[R, P, K] = RESIDUE (B, A)
finds the residues, poles and direct term of a partial fraction expansion of the
ratio of two polynomials B(s)/A(s). If there are no multiple roots,
B(s) R (1) R (2) R (n)
---- = -------- + -------- + ... + -------- + K(s)
A(s) s - P (1) s - P (2) s - P(n)
Vectors B and A specify the coefficients of the numerator and denominator
polynomials in descending powers of s. The residues are returned in the column
vector R, the pole locations in column vector P, and the direct terms in row
vector K.

3)TF2ZP Transfer function to zero-pole conversion: -


[Z, P, K] = TF2ZP (NUM, DEN)
finds the zeros, poles, and gains from a SIMO transfer function in polynomial
form:
NUM(s)
H(s) = --------
DEN(s)
Vector DEN specifies the coefficients of the denominator in descending powers
of s. The zero locations are returned in the columns of matrix Z, with as many
columns as there are rows in NUM. The pole locations are returned in column
vector P, and the gains for each numerator transfer function in vector K.

4)SERIES-Series interconnections of the two LTI models: -

SYS = SERIES (SYS1, SYS2, OUTPUTS1, INPUTS2) connects two LTI


models SYS1 and SYS2 in series such that the outputs of SYS1 specified by
OUTPUTS1 are connected to the inputs of SYS2 specified by INPUTS2.

5)PARALLEL-Parallel interconnections of two LTI models: -

18 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

[num, den] =parallel (num1, den1, num2, den2), this function gives parallel
connection of two LTI models. The arguments for the function are num1, num2
and den1, den2 that are the numerators and denominators of the two function
this function returns the num and den as the output.

6)FEEDBACK-Feedback connections of two LTI models: -

SYS = FEEDBACK (SYS1, SYS2) computes an LTI model SYS for the
closed-loop feedback system. To apply positive feedback, use the syntax.
SYS = FEEDBACK (SYS1, SYS2, +1).

7)TF2SS Transfer function to state-space conversion: -


[A, B, C, D] = TF2SS (NUM, DEN)
calculates the state-space representation:
x = Ax + Bu
y = Cx + Du
of the system:
NUM(s)
H(s) = --------
DEN(s)
from a single input. Vector DEN must contain the coefficients of the
denominator in descending powers of s. Matrix NUM must contain the
numerator coefficients. The A, B, C, D matrices are returned in controller
canonical form. This calculation also works for discrete systems

19 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Program # 01: -
disp('NHU ')
disp('Created by xyz ')
disp(' Reg# ‘)
num=[2 5 3 6]
den=[1 6 11 6]
[r,p,k]=residue(num,den)
[num,den]=residue(r,p,k)
printsys(num,den,'S')

OUTPUT:

Program # 02: -
m = 2;
b = 5;
k = 3;
num = [ 1 ];
den = [ m b k ];
tutorial_tf = tf(num, den)

OUTPUT: -

20 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Program # 03: -
num=[2 5 3 6]
den=[1 6 11 6]
[z,p,k]=tf2zp(num,den)
disp('Zeros of the function is = ')
disp(z)
disp('Poles of the function is = ')
disp(p)
disp('Gain of the function is = ')
disp(k)

OUTPUT: -

21 | P a g e
Linear Control System EE-304NAZEER
Department
HUSSAIN of Electrical Engineering,
UNIVERSITY
NHU
DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 03

Exploring the System Response by different inputs in MATLAB


Simulink.

OBJECT: -
Finding impulse and step response of the following system by using Simulink
and compare the results.

Apparatus Required: MATLAB is required to perform all the experiments for this lab.

Theory: -
G(s)=10/s^2+2s+20
Design two systems in Simulink, one for impulse response and one for step response.
Then use the given equation to obtain the result using scope. To find both the
responses in MATLAB, write the required code and finally compare both the results
(of Simulink and MATLAB).
Step Response Using Simulink:
Procedure:
1. Type “Simulink” in MATLAB command prompt.
2. “Simulink Library Browser” window will appear.
3. Create a new file by selecting “model” from the file option (file>>New>Model).
4. Drag the step function from the Simulink library browser to the new file created
followed by transfer function and scope. Scope is used to see the result (resulting
waveform).
5. Give values to the transfer function according to the question.

6. After saving followed by simulation, click on the scope in the figure to see
the resulting waveform(graph).
7. A window showing the step response will appear.

OUTPUT: -
22 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Impulse Response Using Simulink:


Now in order to find the impulse response repeat the same as explained above
but provide the output of the step function as input to the derivative as shown in
figure below:

OUTPUT: -

Analysis:

23 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Step Response Using MATLAB:


Procedure:
Create a new M-file (File->New->M-file)
Write the MATLAB code given below
num= [10];
deno= [1 2 20];
t=tf (num, deno)
step (t)
tf () is used to find the transfer function.
Save and then run the program. A window showing the step response will
appear, which will be similar the window obtained in Simulink.

Impulse Response Using MATLAB:


Procedure
Write the MATLAB code given below
num= [10];
deno= [1 2 20]; t=tf (num, deno);
step (t)
plot (diff(step(t)))
As the derivative of the step function is an impulse that’s why diff(step(t)) is used in
the above code. Results obtained will be similar to the one obtained in Simulink.

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

24 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

LAB SESSION 04

Verifying the Response of Closed Loop Systems.

OBJECT: - To digitally simulate the time response characteristics of Linear


SISO systems using state variable formulation.

Apparatus Required: A PC with MATLAB package.


Theory:
State Variable approach is a more general mathematical representation of a
system, which, along with the output, yields information about the state of the
system variables at some predetermined points along the flow of signals. It is a
direct time-domain approach, which provides a basis for modern control theory
and system optimization. SISO (single input single output) linear systems can
be easily defined with transfer function analysis. The transfer function approach
can be linked easily with the state variable approach.
The state model of a linear-time invariant system is given by the
following equations:
Ẋ (t) = A X(t) + B U(t) State equation
Y (t) = C X(t) + D U(t) Output equation
Where A = n x n system matrix, B = n x m input matrix, C= p x n output matrix
and D = p x m transmission matrix.

Programme:

Open Loop System Response:

1st – Order System 2nd Order System


T. F=4/(s+2) T. F= 4/s2+6s+16

n=[4]; n=[4];
d=[1 2]; d=[1 6 16];
sys=tf(n,d); sys=tf(n,d);
step(sys) step(sys)
impulse(sys) impulse(sys)

25 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

SECOND ORDER SYSTEM: Open Loop Response (First Order


System):
Response of system to Step and Impulse
input:
T. F= 4/s2+6s+16
T. F=4/(s+2)
SIMULINK Modelling:
Step Input Open Loop –II Order SIMULINK Modelling:
Step Input Open Loop –I Order:

Impulse Input Open Loop –II Order

Impulse Input Open Loop –I Order:

STATE SPACE EQUATION:


A=[-6 -16; 1 0];
B=[1; 0];
C=[ 0 4];
D=[0]; Sys=ss(A,B,C,D);
step(sys) impulse(sys)

RESULT:

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 05
26 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

SECOND ORDER SYSTEM:

T. F= 4/s2+6s+16
Verifying the Response of Open
Loop Systems.
SIMULINK Modelling
OBJECT: - To digitally simulate the Step Input Close Loop –I1 Order:
time response characteristics of Linear
Closed loop SISO systems using state
variable formulation.
Impulse Input Close Loop –II Order:
Apparatus Required: A PC with
MATLAB package.
Theory:
State Variable approach is a more
general mathematical representation of a
system, which, along with the output,
yields information about the state of the
system variables at some predetermined
points along the flow of signals. It is a
direct time-domain approach, which provides a basis for modern control theory
and system optimization. SISO (single input single output) linear systems can
be easily defined with transfer function analysis. The transfer function approach
can be linked easily with the state variable approach.

Programme:

Closed Loop System Response:

1st – Order System 2nd Order System


T. F=4/(s+2) T. F= 4/s2+6s+16
n=[4]; n=[4];
d=[1 2]; d=[1 6 16];
sys=tf(n,d); sys=tf(n,d);
sys=feedback(sys, 1, -1) sys=feedback(sys, 1, -1)
step(sys) step(sys)
impulse(sys) impulse(sys)

27 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Closed Loop Response:


Response of system to Step and Impulse RESULT:
input:
T. F=4/(s+2)

SIMULINK Modelling:
Step Input Close Loop –I Order:

Impulse Input Close Loop –I Order:

Analysis:

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-
FEPS

LAB SESSION 06

Implementation of the Root Locus using MATLAB with different


gain values and pole values.

OBJECT: - Implementation of Root Locus using MATLAB with different


gain values and pole values.
Apparatus Required: A PC with MATLAB package.

Theory: This lab is based on finding the root locus of system. Two basic
commands can be used to get the root locus. Sisotool(sys) and rootlocus(sys)
are used to find root locus but restriction for this lab is usage of rlocus(sys)
command only. The method adopted by W.R. Evans to find the roots of a
characteristic’s equation is called root-locus method. Function for drawing a
root locus in MATLAB is the rlocus () function. Rlocus () computes and plots
the root locus of the single-input, single-output LTI model sys. Rlocus (sys, k)
uses a user-specified vector K of gains.

28 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

K (s−2)
G ( s ) H ( s )=
( s+ 2)(s−2 j)(s+ 2 j)
Simplification of Transfer function:

=(s-2)/(s+2)(s+2j)(s-2j)
=(s-2)/(s+2)(s^2+2s+3)
=(s-2)/(s^3+2s^2+4s+8)
So num= [1 -2] & denum= [1 2 4 8]
Procedure:
Simplify the transfer function to generate num and denum.
Using MATLAB write the code 1, given below, to find the root locus.
After executing code1 a graph will appear showing root locus of a system.
MATLAB Code-2 is executed to give different values of gain (K) to the system
and this time rlocus (sys, k) command is used to plot root locus with different
value of gains.
Graph is plotted only for range of K given in code2 where range of K is from 0
to 10.
By changing the values of K, the value of poles of a system change.
In MATLAB code-2 for different values of K the value of poles is observed
and are shown in figures below.
Students are advised to get the results and verify the results by applying
mathematical ways of calculating transfer function.
MATLAB Code-1:
num=[1 -2]
denum=[1 2 4 8]
sys=tf(num, denum)
rlocus(sys)
title('Root locus of G(S)H(S)= K(s -2)/(s^3+ 2s^2+ 4s+ 8)').
Graph:

29 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Figure (a): Root locus of system for MATLAB code-1.


MATLAB Code-2:
num=[1 -2]
denum=[1 2 4 8]
sys=tf(num, denum) k=[0:1:10]
rlocus(sys, k)
title('Root Locus Plot of G(S)H(S)=K(S-2)/(S+2)(S+2j)(S- 2j), for "K= 0 to
10"’).
Graph:

Figure (b): Root locus of system for MATLAB Code-2.


Observing Different Values of K ranging from 0 to 10:

Value of poles for K=0

30 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Value of poles for K=1


The above procedure is done for all the values of K (0 to 10) and different value of
poles is found at different K.

Different Values of K Value of Poles at


different K

0 -2,6.11e-16+2i, 6.11e-16-2i
1 -1.43, -0.284+2.03i, -0.284-2.03i

2 -0.793, -0.603+2.16i, -0.603-


2.16i

3 -0.309, -0.846+2.4i, -0.846-


2.4i
4 8.88e-016, -1+2.65i, -1-
2.65i
5 0.211, -1.11+2.87i, -1.11-2.87i
6 0.368, -1.18+3.08i, -1.18-3.08i
7 0.491, -1.25+3.27i, -1.25-3.27i
8 0.591, -1.3+3.44i, -1.3-3.44i
9 0.675, -1.34+3.61i, -1.34+3.61i
10 0.747, -1.37+3.76i, -1.37- 3.76i

Analysis:

31 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Conclusion:

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-
FEPS

LAB SESSION 07

Study of the Time Response of the Second Order


System
OBJECT: - To obtain time response of a second order system in case of under
damped, over damped and critically damped systems.
Apparatus Required: PC loaded with MATLAB

Theory: The time response of control system consists of two parts. Transient
response and steady state response. C (t) = Ctr(t) + Css(t). Most of the control
systems use time as its independent variable. Analysis of response means to see
the variation of output with respect to time. The output of the system takes some
finite time to reach to its final value. Every system has a tendency to oppose the
oscillatory behavior of the system which is called damping. The damping is
measured by a factor called damping ratio of the system. If the damping is very
high, then there will not be any oscillations in the output. The output is purely
exponential. Such system is called an over damped system. If the damping is
less compared to over damped case, then the system is called a critically
damped system. If the damping is very less than the system is called under
damped system. With no damping system is undamped.

32 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

1<<∞ --- Over damped system.


=1 --- Critically
damped system.
0<<1 --- Under damped
system.
=0 --- Undamped system.

Time domain specifications: Delay


time Td = (1 + 0.7)/ wn
Rise Time Tr = (Π – θ)/ wd
Peak overshoot time = Tp = Π/ wd
% Mp = exp (- Π/sqrt (1-2))
Settling Time Ts = 4/wn (2% tolerance)
Procedure:
1, Open the MATLAB command window.
2, Click on file-new-M file to open the MATLAB editor window.
In the given MATLAB editor window enter the program to obtain the step
response.
% step response of a second order system
n = input (‘enter the natural frequency’); input (‘enter the damping
ratio’);
num = [n*n]; den = [1 2**n n*n]; sys = tf (num, den);
3, Save the file in work directory.
4, Run the program and enter the respective value for the natural frequency,
damping ration and time.
5, The graphs displayed are according to the above values.
6, The values of wd, td, theta, tr, ts, Mp can be obtained by:
a, Right click on the figure window and select grid to get grids on the curve.
b, Right click on the figure window and select characteristics and enable peak
response, settling time and rise settling.
c, Repeat the steps 5,6,7 for different values of .

Graph: -

33 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Tabular Columns: -

Time Domain Specifications From MATLAB By Calculation


Rise Time
Peak Time
Settling Time
Max. Overshoot

1b) Evaluation of the effect of additional poles and zeros on time


response of second order system.
MATLAB program to evaluate the effect of additional poles and zeros on
time response of second order system. This program uses the command zpk.
For the second order system the poles are -10+30i and -10-30i. The program
given below gives the time response of 2nd order system:
Z= [];
P= [-10+30i, -10-30i];
K=1000;
sys=zpk(z, p, k);
t= [0:0.001:1];
step(sys,1);
grid;
For the second order system, if we add a pole it changes to third order.
To study the effect of additional poles:
Location of poles Effect on time response
-1
-10
-100

To study the effect of additional zeros:


Location of zeros Effect on time response
-1
-10
-100

1c) Effect of loop gain of a negative feedback system on stability: The


following program is used to study the effect of loop gain of a negative
feedback system on stability. The value of gain k is varied, and different step
responses are obtained.
clc;
Z= [];
P= [-0.5+i, -0.5-i, -1];
k1=1;
k2=2;
k3=3;
sys1=zpk(z, p, k1)
34 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

sys2=zpk(z, p, k2)
sys3=zpk(z, p, k3)
t= [0:0.01:20];
[y1, t] =step(sys1, t)
[y2, t] = step(sys2, t)
[y3, t] = step(sys3, t)
plot (t, y1, t, y2, t, y3)
legend (‘k=1’, ‘k=2’, ‘k=3’)
grid;

Result:

Questions:
1-What is meant by time response of a system?
2-What do you mean by damping factor?

35 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 08

Introduction to Proportional Controller

OBJECT: - Investigate the characteristics of the proportional (P) Controller.


Apparatus Required: PC loaded with MATLAB.
Theory:
Introduction: Consider the following unity feedback system:

Plant: A system to be controlled.


Controller: Provides excitation for the plant; Designed to control the overall
system behavior. The three-term controller: The transfer function of the PID
controller looks like the following:

KI K D s2 + K p + K I
K p+ + K D s=
s s
K p =Proportional gain, K D=Derivative gain and K I =Integral gain respectively. First,
let’s take a look at how the PID controller works in a closed-loop system using

36 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

the schematic shown above. The variable (e) represents the tracking error, the
difference between the desired input value (R) and the actual output (Y). This
error signal (e) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal (u) just past
the controller is now equal to the proportional gain (KP) times the magnitude of
the error plus the integral gain (KI) times the integral of the error plus the
derivative gain (KD) times the derivative of the error.

de (t)
u=K p e ( t )+ K I ʃe ( t ) dt + K D
dt
This signal (u) will be sent to the plant, and the new output (Y) will be obtained.
This new output (Y) will be sent back to the sensor again to find the new error
signal (e). The controller takes this new error signal and computes its
derivatives and its internal again. The process goes on and on.

X (s ) 1
G ( s )= = 2 =Plant Function
F ( s ) s +10 s+20
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of
the output to a unit step input. This corresponds to the steady-state error of 0.95,
quite large indeed. Furthermore, the rise time is about one second, and the
settling time is about 1.5 seconds. Let's design a controller that will reduce the
rise time, reduce the settling time, and eliminates the steady-state error.
Proportional control:
The closed-loop transfer function of the above system with a proportional
controller is:

X (s ) Kp
= 2
F ( s ) s +10 s+(20+ K p )

Let the proportional gain (KP) equal 300:


Kp=300;
contr=Kp;
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl, t)
Output:

37 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Note: The MATLAB function called feedback was used to obtain a closed-loop transfer
function directly from the open-loop transfer function (instead of computing closed-loop
transfer function by hand). We have to analyze that the proportional controller reduced
both the rise time and the steady-state error, increased the overshoot, and decreased the
settling time by small amount.

38 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 09

Introduction to Proportional-Integral
Controller
OBJECT: - Investigate the characteristics of the proportional-Integral
Controller.
Apparatus Required: PC loaded with MATLAB.
Theory:
Introduction: Consider the following unity feedback system:

Plant: A system to be controlled.


Controller: Provides excitation for the plant; Designed to control the overall
system behavior. The three-term controller: The transfer function of the PID
controller looks like the following:

KI K D s2 + K p + K I
K p+ + K D s=
s s
K p =Proportional gain, K D=Derivative gain and K I =Integral gain respectively. First,
let’s take a look at how the PID controller works in a closed-loop system using
the schematic shown above. The variable (e) represents the tracking error, the

39 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

difference between the desired input value (R) and the actual output (Y). This
error signal (e) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal (u) just past
the controller is now equal to the proportional gain (KP) times the magnitude of
the error plus the integral gain (KI) times the integral of the error plus the
derivative gain (KD) times the derivative of the error.

de (t)
u=K p e ( t )+ K I ʃe ( t ) dt + K D
dt
This signal (u) will be sent to the plant, and the new output (Y) will be obtained.
This new output (Y) will be sent back to the sensor again to find the new error
signal (e). The controller takes this new error signal and computes its
derivatives and its internal again. The process goes on and on.

X (s ) 1
G ( s )= = 2 =Plant Function
F ( s ) s +10 s+20
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of
the output to a unit step input. This corresponds to the steady-state error of 0.95,
quite large indeed. Furthermore, the rise time is about one second, and the
settling time is about 1.5 seconds. Let's design a controller that will reduce the
rise time, reduce the settling time, and eliminates the steady-state error.
Proportional-Integral control:
Before going into a PID control, let's take a look at a PI control. For the given system,
the
closed-loop transfer function with a PI control is:

X (s ) K p s +KI
= 3 2
F ( s ) s +10 s + ( 20+ K p ) s+ K I

Let's reduce the KP to 30 and let KI equal 70.


Kp=30;
Ki=70;
contr=tf([Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Output:

40 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Analyze:

Analysis:

41 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-
FEPS
LAB SESSION 10
Introduction to Proportional-Derivative
Controller
OBJECT: - Investigate the characteristics of the Proportional-Derivative
Controller.
Apparatus Required: PC loaded with MATLAB.
Theory:
Introduction: Consider the following unity feedback system:

Plant: A system to be controlled.


Controller: Provides excitation for the plant; Designed to control the overall
system behavior. The three-term controller: The transfer function of the PID
controller looks like the following:

KI K D s2 + K p + K I
K p+ + K D s=
s s
K p =Proportional gain, K D=Derivative gain and K I =Integral gain respectively. First,
let’s take a look at how the PID controller works in a closed-loop system using
the schematic shown above. The variable (e) represents the tracking error, the
difference between the desired input value (R) and the actual output (Y). This

42 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

error signal (e) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal (u) just past
the controller is now equal to the proportional gain (KP) times the magnitude of
the error plus the integral gain (KI) times the integral of the error plus the
derivative gain (KD) times the derivative of the error.

de (t)
u=K p e ( t )+ K I ʃe ( t ) dt + K D
dt
This signal (u) will be sent to the plant, and the new output (Y) will be obtained.
This new output (Y) will be sent back to the sensor again to find the new error
signal (e). The controller takes this new error signal and computes its
derivatives and its internal again. The process goes on and on.

X (s ) 1
G ( s )= = 2 =Plant Function
F ( s ) s +10 s+20
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of
the output to a unit step input. This corresponds to the steady-state error of 0.95,
quite large indeed. Furthermore, the rise time is about one second, and the
settling time is about 1.5 seconds. Let's design a controller that will reduce the
rise time, reduce the settling time, and eliminates the steady-state error.

Proportional-Derivative control:
The closed-loop transfer function of the given system with a PD controller is:

X (s ) K D s+ K P
= 2
F ( s ) s + ( 10+ K D ) s+¿ ¿
Let KP equal 300 as before and let KD equal 10.
Kp=300;
Kd=10;
contr=tf([Kd Kp],1);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Output:

43 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Analysis:

44 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-
FEPS
LAB SESSION 11

Introduction to PID Controller


OBJECT: - Study the three term (PID) controller and its effects on the feedback loop
response. Investigate the characteristics of the each of proportional (P), the integral (I),
and the derivative (D) controls, and how to use them to obtain a desired response.
Apparatus Required: PC loaded with MATLAB.
Theory:
Introduction: Consider the following unity feedback system:

Plant: A system to be controlled.


Controller: Provides excitation for the plant; Designed to control the overall
system behavior. The three-term controller: The transfer function of the PID
controller looks like the following:

KI K D s2 + K p + K I
K p + + K D s=
s s
K p =Proportional gain, K D=Derivative gain and K I =Integral gain respectively. First,
let’s take a look at how the PID controller works in a closed-loop system using
the schematic shown above. The variable (e) represents the tracking error, the
difference between the desired input value (R) and the actual output (Y). This
error signal (e) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal (u) just past
45 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

the controller is now equal to the proportional gain (KP) times the magnitude of
the error plus the integral gain (KI) times the integral of the error plus the
derivative gain (KD) times the derivative of the error.

de (t)
u=K p e ( t )+ K I ʃe ( t ) dt + K D
dt
This signal (u) will be sent to the plant, and the new output (Y) will be obtained.
This new output (Y) will be sent back to the sensor again to find the new error
signal (e). The controller takes this new error signal and computes its
derivatives and its internal again. The process goes on and on.

X (s ) 1
G ( s )= = 2 =Plant Function
F ( s ) s +10 s+20
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of
the output to a unit step input. This corresponds to the steady-state error of 0.95,
quite large indeed. Furthermore, the rise time is about one second, and the
settling time is about 1.5 seconds. Let's design a controller that will reduce the
rise time, reduce the settling time, and eliminates the steady-state error.

Proportional-Integral-Derivative control:
Now, let's take a look at a PID controller. The closed-loop transfer function of the given
system with a PID controller is:

X (s ) K D s2 + K P + K I
= 3
F ( s ) s + ( 10+ K D ) s2 + ( 20+ K P ) s+ K I
After several trial and error runs, the gains Kp=350, Ki=300, and Kd=50
provided the desired response. To confirm, enter the following commands to an
m-file and run it in the command window. You should get the following step
response.
Kp=350;
Ki=300;
Kd=50;
contr=tf([Kd Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl, t)
The characteristics of P, I, and D controllers:
The proportional controller (KP) will have the effect of reducing the rise time
and will reduce, but never eliminate, the steady state error. An integral
controller (KI) will have the effect of eliminating the steady state error, but it

46 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

may make the transient response worse. A derivative control (KD) will have the
effect of increasing the stability of the system, reducing the overshoot and
improving the transient response.

Output:

Conclusion:

47 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 12

Exploring the Mathematical Modelling of Electrical Systems.


OBJECT: - Mathematical Modelling of Electrical Systems.
Apparatus Required: PC loaded with MATLAB.
Theory:

The differential equations for the given system are:


According to Mesh Analysis:
e (t )=V L +V C +V R
1
e (t )=LDi+ i+iR
CD
The state equations for the given circuit:
This circuit contains two energy-storage elements, Inductor and Capacitor: State
variable are chosen those elements that can store energy and are differentiable.
48 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Let state-variables are:


X 1 =V C the voltage across the capacitor.
X 2 =i the current in the inductor.
State Equations:

1
x˙1
[ ]
x˙2
=
[ ][ ] [ ]
0
1
L
PROCEDURE:
C x 1 + 0 [u ]
−R x 2
L
1
L

Create a MATLAB-function RLC.m: Write another M. file to call the


function dXdt=RLC( t, X) function:
e= 60; ;%(V) Clear
R= 10; ;%(Ohm) Close
L= 1; ;%(H) Clc
C= 10; ;%(F) X0= [0 0];
% dX/dt [t, X] = ode45(‘RLC’, [0 500], X0);
dXdt (1, 1) = (1/C) *X (2); Subplot(2, 1, 1);
dXdt (2, 1) = (-1/L) * X (1) - (R/L) * X (2) + (1/L) Plot(t, X(:, 1));
*e; Legend(‘Vc’);
grid on;
title(‘Vc’);
subplot(2, 1 , 2);
plot(t, X(:,2), ‘r’);
legend(‘i’);
grid on;
title(‘i’);

Graph:

49 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Time constant= RC= 10*10=100sec


For first time constant:
Vc= 63.2%*e = 0.632*60 = 37.92V

Observations:
Parameter Behavior of System
Voltage Source (e)
Resistance (R)
Inductance (L)
Capacitance (C)

Conclusion:

50 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 13

Exploring the DC Motor Characteristics

OBJECT: - The objective of the experiment is to show how a permanent magnet


D.C. motor may be controlled by varying the magnitude and direction of its armature
current and recognize the torque/speed characteristic of the D.C. Motor
Theory:
Consider a DC motor, whose electric circuit of the
armature and the free body diagram of the rotor are shown in Figure. The aim of the
experiment is to show how a permanent magnet D.C motor may be controlled by
varying the magnitude and direction of its armature current and recognize the
torque/speed characteristic of the D.C. Motor.

Figure: DC Motor armature-controlled rotational actuator.

As the motor accelerates the armature generates an increasing 'back-emf' Va tending to


oppose the driving voltage Vin. The armature current is thus roughly proportional to
(Vin -

51 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Va). If the speed drops (due to loading) Va reduces, the current increases and thus so
does the motor torque. This tends to oppose the speed drop. This mode of control is
called 'armature control' and gives a speed proportional to Vin as in figure.

Model of the armature-controlled DC motor:


Procedure:

Student should be able to understand how electrical terms (voltage, current, emf)
interact with mechanical terms (speed, position) via electro-magnetic circuit
(inductance). The motor torque, T, is related to the armature current, i, by a constant
factor Kt. The back emf, e, is related to the rotational velocity by the following
equations:

T =K t i

e=K e
dt

In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant).

Building the Model:


This system will be modeled by summing the torques acting on the rotor inertia and
integrating the acceleration to give the velocity and integrating velocity to get position.
Also, Kirchhoff’s laws will be applied to the armature circuit. Open Simulink and
open a new model window. First, we will model the integrals of the rotational
acceleration and of the rate of change of armature current.
2
∬ ddtθ2 =∫ dθ
dt

di
∫ dt =i

52 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Insert an Integrator block (from the Linear block library) and draw lines to and from its
input and output terminals.
 Label the input line "d2/dt2(theta)" and the output line "d/dt(theta)" as shown
below.
 To add such a label, double click in the empty space just above the line.
 Insert another Integrator block attached to the output of the previous one and
draw a line from its output terminal.
 Label the output line "theta".
 Insert a third Integrator block above the first one and draw lines to and from its
input and output terminals.
 Label the input line "d/dt(i)" and the output line "i".

Next, we will start to model both Newton's law and Kirchhoff’s law. These laws
applied to the motor system give the following equations:

d2 θ dθ

=T −b => −b
J => 1 (K ¿ ¿t i−b dθ )¿
dt 2
dt dt J dt
di 1 dθ
L =−Ri+V −e=¿ (−Ri +V −K e )
dt L dt
The angular acceleration is equal to 1/J multiplied by the sum of two terms (one pos.,
one
neg.). Similarly, the derivative of current is equal to 1/L multiplied by the sum of three
53 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

terms
(one pos., two neg.).
 Insert two Gain blocks, (from the Linear block library) one attached to each of
the leftmost integrators.
 Edit the gain block corresponding to angular acceleration by double-clicking it
and changing its value to "1/J".
 Change the label of this Gain block to "inertia" by clicking on the word "Gain"
underneath the block.
 Similarly, edit the other Gain's value to "1/L" and its label to Inductance.
 Insert two Sum blocks (from the Linear block library), one attached by a line
to each of the Gain blocks.
 Edit the signs of the Sum block corresponding to rotation to "+-" since one
term is positive and one is negative.
 Edit the signs of the other Sum block to "-+-" to represent the signs of the
terms in Kirchhoff’s equation.

Now, we will add in the torques which are represented in Newton's equation. First, we
will add in the damping torque.
 Insert a gain block below the inertia block, select it by single-clicking on it, and
select Flip from the Format menu (or type Ctrl-F) to flip it left-to-right.
 Set the gain value to "b" and rename this block to "damping".

54 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

 Tap a line (hold Ctrl while drawing) off the first rotational integrator's output
(d/dt(theta)) and connect it to the input of the damping gain block.
 Draw a line from the damping gain output to the negative input of the rotational
Sum block.
Next, we will add in the torque from the armature.
 Insert a gain block attached to the positive input of the rotational Sum block
with a line.
 Edit its value to "K" to represent the motor constant and Label it "Kt".
 Continue drawing the line leading from the current integrator and connect it to
the Kt gain block.

Now, we will add in the voltage terms which are represented in Kirchhoff’s equation.
First, we will add in the voltage drop across the coil resistance.

 Insert a gain block above the inductance block and flip it left-to-right.
 Set the gain value to "R" and rename this block to "Resistance".
 Tap a line (hold Ctrl while drawing) off the current integrator's output and

55 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

connect it to the input of the resistance gain block.


 Draw a line from the resistance gain output to the upper negative input of the
current equation Sum block. Next, we will add in the back emf from the motor.
 Insert a gain block attached to the other negative input of the current Sum block
with a line.
 Edit its value to "K" to represent the motor constant and Label it "Ke".
 Tap a line off the first rotational integrator's output (d/dt(theta)) and connect it to
the Ke gain block.

The third voltage term in the Kirchhoff equation is the control input, V. We will apply
a step input.

 Insert a Step block (from the Sources block library) and connect it with a line to
the positive input of the current Sum block.

56 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

 To view the output speed, insert a Scope (from the Sinks block library)
connected to the output of the second rotational integrator (theta).
 To provide an appropriate unit step input at t=0, double-click the Step block
and set the Step Time to "0".

DC motor nominal values:


 moment of inertia of the rotor (J) = 3.2284E-6 kg.m^2/s^2
 damping ratio of the mechanical system (b) = 3.5077E-6 Nms.
 electromotive force constant (K=Ke=Kt) = 0.0274 Nm/Amp
 electric resistance (R) = 4 ohm
 electric inductance (L) = 2.75E-6 H
 input (V): Source Voltage
 output (theta): position of shaft
The physical parameters must now be set. Run the following commands at the
MATLAB
prompt:
 J=3.2284E-6;
 b=3.5077E-6;
 K=0.0274;
 R=4;
 L=2.75E-6;

57 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

 Run the simulation (Ctrl-t or Start on the Simulation menu).


Simulation:
To simulate this system, first, an appropriate simulation time must be set. Select
Parameters
from the Simulation menu and enter "0.2" in the Stop Time field. 0.2 seconds is long
enough
to view the open-loop response. Also, in the Parameters dialog box, it is helpful to
change the Solver Options method. Click on the field which currently contains "ode45
(Dormand-Prince)". Select the option "ode15s (stiff/NDF)". Since the time scales in
this example are very small, this stiff system integration method is much more efficient
than the default integration method.

Step input:
 Use step input from 0 volts to 2 volts and observe the response.
 Save the response to workspace variable to further compare with the
experimental DC motor (DCM 150F).
 Now Step the input voltage from 2 volts to 4 volts. Save the response to further
compare with experimental motor.
 This is the simulation section for the Exercise 2 – Step input.

Conclusion:

58 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

NAZEER HUSSAIN UNIVERSITY


DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

LAB SESSION 14

Verifying the Block Reduction Technique

OBJECT: The objective of this exercise will be to learn commands in MATLAB that
would be used to reduce linear systems block diagram using series, parallel and
feedback configuration.
Theory:
Series configuration: If the two blocks are connected as shown below then the blocks
are said to be in series. It would like to multiply two transfer functions. The MATLAB
command for the such configuration is “series”.

The series command is implemented as shown below:

MATLAB Code for Series configuration implementation.

59 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

Parallel configuration: If the two blocks are connected as shown below then the
blocks are said to be in parallel. It would like to add two transfer functions.

The MATLAB command for implementing a parallel configuration is “parallel” as


shown
below:

Feedback configuration: If the blocks are connected as shown below then the blocks
are
said to be in feedback. Notice that in the feedback there is no transfer function H(s)
defined.
When not specified, H(s) is unity. Such a system is said to be a unity feedback system.

The MATLAB command for implementing a feedback system is “feedback” as shown


below:

When H(s) is non-unity or specified, such a system is said to be a non-unity feedback

60 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU

system
as shown below:

A non-unity feedback system is implemented in MATLAB using the same “feedback”


command as shown:

Questions:
Question No:1 Given the transfer functions of individual blocks, generate the system
transfer function of the block combinations?

Example 2: For the systems defined in Question No: 1, modify the MATLAB
commands to obtain the overall transfer function when the two blocks are in parallel?

Example 3: Given a unity feedback system as shown in the figure, obtain the overall
transfer
function using MATLAB.

61 | P a g e
Linear Control System EE-304 Department of Electrical Engineering,
NHU NAZEER
HUSSAIN UNIVERSITY
DEPARTMENT OF ELECTRICAL ENGINEERING
FACULTY OF ENGINEERING PRACTICES AND SCIENCES-FEPS

Open Ended Lab


(Freedom to develop own experiment without guidelines)
Objective:

Obtain pole, zero & gain values of a transfer function and Write MATLAB
code to obtain transfer function of a system from its pole, zero, gain values.
Assume pole locations are -2, 1, zero at -1 and gain is 7, also change and choose
according to your own observation.
Observation:

Stability criteria of a system is determined and with the help of various poles
and zeroes and by changing gain values it is observed that what effect system
has on stability and system response.

Learning Outcomes:

Pole, zero values and gain are important parameters for analyzing system
response and all these helps to observe stability of the system and Stability
analysis is very important in the field of Control Systems.

62 | P a g e

You might also like