Ghanchi Mukim Anvar 190230109019 Electrical Engineering: Name Enrollment No Branch
Ghanchi Mukim Anvar 190230109019 Electrical Engineering: Name Enrollment No Branch
ENROLLMENT NO : 190230109019
Objectives: This lab provides an introduction to MATLAB in the first part. The lab also
provides tutorial of polynomials, script writing and programming aspect of MATLAB from
control systems view point.
Polynomial Overview:
MATLAB provides functions for standard polynomial operations, such as polynomial roots,
evaluation, and differentiation. In addition, there are functions for more advanced application,
such as curve fitting and partial fraction expansion.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Characteristic polynomials
The poly function also computes the coefficients of the characteristic polynomial of a matrix:
>> A = [1.2 3 -0.9; 5 1.75 6; 9 0 1];
>> poly(A)
ans =
1.0000 -3.9500 -1.8500 -163.2750
Polynomial Evaluation
The polyval function evaluates a polynomial at a specified value. To evaluate p at s = 5, use
>> polyval (p,5) ans
=
110
It is also possible to evaluate a polynomial in a matrix sense. In this case the equation p(x)= x3
−2x −5 becomes p(X) = X 3 −2X −5I , where X is a square matrix and I is the identity matrix.
For example, create a square matrix and evaluate the polynomial p at X:
>> X = [2 4 5; -1 0 3; 7 1 5];
>> Y = polyvalm (p, X)
Y=
377 179 439
111 81 136
490 253 639
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
4 5 6
r=
0 0 0 0 0
Polynomial Derivatives
The polyder function computes the derivative of any polynomial. To obtain the derivative of
the polynomial >> p = [1 0 -2 -5]; >>q = polyder(p) q =
3 0 -2
Polyder also computes the derivative of the product or quotient of two polynomials. For
example, create two polynomials a and b:
>>a = [1 3 5]:
>>b = [2 4 6]: >>c
= polyder(a, b) c =
8 30 56 38
>>[q,d] = polyder (a,b) q
=
-2 -8 -2
d=
4 16 40 48 36 q/d is
the result of the operation.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
a2 =
1 6 8
Exercise 1: Consider the two polynomials p(s) =s2 + 2s+1 and q(s)=s+1. Using
MATLAB compute a.
p(s)*q(s)
b. Roots of p(s) and q(s)
c. p(-1) and q(6)
Exercise 2: Use MATLAB command to find the partial fraction of the following
B(s) 2s3 +5s2 +3s+6
a. = 3 6s2 +11s+6 A(s) s +
B(s) s2
b. A(s) = +2s+3 3
(s+1)
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Functions:
Functions are M-files that can accept input arguments and return output arguments. The names
of the M-file and of the function should be the same. Functions operate on variables within
their own workspace, separate from the workspace you access at the MATLAB command
prompt. An example is provided below:
function f = fact(n) Function definition
line
% Compute a factorial value. H1 line
% FACT(N) returns the factorial Help text
of N, % usually denoted by N!
% Put simply, FACT(N) is Comment
PROD(1:N).
f = prod(1:n); Function body
M-File Element Description
Function definition Define the function name, and the number and
line (functions only) order of input and output arguments.
H1 line A one line summary description of the program,
displayed when you request help on an entire
directory, or when you use ‘look for’.
Help text A more detailed description of the program,
displayed together with the H1 line when you
request help on a specific function.
Function or script Program code that performs the actual computations
body and assigns values to any output arguments.
Comments Text in the body of the program that explains the
internal workings of the program.
The first line of a function M-file starts with the keyword ‘function’. It gives the function name
and order of arguments. In this case, there is one input arguments and one output argument.
The next several lines, up to the first blank or executable line, are comment lines that provide
the help text. These lines are printed when you type ‘help fact’. The first line of the help text is
the H1 line, which MATLAB displays when you use the ‘lookfor’ command or request help
on a directory. The rest of the file is the executable MATLAB code defining the function. The
variable n & f introduced in the body of the function as well as the variables on the first line
are all local to the function; they are separate from any variables in the MATLAB workspace.
This example illustrates one aspect of MATLAB functions that is not ordinarily found in other
programming languages - a variable number of arguments. Many M-files work this way. If no
output argument is supplied, the result is stored in ans. If the second input argument is not
supplied, the function computes a default value.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Flow Control:
Conditional Control – if, else, switch
This section covers those MATLAB functions that provide conditional program control. if,
else, and elseif. The if statement evaluates a logical expression and executes a group of
statements when the expression is true. The optional elseif and else keywords provide for the
execution of alternate groups of statements. An end keyword, which matches the if, terminates
the last group of statements.
The groups of statements are delineated by the four keywords - no braces or brackets are
involved as given below. if<condition>
<statements>;
elseif<condition>
<statements>; else
<statements>; end
It is important to understand how relation operators and if statements work with matrices. When
you want to check for equality between two variables, you might use if A == B, …..
This is valid MATLAB code, and does what you expect when A and B are scalars. But when
A and B are matrices, A == B does not test if they are equal, it tests where they are equal; the
result is another matrix of 0's and 1's showing element-by-element equality. (In fact, if A and
B are not the same size, then A == B is an error.)
>> A = magic(4);
>> B = A;
>> B (1,1) =
0; >> A = = B
ans = 2
0 1 1 23
1 1 1 24
1 1 1 27
1 1 1 1
The proper way to check for equality between two variables is to use is equal function:
If isequal(A,B),…
Isequal returns a scalar logical value of 1 (representing true) or 0 (false), instead of a matrix, as
the expression to be evaluated by the if function.
Using the A and B matrices from above, you get
>>isequal(A, B)
ans= 0
Here is another example to emphasize this point. If A and B are scalars, the following program
will never reach the “unexpected situation”. But for most pairs of matrices, including our magic
if A > B 'greater' elseif A < B
'less'
elseif A == B
'equal' else
error('Unexpected situation') end squares with interchanged columns, none of the matrix
conditions A>B, A<B, or A == B is true for all elements and so the else clause is executed:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Several functions are helpful for reducing the results of matrix comparisons to scalar conditions
for use with if, including ‘isequal’, ‘isempty’, ‘all’, ‘any’.
For:
The ‘for’ loop, is used to repeat a group of statements for a fixed, predetermined number of
times. A matching ‘end’ delineates the statements. The syntax is as follows: for <index> =
<starting number>:<step or increment>:<ending number>
<statements>; end
for n=1:4
r(n) = n*n; % square of number end
The semicolon terminating the inner statement suppresses repeated printing, and the r after the
loop displays the final result.
It is a good idea to indent the loops for readability, especially when they are nested:
for i = 1:m
for j = 1:n
H(i,j) = 1/(i+j);
end
end while:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
The ‘while’ loop, repeats a group of statements indefinite number of times under control of a
logical condition. So a while loop executes at least once before it checks the condition to stop
the execution of statements. A matching ‘end’ delineates the statements. The syntax of the
‘while’ loop is as follows:
while <condition>
<statements>; end
Here is a complete program, illustrating while, if, else, and end, that uses interval bisection to
find a zero of a polynomial:
a = 0; fa = -Inf;
b = 3; fb = Inf; while b-a>eps*b x = (a+b)/2; fx = x.^3-
2*x-5; if sign(fx) == sign(fa) a = x; fb = fx;
else b =
x; fb = fx;
end
end x
The result is a root of the polynomial x3 - 2x - 5, namely x = 2.0945. The cautions involving
matrix comparisons that are discussed in the section on the if statement also apply to the while
statement. break:
The break statement lets you exit early from a ‘for’ loop or ‘while’ loop. In nested loops, break
exits from the innermost loop only. Above is an improvement on the example from the previous
section. Why is this use of break a good idea?
a = 0; fa = -Inf; b
= 3; fb = Inf;
while b-a > eps*b
x = (a+b)/2; fx =
x.^3-2*x-5; if fx
== 0 break
elseif sign(fx) == sign(fa)
a = x; fa = fx; else b = x;
fb = fx; end end
Continue:
The continue statement passes control to the next iteration of the for loop or while loop in which
it appears, skipping any remaining statements in the body of the loop. The same holds true for
continue statements in nested loops. That is, execution continues at the beginning of the loop
in which the continue statement was encountered.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Rn vs , where vn and Rn are the voltage across resistor n and its resistance,
respectively
vn =
Req
Req = ƩRn is the equivalent resistance and Vs is the source voltage. The power
dissipated in Rn vs2 . Write a program in a script file that calculates the each resistor is given by:
Pn = 2
Req
voltage across each resistor, and the power dissipated in each resistor, in a circuit that has
resistors connected in series. When file is executed it requests the user to first enter the source
voltage and then to enter the resistance of resistors in a vector. The program displays a table
with the resistances listed in the first column, the voltage across the resistor in the second, and
the power dissipated in the resistor in the third column. Following the table, the program
displays the current in the circuit, and the total power. Run the file and enter the following data
for vs and the R’s.
vs=24 V; R1=20Ω; R2=14Ω; R3=12Ω; R4=18Ω; R5=8Ω; R6=15Ω; R7=10Ω
sin x= k=o (2k+1)! . Write a user defined function file that calculates sin(x)
by using the Taylor’s series. For the function name and argument use y = Tsin(x,n).
The input arguments are the angle x in degrees, and n the number of terms in the series.
Use the function to calculate sin (150˚) using 3 and 7 terms.
*******
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
AIM: To study Linear Time Invariant System and Representation using MATLAB
Objectives: The objective of this exercise is to learn commands in MATLAB that would be
used to represent such systems in terms of transfer function or pole-zero gain representations.
Also learn how to make preliminary analysis of such systems using plots of poles and zeros
locations as well as time response due to impulse, step and arbitrary inputs.
The spring force is assumed to be either linear or can be approximated by a linear function
Fs(x)=Kx, B is the friction coefficient, x(t) is the displacement and Fa(t) is the applied force:
The differential equation for the above Mass-spring system can then be derived as follows
d2x(t) dx(t)
M dt2 + B dt + Kx(t) = Fa (t)
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Transfer Function:
Applying the Laplace transformation while assuming the initial conditions are zeros, we get
Output Fa(s) 1
TF = Input = X(s) = Ms2 + Bs + K
Linear Time-Invariant systems in MATLAB:
Control System toolbox in MATLAB offers extensive tools to manipulate and analyze linear
time-invariant (LTI) models. It supports both continuous and discrete-time systems. Systems
can be single-input/single-output (SISO) or multiple-input/multiple-output (MIMO). You can
specify LTI model as:
Transfer functions (TF), for example,
+1
P(s)= s2 +s s +10
Note: All LTI models are represented as a ratio of polynomial functions.
Building LTI models with Control System Toolbox is straightforward. The following sections
show simple examples. Note that all LTI models, i.e. TF, ZPK and SS are also MATLAB
objects.
You can create transfer function (TF) models by specifying numerator and denominator
coefficient. For example,
>>num = [1 0];
>>den = [1 2 1];
Transfer function:
sys =
s
-------------
s^2 + 2 s + 1
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
A useful trick is to create the Laplace variable, s. That way, you can specify polynomials using
s as the polynomial variable.
Transfer function:
s
-------------
s^2 + 2 s + 1
This is identical
to the previous
transfer
function.
To create zero-pole-gain(ZPK) models, you must specify each of three components in vector
format. For example,
>>sys=zpk([0];[-1 -1],[1])
s
-------
(s+1)^2
Produces the same transfer function built in the TF example, but the representation in now
ZPK. This example shows a more complicated ZPK model.
Zero/pole/gain
0.776 s (s-1)
--------------------
(s+1) (s+3) (s+0.28)
[p,z]=pzmap(sys)
pzmap(sys) plots the pole-zero map of the continuous or discrete-time LTI model sys. For SISO
systems, pzmap plots the transfer function poles and zeros. The poles are plotted as x’s and the
zeros are plotted as o’s. pzmap(sys1,sys2,…sysN) plots the pole-zero map of several LTI
models on a single figure. The LTI models can have different numbers of inputs and outputs.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
When invoked with left hand arguments, [p,z]=pzmap(sys) returns the system poles and zeros
in the column vectors p and z. No plot is drawn on the screen. You can use the functions sgrid
and zgrid to plot lines of constant damping ratio and natural frequency in the s- or z- plane.
Example
2s2 + 5s +1
P(s) = s2 + 2s + 3
>>H = tf([2 5 1], [1 2 3]);
>>pzmap(H)
>>sgrid
You can simulate the LTI systems to inputs like impulse, step and other standard inputs and
see the plot of the response in the figure window. MATLAB command ‘impulse’ calculates the
unit impulse response of the system, ‘step’ calculates the unit step response of the system and
‘lsim’ simulates the (time) response of continuous or discrete linear systems to arbitrary inputs.
When invoked without left-hand arguments, all three commands plots the response on the
screen. For example:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
>>impulse (H)
>>step (H)
Time-interval specification:
To contain the response of the system you can also specify the time interval to simulate the
system.
For example,
>>t=0:0.01:10;
To simulate the time response of continuous or discrete linear systems to arbitrary inputs use
‘lsim’. When invoked without left-hand arguments, ‘lsim’ plots the response on the screen.
Lsim (sys,u,t) produces a plot of the time response of the LTI model sys to the input time history
‘t’, ‘u’. The vector ‘t’ specifies the time samples for the simulation and consists of regularly
spaced time samples.
T = 0:dt:Tfinal
The matrix u must have as many rows as time samples (length(t)) and as many columns as
system inputs.
Simulate and plot the response of the system
2s2 +5s+1
H(s) = s2 + 2s+3
to a square wave with period of four seconds.
First generate the square wave with gensig. Sample every 0.1 second during 10 seconds:
>>[u, t] = gensig(‘square’,4,10,0.1);
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
>>lsim(H,u,t)
Linear Simulation Results
2.5
1.5
0.5
Amplitude 0
-0.5
-1
-1.5
-2
0 1 2 3 4 5 6 7 8 9 10
Time (seconds)
6s2 +1
=
G(s) s3 + 3s2 +
3s + 7
Using MATLAB plot the pole zero map of the above system
Exercise 2:
Plot the response of the system when R(s) is a unit impulse and unit step for the parameter
z=3,6 and 12.
******
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Objectives: 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.
Series configuration:
If two blocks are connected as shown below then the blocks are said to be in series. It would
like multiplying two transfer function. The MATLAB command for such configuration is
“series”.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Example 1: Given the transfer functions of individual blocks generate the system transfer
function of the block combinations.
sys =
s + 1 -----------------
-
500 s^3 + 1000 s^2
Parallel configuration: If two blocks are connected as shown below then the blocks are said
to be in parallel. It would like adding two transfer functions.
Example 2: For the previous system defined, modify the MATLAB commands to obtain the
overall transfer function when the two blocks are in parallel.
Feedback configuration: If the blocks are connected as shown below then the blocks are said
to be in feedback. Notice that in the feedback there is no transfer function H(s) defined. When
not specified, H(s) is unity. Such a system is said to be a unity feedback system.
The MATLAB command for implementing a feedback system is “feedback” as shown below.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
When H(s) is non-unity or specified, such a system is said to be a non-unity feedback system
as shown below:
Example 3: Given a unity feedback system as shown in the figure, obtain the overall transfer
function using MATLAB:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
sys =
s+1
--------------------------
500 s^3 + 1000 s^2 + s + 1
Example 4: Given a non-unity feedback system as shown in the figure, obtain the overall
transfer function using MATLAB:
>> sys
s+2
--------------------------
500 s^3 + 1000 s^2 + s + 1
Poles and Zeros of system: To obtain the poles and zeros of the system use the MATLAB
command “pole” and “zero” respectively as shown in example 5. You can also use MATLAB
command “pzmap” obtain the same.
Example 5: Given a system transfer function plot the location of the system zeros and poles
using MATLAB pole-zero map command.
For Example:
>> z = zero(sysg)
z=
0 + 0.4082i
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
0 - 0.4082i >>
p = pole(sysg)
p=
-1.0000
-1.0000 + 0.0000i
-1.0000 - 0.0000i
>>sys = sysg/sysh
6 s^5 + 18 s^4 + 25 s^3 + 75 s^2 + 4 s + 12
------------------------------------------- s^5 +
6 s^4 + 14 s^3 + 16 s^2 + 9 s + 2
>>pzmap(sys)
Exercise 1:
For the following multi-loop feedback system, get closed loop transfer function and the
corresponding pole-zero map of the system.
Exercise 2:
Consider the feedback system depicted in the figure below.
a. Compute the closed-loop transfer function using the ‘series’ and ‘feedback’ functions
b. Obtain the closed-loop system unit step response with the ‘step’ function and verify that
final value of the value of the output is 2/5.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Exercise 3:
A satellite single-axis altitude control system can be represented by the block diagram in the
figure given. The variables ‘K’, ‘a’ and ‘b’ are controller parameters, and ‘J’ is the spacecraft
moment of inertia. Suppose the nominal moment of inertia is ‘J’ = 10.8E8, and the controller
parameters are k = 10.8E8, a=1, and b=8.
Exercise 4:
Consider the feedback control system given in figure, where
G ( s) = + and H (s) =
s 1 1
s +2 s +1
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
******
AIM: To Study performance of first order and second order system using MATLAB.
Objectives: The objective of this exercise will be to study the performance characteristics of
first and second order systems using MATLAB.
Fig. 1: RC circuit
If the capacitor is initially uncharged at zero voltage when the circuit is switched on, it starts to
charge due to the current ‘i’ through the resistor until the voltage across it reaches the supply
voltage. As soon as this happens, the current stops flowing or decays to zero, and the circuit
becomes like an open circuit. However, if the supply voltage is removed, and the circuit is
closed, the capacitor will discharge the energy it stored again through the resistor. The time it
takes the capacitor to charge depends on the time constant of the system, which is defined as
the time taken by the voltage across the capacitor to rise to approximately 63% of the supply
voltage. For a given RC-circuit, this time constant is τ=RC. Hence its magnitude depends on
the values of the circuit components.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
The RC circuit will always behave in this way, no matter what the values of the components.
That is, the voltage across the capacitor will never increase indefinitely. In this respect we will
say that the system is passive and because of this property it is stable.
For the RC circuit as shown in Fig. 1, the equation governing its behavior is given by
dVc(t) 1 1
+ Vc(t) = E where VC(0) = V0 (1) dt RC RC
Where VC(t) is the voltage across the capacitor, R is the resistance and C is the capacitance.
The constant τ=RC is the time constant of the system and is defined as the time required by the
system output i.e.VC(t) to rise to 63% of its final value (which is E). Hence the above equation
(1) can be expressed in terms of the time constant as:
dVc(t)
+Vc(t) = E where Vc(0) = V0 dt
Obtaining the transfer function of the above differential equation, we get
Vc(s) 1
= g(s) s +1
Where τ is time constant of the system and the system is known as the first order system. The
performance measures of a first order system are its time constant and its steady state.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Output F(s) 1
TF = Input = X(s) = (Ms2 + Bs + K)
Y(s) = 2
2 n
n s+ n2 R(s)
S+
With step input applied to the system, we obtain
2
Y(s) = 2
for which the transient output, as obtained from the Laplace transform is
1
Y(t) =1− 1 − e− nt sin( n 1− 2t + cos−1( ))
2
where 0 < δ <1. The transient response of the system changes for different values of damping
ratio, δ. Standard performance measures for a second order feedback system are defined in
terms of step response of a system. Where, the response of the second order system is shown
below.
P.O. = M Pt − fv X100%
fv
where MPt is the peak value of the time response, and fv is final value of the response. Settling
Time: The time required for the system’s output to settle within a certain percentage of the
input amplitude (which is usually taken as 2%). Then, settling time, Ts, is calculated as
4
Ts =
n
Exercise 1:
a. Given the values of R and C, obtain unit step response of the first order system.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Exercise 2:
Effect of damping ratio ζ on performance measures. For a single-loop second order feedback
system given below.
Find the step response of the system for values of ωn =1 and ζ = 0.1, 0.4, 0.7, 1.0 and 2.0. Plot
all the results in the same figure window and fill the following table.
Settling Steady state
ζ Rise Time Peak Time %Overshoot
time value
0.1
0.4
0.7
1.0
2.0
******
AIM: To Study Proportional, PI and PID controller and its response using MATLAB.
Objectives: Study the three term (PID) controller and its effects on the feedback loop response.
Investigate the characteristics of each of proportional (P), the integral (I), and the derivative
(D) controls, and how to use them to obtain a desired response.
Introduction:
Consider the following unity feedback system:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
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:
KP + KI + KDs =
KDs2 + KPs
+ KI s s
KP = Proportional gain
KI = Integral gain
KD = Derivative gain
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 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 = KPe(t) + KI e(t)dt + KD 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 integral again. The process goes
on and on.
Example Problem:
M x +bx +kx=F
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Ms2X(s)+bsX(s)+kX(s) = F(s)
The transfer function between the displacement X(s) and the input F(s) then becomes
X(s) 1
= 2 bs+ k F(s) Ms +
F(s) s +10s + 20
The goal of this problem is to show you how each of Kp, Ki and Kd contributes to obtain
Open-loop step response: Let’s first view the open-loop step response.
0.045
0.04
0.035
0.03
0.025
0.02
0.015
0.01
0.005
0
0 0.5 1 1.5 2 2.5
Time (seconds)
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.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Proportional Control:
The closed-loop transfer function of the above system with a proportional controller is:
X (s) KP
F (s) = 2
10 s + ( 20 + K P ) s+
step(sys_cl,t)
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (seconds)
Note: The MATLAB function called feedback was used to obtain a closed-loop transfer
function directly from the open-loop transfer function. The above plot shows that the
proportional controller reduced both the rise time and the steady-state error, increases the
overshoot, and decreased the settling time by small amount.
Proportional-Derivative control:
The closed-loop transfer function of the given system with a PD controller is:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
feedback(contr*plant, 1); t =
0:0.01:2; step(sys_cl, t)
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (seconds)
This plot shows that the derivative controller reduced both the overshoot and the settling time,
and had a small effect on the rise time and the steady-state error.
Proportional-Integral control:
Before going into a PID control, let’s take a look at a PI control. For the given system, the
closed-loop transfer function with a PI control is:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
X(s) = 3 10s2K(20PS++KKPI )s + KI )
F(s) s+
0:0.01:2; step(sys_cl,t)
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (seconds)
We have reduced the proportional gain (Kp) because the integral controller also reduces the
rise time and increases the overshoot as the proportional controller does (double effect). The
above response shows that the integral controller eliminated the steady-state error.
Proportional-Integral-Derivative control:
The closed loop transfer function of the given system with a PID controller is:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
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;
feedback(contr*plant, 1); t =
0:0.01:2; step(sys_cl,t)
Step Response
1
0.9
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (seconds)
Now, we have obtained a closed-loop system with no overshoot, fast rise time, and no
steadystate error.
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 (K I) will have the effect if
eliminating the steady state error, but it may make the transient response worse. A derivative
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
control (KD) will have the effect of increasing the stability of the system, reducing the overshoot
and improving the transients response.
Effect of each controller KP, KI and KD on the closed-loop system are summarized below
Note that these corrections may not be accurate, because K P, KI and KD are dependent of each
other. In fact, changing one of these variables can change the effect of the other two. For this
reason the table should only be used as a reference when you are determining the values for
KP, KI and KD.
Exercise 1:
400
GP(s) =
s(s + 48.5)
Based on your results in parts b) and c) above what do you conclude as a suitable PID controller
for this process and give your justification.
Exercise 2:
******
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Objectives: Study the root locus analysis using MATLAB commands and to find parameter
values associated with poles within the target region.
Introduction:
A root loci is simply a plot of the s zero values and the s poles on a graph with real and
imaginary ordinates. The root locus is a curve of the location of the poles of a transfer function
as some parameter (generally the gain K) is varied. The locus of the characteristic equation of
the closed loop system as the gain varies from zero to infinity gives the name of the method.
This method is very powerful graphical technique for investigating the effects of the variation
if system parameters on the locations of the closed loop poles. Root loci are completed to select
the best parameter value for stability.
Consider the System shown in Fig Below. The goal is to use MATLAB to draw a root locus
diagram for the parameter K, given the parameter m = 4.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
s3 −s =0
The MATLAB commands that produce the root locus diagram are:
>> rlocus(sys)
>> axis(‘equal’)
4
Imaginary Axis (seconds -1)
-2
-4
-6
Note that MATLAB does not show the direction of the movement of the poles. It is understood
that the movement is from the poles to the zeros of P(s). The “axis” command ensures that the
diagram is shown in its true shape.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
The damping ratios and settling times of the poles are determined by their location on the root
locus diagram. To ensure a settling time less than Ts, the real parts of all the poles of the system
must be to the left of 4/Ts. The damping ratio of each of the complex poles is determined by
drawing a vector from the origin to the location of the pole and measuring the angle θ between
this vector and the negative real axis. The damping ratio is calculated as ζ = cos(θ). For
example, poles that lies below the θ=45˚ line have damping ratio ζ > 0.7.
To find parameter values associated with poles within the target region, use the “rlocfind”
command in MATLAB. After executing the “rlocfind” command, click on a desirable pole
location on one of the branches of the root locus in the root locus plot window. MATLAB
automatically picks the point on the branch that is closest to your selection.
>>grid
Selected point = -
6.8389 + 4.4828i k =
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
15.5301 poles
-6.8342 + 4.4752i
-6.8342 - 4.4752i
-1.8617
Note that MATLAB places a “+” at the locations of the chosen poles.
Exercise1:
Using the rlocus function, obtain the root locus for the following transfer functions of the
system shown in fig. below. When 0 < K< ∞:
10
(a) G ( s ) = ,
s+
3 2
14 s + 43s + 30
s2 +s+1
(c) G(s) = s(s2 +5s+10)
Exercise 2:
A unity feedback system has the loop transfer function
s2 −2s+2
KG(s) =K s(s2 +3s+2)
Develop an m-file to plot the root locus and show with the rlocfind function that the maximum
value of K for a stable system is K=0.79.
Exercise 3:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
K(s+1)(s+2)
s(s+4)
******
Objectives: Study the root locus analysis using MATLAB commands and to find parameter
values associated with poles within the target region.
Introduction:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
A Bode diagram consists of two graphs: One is a plot of the logarithm of the magnitude of a
sinusoidal transfer function; the other is a plot of the phase angle; both are plotted against the
frequency on a logarithmic scale. Bode analysis plays a very important role in finding the
stability of the system. The bode analysis is an improvement of Nyquist analysis. The main
advantage of using the Bode diagram is that multiplication of magnitudes can be converted into
addition. Furthermore, a simple method for sketching an approximate log-magnitude curve is
available.
A Bode diagram is obtained with the bode function. The bode diagram is automatically
generated of the bode function invoked without left-hand arguments. Otherwise, the magnitude
and phase characteristics are placed in the workspace through the variables mag and phase. A
bode diagram is obtained with the plot or semilogx function using mag, phase, and ω. The
vector ω contains the values of the frequency in rad/s at which the bode diagram will be
calculated. If ω is not specified, the bode function will automatically choose the frequency
values by placing more points in regions where the frequency response is changing quickly. If
the frequencies are specified explicitly, it is desirable to generate the vector ω using the
logspace function.
Note that the experimental determination of a transfer function can be made simple if frequency
response data are presented in the form of Bode diagram.
20000
Example: Consider the following transfer function TF =
s + 20000
The MATLAB commands that produce the bode diagram are: Bode Diagram
>> s=tf(‘s’);
>> H = (20000/(s+20000));
>> bode(H)
>> grid on
Another way for plotting bode diagram is without using control system toolbox.
Expand the numerator and denominator of your transfer function by multiplying out the terms.
Then make an array of the coefficients of the numerator and denominator of the transfer
function in descending order of powers. Example: if numerator is As^2 + Bs + C, array will be
num = [A B C]. Note that the arrays for the numerator and denominator must be equal in length.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
numTF = [0 20000];
denTF = [1 20000]; w
= 0:10:10e4;
subplot(2,1,1)
semilogx(w,20*log10(y1)) grid
on ylabel(‘Magnitude (dB)’)
title(‘Bode diagram’)
subplot(2,1,2)
semilogx(w,y2*(180/pi))
grid on
ylabel(‘Phase(deg)’)
xlabel(‘Frequency(Rad/s)’)
Exercise 1:
For the following transfer functions, sketch the bode plot using bode function:
(a) G(s) =
+10
(b) G(s) = s
(s + 2)(s + 40)
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
1
(c) G(s)= s2 + 2s+50
s−7
(d) G(s) = (s+ 2)(s2 +12s+50)
Exercise 2:
Determine the closed-loop system bandwidth by using the bode function to obtain the Bode
plot, and estimate the bandwidth from the plot. Label the plot with bandwidth.
Exercise 3:
Given , Gc (s) =
,
12
Gp (s) =
s(s +1)
Using Matlab
(a) Obtain Bode plot of GC(s).
(b) Obtain Bode plot of GP(s).
(c) Obtain Bode plot of GC(s).GP(s).
*******
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Introduction:
Nyquist plots, just like Bode diagrams, are commonly used in the frequency response
representation of linear, time-invariant, feedback control systems, Nyquist plots are polar plots,
while Bode diagrams are rectangular plots. One plot or the other may be more convenient for
a particular operation, but a given operation can always be carried out in either plot.
The MATLAB command nyquist computes the frequency response for continuous time, linear,
time-invariant systems. When invoked without left-hand arguments, Nyquist produces a
Nyquist plot on the screen.
The command nyquist(num, den) draws the Nyquist plot of the transfer function num(s)
G(s) = , where num and den contain the polynomial coefficients in descending den(s)
powers of s, other commonly used nyquist commands are nyquist(num,
den, w)
nyquist(A, B, C, D) nyquist(A,
B, C, D, w) nyquist(A, B, C,
D, iu, w) nyquist(sys)
The command involving the user-specified frequency vector w, such as nyquist(num, den, w),
calculates the frequency response at the specified points in radians per second.
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.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Note that re and im have as many columns as outputs and one row for each element in w.
Example: Consider the following transfer function
k(s +2)
G(s) =
(s +1)(s −3)
0.1
den)
0.05
Imaginary Axis
h= 0
s + 2 ------------- s^2 - 2 s -
-0.05
3
-0.1
>> nyquist(h)
-0.15
-0.2
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4
a) G(s) =
b) G(s) =
c) G(s) =
Exercise 2:
Consider the system represented in state variable form
X = 01 −110 X
+ 220 u − y
= 10 0 X + 0 u
Using the nyquist function, obtain the polar plot.
******
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Applications:
One of the significant features of the stepping motor is its ability to hold a position with
welldefined accuracy for any length of time. This makes the stepping motor a true digital
actuator without the complication of tachometer, error potentiometer, amplifier and other
stabilizing networks. Some of the common applications of stepper motor is:
A stepper motor can also be used as an integrator by feeding a continuously variable signal to
an analogue to digital (A/D) converter giving a pulse frequency proportional to the input signal.
A stepper motor when supplied with these pulses will move the load attached to its shaft
through a distance proportional to the time integral of the signal.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
Stepper motors are available in 3 lead, 4 lead and 5 leads type, 5 lead types are also called
“bifilar type”. These are available in standard voltage ratings of 6 V, 12 V and 24 Vdc. For a
phase switched DC stepping these can be connected to provide either 200 steps per revolution.
There are basically three types of stepper motor in use. They are permanent magnet, variable
reluctance and hybrid type. Each type may vary widely in constructional details but all have a
cylindrical stator with salient poles or teeth, each of which carries a coil to which pulses are
successively applied.
CIRCUIT DIAGRAM:
PROCEDURE:
1. Make connections as shown in the circuit diagram.
2. Plug in stepper motor to the input.
3. Keep the coarse switch in the clock adj. block to low mode; direction switch in
clockwise and fine adjustment potentiometer P1 in clk adj block in the minimum
positon i.e. fully anti-clockwise.
4. Connect the require supply to the unit and switch on the unit.
5. Observe and record the sequence of glowing LDE’s. Observe the advancing steps of
motor.
6. Observe the clock frequency at the clock terminal of IC 4013 on CRO.
7. Observe the control action of the coarse switch and fine adjust potentiometer P1 in
clock adj .block, and direction selector switch.
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat
2150909: Control System Engineering (Laboratory)
OBSERVATION TABLE:
Clock wise Direction
Step A1 B1 A2 B2
1
2
3
4
5
Step A1 B1 A2 B2
1
2
3
4
5
CONCLUSION:
Electrical Engineering Department, Dr. S. & S. S. Ghandhy Government Engineering College, Surat