0% found this document useful (0 votes)
192 views34 pages

EEE3001 Software Manual

This document describes modeling a DC motor using Simulink. It involves deriving the transfer function of an armature controlled DC motor from its differential equation, drawing the block diagram, and then modeling it in Simulink. Key steps include writing the differential equation, deriving the transfer function, drawing the block diagram, opening Simulink, and applying an input to verify the output. Stability analysis of linear systems is also discussed, noting that a system is stable if its impulse response is bounded and decreases to zero for bounded inputs, or if the roots of its characteristic equation all have negative real parts.

Uploaded by

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

EEE3001 Software Manual

This document describes modeling a DC motor using Simulink. It involves deriving the transfer function of an armature controlled DC motor from its differential equation, drawing the block diagram, and then modeling it in Simulink. Key steps include writing the differential equation, deriving the transfer function, drawing the block diagram, opening Simulink, and applying an input to verify the output. Stability analysis of linear systems is also discussed, noting that a system is stable if its impulse response is bounded and decreases to zero for bounded inputs, or if the roots of its characteristic equation all have negative real parts.

Uploaded by

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

BLOCK DIAGRAM REDUCTION

EXPT. NO:
DATE:
AIM:
To reduce the given Block diagram to transfer function model using M-file Editor in MATLAB.

APPARATUS REQUIRED:

Personal Computer with MATLAB.

THEORY:

It is a representation of the control system giving the inter-relation between the transfer function
of various components. The block diagram is obtained after obtaining the differential equation & Transfer
function of all components of a control system. The arrow head pointing towards the block indicates the
i/p & pointing away from the block indicates the o/p. After obtaining the block diagram for each & every
component, all blocks are combined to obtain a complete representation. It is then reduced to a simple
form with the help of block diagram algebra.

Blocks connected in Series


Let the process represented by the transfer function G(s) be
S 1
G(s) = .and let the controller represented by the transfer function
500 S 2
S 1
Gc(s) be Gc(s) = .Compute the series transfer function Gc(s)G(s)
S 2

S 1 S 1
G(s) = Gc(s) =
R(s) 500 S 2 S 2 Y(s)

»numg=[1 1]; deng = [500 0 0];


»numh=[1 1]; denh = [1 2]
»[num, den]= series(numg,deng,numh,denh);
»printsys(num,den)

The output of this program is


num/den =

s^2 + 2 s + 1
------------------
500 s^3 + 1000 s^2
Blocks connected in parallel
A simple open – loop control system can be obtained by interconnecting a plant and a controller
in parallel.
1
G(s) =
S 2
+
R(s) + Y(s)
S 3
Gc(s) =
S  10

The transfer function in this case is Gc(s)+G(s).Let the process represented by the transfer
1
function G(s) be G(s) = .and let the controller represented by the transfer function Gc(s) be
S 2
S 3
Gc(s) = . Compute the combined transfer function of the blocks.
S  10

»num1 = 1;
»den1 =[1 2];
»num2 =[1 3];
»den2 =[1 10];
» [nump, denp] = parallel(num1, den1, num2, den2);
»printsys(nump, denp);

Execution of the above yields the result

num/den =
s^2 + 6s +16
s^2 + 12s + 20

Feedback function

This function reduces the process of computing the closed loop transfer function for single or
multiple loops.

R(s) Ys)
G(s)

H(s)

Y ( S ) num num1 num2


T(s) = = ; G(s)= ;H(s) =
G ( S ) den den1 den2
+1 – positive feed back
–1 – negative feedback

command : [num, den] = feedback(num1, den1, num2, den2, sign)

Single loop

Example :1
R(s) S 1 Y(s)
G(s) =
500 S 2

S 1
H(s) =
S 2

» numg = [1 1] ; deng = [500 0 0];


» numh = [1 1] ; denh = [ 1 2 ];
» [num, den] = feedback(numg,deng,numh,denh,-1);
» printsys(num, den)

The output of the program will be

Transfer function
s^2 + 3 s + 2
----------------------------
500 s^3 + 1001 s^2 + 2 s + 1

PROCEDURE:

1. Enter the command window of the MATLAB.


2. Create a new M – file by selecting File – New – M – File.
3. Type and save the program.
4. Execute the program by either pressing F5 or Debug – Run.
5. View the results.
6. Analysis the stability of the system.

For reducing very complex systems, blkbuild and connect commands are used as
illustrated below;
BLKBUILD Builds a block-diagonal state-space structure from a block diagram of
transfer functions and state models. This is a SCRIPT FILE.
Each block is numbered as shown. In the first seven lines of the program, the above
blocks are completely defined. The numbers of blocks are then defined n blocks. The command
blkbuild uses the variable nblocks to begin building the system. It converts all the transfer
functions to state space models and assembles them into one large block state space model called
a, b, c, d.
The next step is to create the matrix q that describes the interconnections of various
blocks. Each row corresponds to a block and the first element in the row is the block number and
the remaining elements indicate the blocks whose outputs are connected to the input of the
current block.
After defining q, the block 1 that receives the system input and block 4 that produces the system
output are defined by the variables „input‟ and „output‟. The connect command makes the
connections and reduces the system into a single state space model which is then converted back
into transfer function.

INPUTS:
n is the number of blocks in the diagram.
ni and di are the numerator and denominator polynomials for the ith block if it is a
transfer function.
ai,bi,ci,di are the state matrices for the ith block if it is a state model.

OUTPUTS:

a,b,c,d is the resulting state space structure. The matrices are built up by progressive
APPENDs of the state

PROBLEM (i)

R(S) +
+ C(S)
G1(S) + G3 (S) + G4(S)
G2(S)

1 - 22 - 3 3 - 44

H2(S) H3(S)

66 7
H1(S)

Let G1(s) = 1 G2(s) = 1/(s+1),

G3(s) = 1/(s+2) G4(s) = 1/(s+3),

H1(s) = 4 H2(s) = 8, H3(s) = 12,


Solution:

%TF OF COMPLETE BLOCK DIAGRAM 1


»n1=1;d1=1;
»n2=1;d2=[1 1];
»n3=1;d3=[1 2];
»n4=1;d4=[1 3];
»n5=4;d5=1;
»n6=8;d6=1;
»n7=12;d7=1;
»nblocks=7;
»blkbuild
»q = [ 1 0 0 0 0
2 1 -5 0 0
3 2 -6 0 0
4 2 -6 3 -7
5 3 0 0 0
6 3 0 0 0
7 4 0 0 0 ]
»iu = 1;
»iy = 4;
» [A,B,C,D]=connect(a,b,c,d,q,iu,iy);
» sys=ss(A,B,C,D);
»sys=tf(sys)

System Response:
State model [a,b,c,d] of the block diagrams has 7 inputs and 7 outputs

num/den =

1s + 3 _____ .
s^3 + 26 s^2 + 179s + 210

Inference:

Result:

The Block diagram to transfer function reduction of the given model has been done using
MATLAB.
Exp No:
Date:

MODELING OF DC MOTOR USING SIMULINK

AIM: To model an armature controlled DC motor using Simulink.

APPARATUS REQUIRED:

Personal Computer with MATLAB.

THEORY:

It is a representation of the control system giving the inter-relation between the transfer function
of various components. The block diagram is obtained after obtaining the differential equation & Transfer
function of all components of a control system. The arrow head pointing towards the block indicates the
i/p & pointing away from the block indicates the o/p. After obtaining the block diagram for each & every
component, all blocks are combined to obtain a complete representation. It is then reduced to a simple
form with the help of block diagram algebra.

Procedure:
i) Write the differential equation of Armature controlled DC Motor
ii) Derive the Transfer Function
iii) Draw the block diagram of Armature controlled DC Motor
iv) Model the block diagram in Simulink
v) Apply input and very the output

(Finish the first 3 steps as pre-lab work before coming to the Lab))
Exp No : STABILITY ANALYSIS OF LINEAR SYSTEMS
Date :

AIM:

To obtain the various plots and check for stability of the system with open loop transfer function,

APPARATUS REQUIRED:

A PC with MATLAB Software

THEORY:

A Linear Time-Invariant Systems is stable if the following two notions of system stability are
satisfied
 When the system is excited by Bounded input, the output is also a Bounded
output.
 In the absence of the input, the output tends towards zero, irrespective of the
initial conditions.

The following observations are general considerations regarding system stability,

o If all the roots of the characteristic equation have negative real parts, then the
impulse response is bounded and eventually decreases to zero, then system is
stable.
o If any root of the characteristic equation has a positive real part, then system is
unstable.
o If the characteristic equation has repeated roots on the jω-axis, then system is
unstable.
o If one are more non-repeated roots of the characteristic equation on the jω-axis,
then system is unstable.

a. Using BODE PLOT :

Consider a Single-Input Single-Output system with transfer function

C(s) b0 sm + b1 sm-1 + ……+ bm


=
R(s) a0 sn + a1sn-1 + ……+an
Where m < n.

 Rule 1 A system is stable if the phase lag is less than 180˚ at the frequency for
which the gain is unity (one).
 Rule 2 A system is stable if the gain is less than one (unity) at the frequency for
which the phase lag is 180˚.

The application of these rules to an actual process requires evaluation of the gain and phase shift
of the system for all frequencies to see if rules 1 and 2 are satisfied. This is obtained by plotting
the gain and phase versus frequency. This plot is called BODE PLOT. The gain obtained here is
open loop gain. The exact terminology is in terms of a Gain Margin and Phase Margin from
the limiting values quoted.

 If the phase lag is less than 140˚ at the unity gain frequency, the system is stable.
This then, is a 40˚ Phase Margin from the limiting values of 180˚.
 If the gain is 5dB below unity (or a gain of about 0.56) when the phase lag is
180˚, the system is stable. This is 5dB Gain Margin.

PROCEDURE:

Step 1: Write a program to obtain the Bode plot for the given system.
Step 2: Access the stability of given system using the plot obtained.

PROGRAM

%BODE PLOT OF THE SYSTEM


%Enter the numerator and denominator of the transfer function
num=[ ];
den=[ ];
sys=tf(num,den)
%Specify the frequency range and enter the command
w=logspace(-2,4,1000);
bode(sys,w)
xlabel('Frequency')
ylabel( ' Phase angle in degrees Magnitude of G(s) in decibels')
title('Bode Plot of the system ')
%To determine the Gain Margin, Phase Margin, Gain crossover frequency and
%Phase cross over frequency
margin(sys)
[ Gm, Pm, Wpc, Wgc ]= margin (sys)
MANUAL CALCULATIONS:

OUTPUT (from manual calculation):

OUTPUT (from program):

RESULT:

The Bode plot is drawn for the given transfer function using MATLAB and verified manually.
From the plot obtained, the system is found to be ______________.

b. Using Root Locus

AIM:

To obtain the Root locus plot and to verify the stability of the system with transfer function,
G(s) =

APPARATUS REQUIRED:

A PC with MATLAB Software

THEORY:

ROOT LOCUS PLOT:

The characteristic of the transient response of a closed-loop system is related to the location of
the closed loop poles. If the system has a variable loop gain, then the location of the closed-loop
poles depend on the value of the loop gain chosen. A simple technique known as “Root Locus
Technique” used for studying linear control systems in the investigation of the trajectories of the
roots of the characteristic equation.
This technique provides a graphical method of plotting the locus of the roots in the s-plane as a
given system parameter is varied over the complete range of values (may be from zero to
infinity). The roots corresponding to a particular value of the system parameter can then be
located on the locus or the value of the parameter for a desired root location can be determined
form the locus. The root locus is a powerful technique as it brings into focus the complete
dynamic response of the system. The root locus also provides a measure of sensitivity of roots to
the variation in the parameter being considered. This technique is applicable to both single as
well as multiple-loop systems.

PROCEDURE:

1. Write a program to obtain the root locus plot for the given system.
2. Access the stability of given system using the plot obtained.

PROGRAM:

%ROOT LOCUS OF THE SYSTEM%


num=[ ]
den=[ ]
sys=tf(num,den)
rlocus(sys)
v=[-10,10,-8,8];
axis(v)
xlabel('Real Axis')
ylabel('Imaginary Axis')
title('Root Locus of the system')
title('Root Locus Plot of the system ')

MANUAL CALCULATIONS:

OUTPUT (from manual calculation)

OUTPUT (from program):


RESULT:

The Root locus plot is drawn for the given transfer function, G(s)= ___________________
using MATLAB and the range of gain K for stability is______________.

c. USING NYQUIST PLOT

AIM:

To obtain the Nyquist plot and check the stability of the system using Nyquist Stability Criterion
for the given unity feedback system with transfer function

G(s)H(s) =

APPARATUS REQUIRED

A PC with MATLAB Software

THEORY:

NYQUIST STABILITY CRITERION:

POLAR PLOTS OR NYQUIST PLOTS:


The sinusoidal transfer function G(jω) is a complex function is given by
G(jω) = Re[ G(jω)] + j Im[G(jω)] or
G(jω) = │G(jω) │ ∟G(jω) = M ∟Φ -----------(1)

From equation (1), it is seen that G(jω) may be represented as a phasor of magnitude M and
phase angle Φ. As the input frequency varies from 0 to ∞, the magnitude M and phase angle Φ
changes and hence the tip of the phasor G(jω) traces a locus in the complex plane. The locus
thus obtained is known as POLAR PLOT. The major advantage of the polar plot lies in
stability study of systems. Nyquist related the stability of a system to the form of these plots.
Polar plots are referred as NYQUIST PLOTS.

PROCEDURE:

1. Write a program to obtain the Nyquist plot for the given system.
2. Access the stability of given system using the plot obtained.

PROGRAM

%NYQUIST PLOT
%Enter the numerator and denominator of the transfer function
num=[ ]
den=[ ]
sys=tf(num,den)

%Specify the frequency range and enter the command


nyquist(sys)
v=[ ]
axis(v)
xlabel('Real Axis');
ylabel('Imaginary Axis');
title('Nyquist Plot of the system „)

MANUAL CALCULATIONS:

OUTPUT ( from Manual calculation)

OUTPUT (from program)

RESULT:

The Nyquist plot is drawn for the given transfer function, G(s) = ______________________
using MATLAB and the system is found to be ______________________.
Exp No : TIME RESPONSE OF LINEAR SYSTEMS
Date :

AIM:

To obtain the various plots and study the response of the given system with various input given.

APPARATUS REQUIRED:

A PC with MATLAB Software

THEORY:

The order of a system is defined as being the highest power of derivative in the differential
equation, or being the highest power of s in the denominator of the transfer function. A first-
order system only has s to the power one in the denominator, while a second-order system has
the highest power of s in the denominator being two.

Types of the input functions (or test input signals) commonly used are:
• Impulse function:
• Step function: In the time domain, u(t) = c. In the s domain, U(s) = c/s.
• Ramp function: In the time domain, u(t) = ct. In the s domain, U(s) = c/s2
Sinusoidal function
where c is a constant in all the above.
With these test signals, mathematical and experimental analyses of control systems can be
carried out easily since the signals are very simple functions of time.
This of these typical signals to use for analyzing system characteristics may be determined by the
form of the input that the system will be subjected to most frequently under normal operation. If
the inputs to a control system are gradually changing functions of time, then a ramp function of
time may be a good test signal. Similarly, if a system is subjected to sudden disturbances, a step
function of time may be a good test signal, and for a system subjected to a shock input, a pulse or
an impulse function may be best.

PROCEDURE:

1. Write a program to obtain the various plot for the given system.
2. From the given system find the values for rise , peak ,settling times and % overshoot .

%Compute step response for a second-order system for a different Zeta values
t=[0:0.1:10];num=[1];
zeta1=0.1;den1=[1 2*zeta1 1]; sys1=tf(num,den1);
zeta2=0.25; den2=[1 2*zeta2 1 ]; sys2=tf(num,den2);
zeta3=0.5; den3=[1 2*zeta3 1]; sys3=tf(num,den3);
zeta4=1.0; den4=[1 2*zeta4 1]; sys4=tf(num,den4);
[y1 ,T1]=step(sys1 ,t);
[y2,T2]=step(sys2,t);
[y3,T3]=step(sys3,t);
[y4,T4]=step(sys4,t);
plot(t,y1 ,t,y2,t,y3,t,y4)
xlabel(' \omega _nt');
ylabel('y(t)/omega_n');
title('\zeta = 0.1, 0.25, 0.5, 1.0');
grid

%Compute impulse response for a second-order system


t=[0:0.1:10];num=[5];
zeta1=0.2;den1=[1 2*zeta1 1]; sys1=tf(num,den1);
zeta2=0.4; den2=[1 2*zeta2 1 ]; sys2=tf(num,den2);
zeta3=0.6; den3=[1 2*zeta3 1]; sys3=tf(num,den3);
zeta4=1.0; den4=[1 2*zeta4 1]; sys4=tf(num,den4);
[y1 ,T1]=impulse(sys1 ,t);
[y2,T2]=impulse(sys2,t);
[y3,T3]=impulse(sys3,t);
[y4,T4]=impulse(sys4,t);
plot(t,y1 ,t,y2,t,y3,t,y4)
xlabel(' \omega _nt'), ylabel('y(t)/omega_n')
title('\zeta = 0.1, 0.25, 0.5, 1.0'), grid

n1=[1 5]
d1=[5 1 4 3]
g=tf(n1,d1);
t = 0: 0.005 :5;
r = 2 - 2*t+ t.^2;
c =lsim(n1,d1,r,t);%compute response using lsim function
plot(t,r,'*k',t,c,'-k');
grid;
xlabel('time,t in sec');
ylabel('Input,r(t) and Output,c(t)');
text(0.25,2.65,'r(t)')
text(0.25,0.6,'c(t)')
%computing the Time domain specifications
num = [6.3223 18 12.811];
den = [1 6 11.3223 18 12.811];
t = 0:0.02:20;
[y,x,t] = step(num,den,t);
plot(t,y)
grid
title('Unit-Step Response')
xlabel('t (sec)')
ylabel('Output y(t)')
r1 = 1; while y(r1) < 0.1, r1 = r1+1; end;
r2 = 1; while y(r2) < 0.9, r2 = r2+1; end;
rise_time = (r2-r1)*0.02
[ymax,tp] = max(y);
peak_time = (tp-1)*0.02
max_overshoot = ymax-1
s = 1001; while y(s) > 0.98 & y(s) < 1.02; s = s-1; end;
settling_time = (s-1)*0.02

%Computing the Time domain specifications using formula


num = 220;
den = [2 18 220];
T = tf(num, den)
omegan = sqrt (den(3))
zeta = den(2) / (2*omegan)
Ts = 4/ (zeta*omegan)
Tp = pi/ (omegan*sqrt(1-zeta^2))
Tr = (1.76*zeta^3-.417*zeta^2 + 1.039*zeta + 1)/omegan
percent = exp(-zeta*pi/ sqrt(1-zeta^2))*100
step(T)
title('a')

RESULT:
Expt. No. Date:

SIMULATION OF FIRST ORDER SYSTEMS

AIM:

To digitally simulate the time response characteristics of a linear system without


non- linearities and to verify it manually.

APPARATUS REQUIRED:

A PC with MATLAB package

THEORY:

The time response characteristics of control systems are specified in terms of time
domain specifications. Systems with energy storage elements cannot respond instantaneously
and will exhibit transient responses, whenever they are subjected to inputs or disturbances.
The desired performance characteristics of a system of any order may be specified in
terms of transient response to a unit step input signal. The transient response characteristics of a
control system to a unit step input is specified in terms of the following time domain
specifications
 Delay time td
 Rise time tr
 Peak time tp
 Maximum peak overshoot Mp
 Settling time ts

STUDY OF BASIC MATLAB COMMANDS:

The name MATLAB stands for MATRIX LABORATORY. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of
the art in software for matrix computation. It has evolved over a period of years with input from
many users. In university environments, it is the standard instructional tool for introductory and
advanced courses in MATHEMATICS, ENGINEERING, AND SCIENCE. In industry,
MATLAB is the tool of choice for high-productivity research, development, and analysis.

MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming in an easy-to-use environment where problems and solutions are
expressed in familiar mathematical notation. Typical uses include,

 Math and computation


 Algorithm development
 Data acquisition Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including graphical user interface building

It is an interactive system whose basic data element is an array that does not require
dimensioning. This allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program in
a scalar non-interactive language such as C or Fortran. It also features a family of add-on
application-specific solutions called toolboxes. Very important to most users of MATLAB,
toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive
collections of MATLAB functions (M-files) that extend the MATLAB environment to solve
particular classes of problems. Areas in which toolboxes are available include SIGNAL
PROCESSING, CONTROL SYSTEMS, NEURAL NETWORKS, FUZZY LOGIC,
WAVELETS, SIMULATION, AND MANY OTHERS.

Some practical examples of first order systems are RL and RC circuits.

PROCEDURE:

1. Derive the transfer function of a RL series circuit.


2. Assume R= 1 Ohms L = 0. 1 H. Find the step response theoretically and plot it on a
graph sheet.
3. To build a SIMULINK model to obtain step response / sine response of a first order
system, the following procedure is followed:
1. In MATLAB software open a new model in SIMULINK library browser.
2. From the continuous block in the library drag the transfer function block.
3. From the source block in the library drag the step input/ sine input.
4. From the sink block in the library drag the scope.
5. From the math operations block in the library drag the summing point.
6. Connect all to form a system and give unity feedback to the system.
7. For changing the parameters of the blocks connected double click the respective
block.
8. Start simulation and observe the results in scope. (Use a mux from the signal
routing block to view more than one graph in the scope)
9. Compare the simulated and theoretical results.

BLOCK DIAGRAM:

Step response of a first order system:


Sine response of a first order system:

2. MATLAB (m-file) program to obtain the step response and impulse response

% MATLAB program to find the step response

num=[ ];
den=[ ];
sys = tf (num,den);
step (sys);
grid

OUTPUT: (Paste the graph obtained from PC)


% MATLAB program to find the impulse response

num=[ ];
den=[ ];
sys = tf (num,den);
impulse (sys);
grid

OUTPUT: (Paste the graph obtained from PC)

CALCULATIONS:

Unit step response of the given RL series circuit:

Unit Impulse response of the given RLC series circuit:

RESULT:

The time response characteristics of a first order system is simulated digitally and verified
manually.

SIMULATION OF SECOND ORDER SYSTEMS

AIM:

To digitally simulate the time response characteristics of a second order system and verify
manually.

APPARATUS REQUIRED

A PC with MATLAB Software


THEORY

The time characteristics of control systems are specified in terms of time domain specifications.
Systems with energy storage elements cannot respond instantaneously and will exhibit transient
responses, whenever they are subjected to inputs or disturbances. The desired performance
characteristics of a system of any order may be specified in terms of transient response to a unit
step input signal. The transient response characteristics of a control system to a unit step input is
specified in terms of the following time domain specifications:
 Delay time td
 Rise time tr
 Peak time tp
 Maximum overshoot Mp
 Settling time ts

PROCEDURE:

1. Derive the transfer function of a RLC series circuit.


2. Assume R= 1 Ohms, L = 0. 1 H and C = 1 micro Farad. Find the step response
theoretically and plot it on a graph sheet.
3. To build a SIMULINK model to obtain step response / sine response of a second order
system, the following procedure is followed:
1. In MATLAB software open a new model in SIMULINK library browser.
2. From the continuous block in the library drag the transfer function block.
3. From the source block in the library drag the step input/ sine input.
4. From the sink block in the library drag the scope.
5. From the math operations block in the library drag the summing point.
6. Connect all to form a system and give unity feedback to the system.
7. For changing the parameters of the blocks connected double click the respective
block.
8. Start simulation and observe the results in scope. (Use a mux from the signal
routing block to view more than one graph in the scope)
9. From the step response obtained note down the rise time, peak time, peak
overshoot and settling time.
10. Compare the simulated and theoretical results.

BLOCK DIAGRAM:

Step response of a second order system:


Sine response of a second order system:

2. MATLAB program to obtain the step response and impulse response of second order
system.

% MATLAB program to find the step response


num=[ ];
den=[ ];
sys = tf (num,den);
step (sys);

OUTPUT: (Paste the graph obtained from PC)

% MATLAB program to find the impulse response

num=[ ];
den=[ ];
sys = tf (num,den);
impulse (sys);

OUTPUT: (Paste the graph obtained from PC)

CALCULATIONS:

Unit step response of the given RLC series circuit:

Unit impulse response of the given RLC series circuit:

RESULT:

The time response characteristics of the given second order system is simulated digitally and
verified manually.
Exp No Date:
Implementation of PID Controller

Objective: Study the three term (PID) controller and its effects on the feedback loop response.
Investigate the characteristics of the each of proportional (P), the integral (I), and the derivative (D)
controls, and how to use them to obtain a desired response.

APPARATUS REQUIRED

A PC with MATLAB Software

Theory :

Consider the following unity feedback system:

R e u
Plant
Controller
+ - Y

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
Gc (s)  K P   KDs
s (1)

The transfer function of a PID controller is found by taking the Laplace transform of Eq.(1).

(2)

= Proportional gain = Integral gain = Derivative gain

We can define a PID controller in MATLAB using the transfer function directly, for example:
Kp = 1;
Ki = 1;
Kd = 1;

s = tf('s');
C = Kp + Ki/s + Kd*s
C =

s^2 + s + 1
-----------
s

Continuous-time transfer function.

Alternatively, we may use MATLAB's PID controller object to generate an equivalent


continuous-time controller as follows:

C = pid(Kp,Ki,Kd)
C =

1
Kp + Ki * --- + Kd * s
s

with Kp = 1, Ki = 1, Kd = 1

Continuous-time PID controller in parallel form.

convert the PID object to a transfer function to see that it yields the same result as above:

tf(C)
ans =

s^2 + s + 1
-----------
s

Continuous-time transfer function.


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(t )  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.

The Characteristics of P, I, and D Controllers

A proportional controller ( ) will have the effect of reducing the rise time and will reduce but
never eliminate the steady-state error. An integral control ( ) will have the effect of
eliminating the steady-state error for a constant or step input, but it may make the transient
response slower. A derivative control ( ) will have the effect of increasing the stability of the
system, reducing the overshoot, and improving the transient response.

The effects of each of controller parameters, , , and on a closed-loop system are


summarized in the table below.

CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR


Kp Decrease Increase Small Change Decrease
Ki Decrease Increase Increase Eliminate
Kd Small Change Decrease Decrease No Change

Note that these correlations may not be exactly accurate, because , , and are dependent
on 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
, and .

Example Problem:

Suppose we have a simple mass, spring, and damper problem.


The modeling equation of this system is

(3)

Taking the Laplace transform of the modeling equation, we get

(4)

The transfer function between the displacement and the input then becomes

(5)

Let

M = 1 kg
b = 10 N s/m
k = 20 N/m
F=1N

Plug these values into the above transfer function

(6)

We need to show how each of , and contributes to obtain


Fast rise time
Minimum overshoot
No steady-state error

Open-Loop Step Response

Do the open-loop step response. Create a new m-file and run the following code:

s = tf('s');
P = 1/(s^2 + 10*s + 20);
step(P)

The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to an
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. Then
now design a controller that will reduce the rise time, reduce the settling time, and eliminate the
steady-state error.

Proportional Control

From the table shown above, we see that the proportional controller (Kp) reduces the rise time,
increases the overshoot, and reduces the steady-state error.

The closed-loop transfer function of the above system with a proportional controller is:
(7)

Let the proportional gain ( ) equal 300 and change the m-file to the following:

Kp = 300;
C = pid(Kp)
T = feedback(C*P,1)

t = 0:0.01:2;
step(T,t)
C=

Kp = 300

P-only controller.

T=

300
----------------
s^2 + 10 s + 320

Continuous-time transfer function.


The above plot shows that the proportional controller reduced both the rise time and the steady-
state error, increased the overshoot, and decreased the settling time by small amount.

Proportional-Derivative Control

Now, let's take a look at a PD control. From the table shown above, we see that the derivative
controller (Kd) reduces both the overshoot and the settling time. The closed-loop transfer
function of the given system with a PD controller is:

(8)

Let equal 300 as before and let equal 10. Enter the following commands into an m-file and
run it in the MATLAB command window.

Kp = 300;
Kd = 10;
C = pid(Kp,0,Kd)
T = feedback(C*P,1)

t = 0:0.01:2;
step(T,t)
C=

Kp + Kd * s

with Kp = 300, Kd = 10

Continuous-time PD controller in parallel form.

T=

10 s + 300
----------------
s^2 + 20 s + 320

Continuous-time transfer function.

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. From the table, we see that an
integral controller (Ki) decreases the rise time, increases both the overshoot and the settling time,
and eliminates the steady-state error. For the given system, the closed-loop transfer function with
a PI control is:

(9)

Let's reduce the to 30, and let equal 70. Create a new m-file and enter the following
commands.

Kp = 30;
Ki = 70;
C = pid(Kp,Ki)
T = feedback(C*P,1)

t = 0:0.01:2;
step(T,t)
C=

1
Kp + Ki * ---
s

with Kp = 30, Ki = 70

Continuous-time PI controller in parallel form.

T=

30 s + 70
------------------------
s^3 + 10 s^2 + 50 s + 70

Continuous-time transfer function.


Run this m-file in the MATLAB command window, and you should get the following plot. We
have reduced the proportional gain (Kp) because the integral controller also reduces the rise time
and increases the overshoot as the proportional controller does (double effect). The above
response shows that the integral controller eliminated the steady-state error.

Proportional-Integral-Derivative Control

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

(10)

After several trial and error runs, the gains = 350, = 300, and = 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;
C = pid(Kp,Ki,Kd)
T = feedback(C*P,1);
t = 0:0.01:2;
step(T,t)
C=

1
Kp + Ki * --- + Kd * s
s

with Kp = 350, Ki = 300, Kd = 50

Continuous-time PID controller in parallel form.

Now, we have obtained a closed-loop system with no overshoot, fast rise time, and no steady-
state error.

General Tips for Designing a PID Controller

When you are designing a PID controller for a given system, follow the steps shown below to
obtain a desired response.

1. Obtain an open-loop response and determine what needs to be improved


2. Add a proportional control to improve the rise time
3. Add a derivative control to improve the overshoot
4. Add an integral control to eliminate the steady-state error
5. Adjust each of Kp, Ki, and Kd until you obtain a desired overall response. You can
always refer to the table shown in this "PID Tutorial" page to find out which controller
controls what characteristics.

You might also like