LAB MANUAL SIMULATION FINAL
LAB MANUAL SIMULATION FINAL
LAB MANUAL SIMULATION FINAL
SIMULATION LABORATORY
B. Tech.
The list of experiments given above is only suggestive. The Instructor may add
new experiments as per the requirement of the course.
Course Outcome:
After completion of this course, the students would be able to:
Understand modeling of complex systems with hands on experience for a
given process
Understand signal transmission through linear systems, convolution and
correlation of signals and sampling
EXPERIMENT: - 01
Objective: - To study the generating Lissajous pattern for different frequency
input.
Where, fV/fH=nH/nV
We can find the values of nH and nV from Lissajous figure. So, by substituting the
values of nH, nV and fH in Equation 1, we will get the value of fV, i.e.
the frequency of sinusoidal signal that is applied to the vertical deflection
plates of CRO.
Measurement of Phase Difference: -
A Lissajous figure is displayed on the screen when sinusoidal signals are applied
to both horizontal & vertical deflection plates of CRO. Hence, apply the sinusoidal
signals, which have same amplitude and frequency to both horizontal and vertical
deflection plates of CRO.
For few Lissajous figures based on their shape, we can directly tell the phase
difference between the two sinusoidal signals.
If the Lissajous figure is a straight line with an inclination of 45∘ with positive x-axis,
then the phase difference between the two sinusoidal signals will be 0∘0∘. That means,
there is no phase difference between those two sinusoidal signals.
If the Lissajous figure is a straight line with an inclination of 135∘ with positive x-axis,
then the phase difference between the two sinusoidal signals will be 180∘. That means,
those two sinusoidal signals are out of phase.
If the Lissajous figure is in circular shape, then the phase difference between the two
sinusoidal signals will be 90∘ or 270∘.
Flowchart: -
Define the frequency values in "w1"
and "w2".
w1=50;
w2=100;
p1=0;
p2=0;
t=0:0.01:2*pi;
x=sin(w1*t+p1);
y=sin(w2*t+p2);
subplot(2,2,2);
plot(x,y);
w1=50;
w2=50;
p1=pi/4;
p2=3*pi/4;
t=0:0.01:2*pi;
x=sin(w1*t+p1);
y=sin(w2*t+p2);
subplot (2,2,3);
plot (x, y);
Simulation model: -
Circuit Diagram :-A series RLC circuit with input applied at the resistor and
ground and output taken across the capacitor is drawn as:
Replacing C by 1/sC and L by sL the equivalent circuit can be drawn as:
Calculation :- Applying voltage division rule , the voltage across the capacitor is :
Flowchart:
Define 's' as variable of transfer
function using 'tf' function.
Simulink Diagram:- For step response of RLC circuit the simulink diagram is as
shown
sR
H ( s)
sR 1
A first-order low-pass filter is another simple passive filter circuit that allows low-frequency
signals to pass through while attenuating high-frequency signals. The transfer function of a
first-order low-pass filter can be represented as:
1
H ( s)
sR 1
3. R-L Circuit:
An R-L circuit consists of a resistor (R) and an inductor (L) connected in series. The response of
this circuit is governed by the time constant τ, which is the product of the resistance and
L
inductance (τ= ). The transfer function of an R-L circuit is:
R
1
H ( s)
sL R
Circuit Diagram :-
1. Passive High pass filter
sR
H ( s)
sR 1
1
H ( s)
sR 1
3. RL Circuit
1
H ( s)
sL R
Flow-Chart (For MATLAB code):-
MATLAB Code :-
R=2; C=3 ;L=1
S=tf('s');
Highpass= (R*C*S)/(1+R*C*S);
Lowpass = 1/(1+R*C*S);
RLckt=R/(R+S*L);
subplot(3,2,1);
step(Highpass);
subplot(3,2,2);
step(Highpass/S);
subplot(3,2,3);
step(Lowpass);
subplot(3,2,4);
step(Lowpass/S);
subplot(3,2,5);
step(RLckt);
subplot(3,2,6);
step(RLckt/S);
Simulink Diagram :-
Results :-
MATLAB Output :-
Scope Output for High pass(step and ramp input):-
Summing the forces in the free-body diagram of the cart in the horizontal direction,
you get the following equation of motion.
(1)
Summing the forces in the free-body diagram of the pendulum in the horizontal
direction, you get the following expression for the reaction force N.
(2)
If you substitute this equation into the first equation, you get one of the two
governing equations for this system.
(3)
To get the second equation of motion for this system, sum the forces perpendicular
to the pendulum. Solving the system along this axis greatly simplifies the
mathematics. You should get the following equation.
(4)
To get rid of the P and N terms in the equation above, sum the moments about the
centroid of the pendulum to get the following equation.
(5)
Combining these last two expressions, you get the second governing equation.
(6)
Since the analysis and control design techniques we will be employing in this
example apply only to linear systems, this set of equations needs to be linearized.
Specifically, we will linearize the equations about the vertically upward equillibrium
position, 𝜃 = 𝜋 and will assume that the system stays within a small neighborhood of
this equillbrium. This assumption should be reasonably valid since under control we
desire that the pendulum not deviate more than 20 degrees from the vertically upward
position. Let 𝜙 represent the deviation of the pedulum's position from equilibrium,
that is, 𝜃 = 𝜋+ 𝜙 . Again presuming a small deviation (𝜙 ) from equilibrium, we can
use the following small angle approximations of the nonlinear functions in our
system equations:
After substiting the above approximations into our nonlinear governing equations,
we arrive at the two linearized equations of motion. Note has been substituted for
the input F.
1. Transfer Function
To obtain the transfer functions of the linearized system equations, we must first take
the Laplace transform of the system equations assuming zero initial conditions. The
resulting Laplace transforms are shown below.
Recall that a transfer function represents the relationship between a single input and
a single output at a time. To find our first transfer function for the output 𝜙 (s) and
an input of we need to eliminate X(S) from the above equations. Solve the first
equation for X(s).
(
Then substitute the above into the second equation.
where,
From the transfer function above it can be seen that there is both a pole and a zero
at the origin. These can be canceled and the transfer function becomes the
following.
Second, the transfer function with the cart position X(s) as the output can be
derived in a similar manner to arrive at the following.
2. State-Space
The linearized equations of motion from above can also be represented in state-
space form if they are rearranged into a series of first order differential equations.
Since the equations are linear, they can then be put into the standard matrix form
shown below.
The C matrix has 2 rows because both the cart's position and the pendulum's position
are part of the output. Specifically, the cart's position is the first element of the output
Y and the pendulum's deviation from its equilibrium position is the second element
of Y.
Flowchart:-
Define 's' as variable of transfer
function using 'tf' function
b = pidtune(P_pend,'PID') ;
c = feedback(P_pend*b,1);
step(c)
Simulink Model :-
MATLAB Output: -
Simulink Output:-
Result: - We have successfully modelled and controlled the
inverted pendulum.
EXPERIMENT 05
Circuit Diagram :-
Transfer function :- 1/(Ms^2+Bs+K);
Flowchart:
THEORY:
The primary objective of this experiment is to design the compensation of single –input-single-output
linear time invariant control system.
Compensation is the modification of the system dynamics to satisfy the given specification. The
compensation is done by adding some suitable device in which is called as compensator. Compensator is realized
by such a way as to meet the performance specifications.
If sinusoidal input is applied to a network and if the steady state output has a phase lead, then the network
is called a lead network, and if the output has a phase lag then the network is called as a phase lag network.
Compensators are realized in our experiments using op-amps , electrical RC network as shown in figure.
where
The closed loop transfer function equation for the compensated system becomes
Hence
numc= [0 0 18.7 54.23]
denc= [1 7.4 29.5 54.23]
Hence
numc= [0 0 4]
denc= [1 2 4]
PROGRAM:
% Unit Step Response of Compensated and Uncompensated systems
1.4
Comp ensated syste m
1.2
1
Outputs c1 and c2
0.8
Uncompensated system
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t sec
For Lag Compensator
The closed loop transfer function equation for the compensated system becomes
PROGRAM:
% Unit Step Response of Compensated and Uncompensated systems
1.2
Compensated system
1
Outputs c1 and c2
Uncompensated system
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25 30 35 40
t sec
ROOT LOCUS:
AIM: To obtain the root locus of the system whose transfer function is defined by
(S+5)
G(S)=
S^2+7S+25
PROCEDURE:
PROGRAM:
%Program to find the root locus of transfer function%
s+5)
%
% s^2+7s+25
clc;
clear all;
close all;
% initialzations
num=input('enter the numerator coefficients ---->');
den=input('enter the denominator coefficients ---->');
%Transfer function
sys=tf(num,den);
rlocus(sys);
PROGRAM RESULT:
enter the numerator coefficients---->[1 5]
enter the denominator coefficients---->[1 7 25]
Root Locus
5
1
Imaginary Axis
-1
-2
-3
-4
-5
-18 -16 -14 -12 -10 -8 -6 -4 -2 0 2
Real Axis
BODE PLOT:
THEORY: The gain margin is defined as the change in open loop gain required to make the system
unstable. Systems with greater gain margins can withstand greater changes in system parameters before
becoming unstable in closed loop. Keep in mind that unity gain in magnitude is equal to a gain of zero
in dB.
The phase margin is defined as the change in open loop phase shift required to make a closed loop
system unstable.
The phase margin is the difference in phase between the phase curve and -180 deg at the point
corresponding to the frequency that gives us a gain of 0dB (the gain cross over frequency, Wgc).
Likewise, the gain margin is the difference between the magnitude curve and 0dB at the point
corresponding to the frequency that gives us a phase of -180 deg (the phase cross over frequency, Wpc).
AIM: To obtain the bode plot and to calculate the phase margin, gain margin, phase cross over and gain
cross over frequency for the systems whose open loop transfer function is given as follows.
25(S+1) (S+7)
G(s) =
S(S+2) (S+4) (S+8)
PROCEDURE:
PROGRAM:
%Program to find Bode Plot
% 25(s+1)(s+7)
%
% s(s+2)(s+4)(s+8)
clc;
clear all;
close all;
% initialzations
k=input('enter the gain---->');
z=input('enter the zeros ---->');
p=input('enter the ploes ---->');
t=zpk(z,p,k);
bode(t);
[Gm,Pm,Wcg,Wcp]=margin(t);
disp(Gm);
disp(Pm);
disp(Wgc);
disp(Wpc);
PROGRAM RESULT:
enter the gain ---->25
enter the zeros---->[-1 -7]
enter the ploes---->[0 -2 -4 -8]
Gm= Inf
Pm= 63.1105
Wgc= Inf
Wpc= 3.7440
Bode Diagram
50
Magnitude (dB)
-50
-100
-45
Phase (deg)
-90
-135
-180
-1 0 1 2 3
10 10 10 10 10
Frequency (rad/sec)
NYQUIST PLOT:
AIM:
To obtain the Nyquist plot and to calculate the phase margin, gain margin, phase cross over and
gain cross over frequency for the systems whose open loop transfer function is given as follows.
50(S+1)
G(S) =
S(S+3) (S+5)
PROCEDURE:
PROGRAM:
%Program to find the Nyquist Plot
% 50(s+1)
%
% s(s+3)(s+5)
clc;
clear all;
close all;
% initialzations
num=input('enter the numerator coefficients ---->');
den=input('enter the denominator coefficients ---->');
sys=tf(num,den);
nyquist(sys);
title('system1');
[Gm,Pm,Wcg,Wcp]=margin(sys);
disp(Gm);
disp(Pm);
disp(Wgc);
disp(Wpc);
PROGRAM RESULT:
enter the numerator coefficients---->[50 50]
enter the denominator coefficients---->[1 8 15]
Gm= Inf
Pm= 98.0516
Wgc=Inf
Wpc=49.6681
system1
4
1
Imaginary Axis
-1
-2
-3
-4
-1 0 1 2 3 4 5 6 7
Real Axis
RESULTS & DISCUSSIONS: Root Locus, Bode plot and Nyquist plot determined using the built-in
functions of MATLAB.
They are a powerful tool to design systems to required performance.
In order to determine the stability of the system using the root locus technique we find the range
of values of k for which the complete performance of the system will be satisfactory and the
operation is stable.
Bode plots provides relative stability in terms of gain margin and phase margin
EXPERIMENT NO – 8
TRANSFER FUNCTION ANALYSIS OF I) TIME RESPONSE FOR
STEP INPUT II) FREQUENCY RESPONSE FOR SINUSOIDAL
INPUT.
AIM:To find the I) Time response for step input II) Frequency response for sinusoidal input.
THEORY: The general expression of transfer function of a second order control system is given as
Here, ζ and ωn are damping ratio and natural frequency of the system respectively
There are number of common terms in transient response characteristics and which are
1. Delay time (td) is the time required to reach at 50% of its final value by a time response signal
2. Rise time (tr) is the time required to reach at final value by a under damped time response signal
during its first cycle of oscillation. If the signal is over damped, then rise time is counted as the
time required by the response to rise from 10% to 90% of its final value.
3. Peak time (tp) is simply the time required by response to reach its first peak i.e. the peak of first
4. Maximum overshoot (Mp) is straight way difference between the magnitude of the highest peak
of time response and magnitude of its steady state. Maximum overshoot is expressed in term of
percentage of steady-state value of the response. As the first peak of response is normally
maximum in magnitude, maximum overshoot is simply normalized difference between first peak
and steady-state value of a response.
5. Settling time (ts) is the time required for a response to become steady. It is defined as the time
required by the response to reach and steady within specified range of 2 % to 5 % of its final
value.
6. Steady-state error (e ss ) is the difference between actual output and desired output at the infinite
range of time.
C(S) 100
=
R(S) S2 +12S + 100
Plot the unit step response curve and find time domain specifications
PROGRAM:
clc;
clear all;
close all;
num=input('enter the numerator coefficients ---->');
den=input('enter the denominator coefficients ---->');
system=tf(num,den);
system
step(system)
grid on;
wn=sqrt(den(1,3));
zeta= den(1,2)/(2*wn);
wd=wn*sqrt(1-zeta^2);
disp('Delay time in seconds is')
td=(1+0.7*zeta)/wd
disp('Rise time in seconds is')
theta=atan(sqrt(1-zeta^2)/zeta);
tr=(pi-theta)/wd
disp('Peak time in seconds');
tp=pi/wd
disp('Peak overshoot is');
mp=exp(-zeta*pi/sqrt(1-zeta^2))*100
disp('settling time in seconds is');
ts=4/(zeta*wn)
PROGRAM RESULT:
enter the numerator coefficients ---->100
enter the denominator coefficients---->[1 12 100]
Transfer function:
100
s^2 + 12 s + 100
td =
0.1775
tr =
0.2768
tp =
0.3927
Peak overshoot is
mp =
9.4780
ts =
0.6667
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
Time (sec)
By the term frequency response, we mean the steady-state response of a system to a sinusoidal input.
Industrial control systems are often designed using frequency response methods. Many techniques are
available in the frequency response methods for the analysis and design of control systems.
Consider a system with sinusoidal input r(t) Asin t . The steady-state output may be written
as, c(t) B sin(t ) . The magnitude and the phase relationship between the sinusoidal input and the
steady-state output of a system is called frequency response. The frequency response test is performed
by keeping the amplitude A fixed and determining B and for a suitable range of frequencies.
Whenever it is not possible to obtain the transfer function of a system through analytical techniques,
frequency response test can be used to compute its transfer function.
The design and adjustment of open-loop transfer function of a system for specified closed-loop
performance is carried out more easily in frequency domain. Further, the effects of noise and parameter
variations are relatively easy to visualize and assess through frequency response. The Nyquist criteria is
used to extract information about the stability and the relative stability of a system in frequency domain.
Where, u / n is the normalized signal frequency. From the above equation we get,
1
T ( j) M
(1 u2 )2 (2 u)2 .
T ( j) tan1[2 u /(1 u2 )]
The steady-state output of the system for a sinusoidal input of unit magnitude and variable frequency
is given by, 1 2 u
c(t) sin t tan1
1 u2
.
(1 u2 )2 (2 u)2
It is seen from the above equation that when,
u 0, M 1 and 0
1
u 1, M and / 2
2
u , M 0 and
The magnitude and phase angle characteristics for normalized frequency u for certain values of are
shown in figure in the next page.
The frequency where M has a peak value is called resonant frequency. At this point the slope of the
1 4(1 ur )ur 8 ur
2 2
dM
magnitude curve is zero. Setting 0 we get, 0.
du u ur 2 (1 ur2 )2 (2 u r)2 3/ 2
Solving, ur 1 2 2 or, resonant frequencyr n 1 2 2 . ………… …… (01)
1
The resonant peak is given by resonant peak, M r . ……………… (02)
2 1 2
1
For, ( 0.707) , the resonant frequency does not exist and M decreases monotonically
2
with increasing u.
1
For 0 , the resonant frequency is always less than n and the resonant peak has a
2
value greater than 1.
From equation (01) and (02) it is seen that The resonant peak Mr of frequency response is indicative of
damping factor and the resonant frequency r is indicative of natural frequency for a given and
hence indicative of settling time.
For r , M decreases monotonically. The frequency at which
1
M has a value of is called the cut-off frequency c . The
2
range of frequencies over which M is equal to or greater than
1 is defined as bandwidth, .
b
2
The bandwidth of a second-order system is given by,
1 2 2 2 4 2 4 4 ………….(03)
1/ 2
b n
Figure below shows the plot of resonant peak of frequency response and the peak overshoot of step
response as a function of .
PROGRAM:
PROGRAM RESULT:
enter the numerator coefficients ---->100
enter the denominator coefficients---->[1 12 100]
resonant peak is
mr =
1.0417
resonant frequency in rad/sec is
wr =
5.2915
bandwidth in rad/sec is
wb =
11.4824
pm =
239.1873
1.001 0
0.999
0.998
-5
0.997
magnitude
phase
0.996
0.995
-10
0.994
0.993
0.992
0.991 -15
0 0.5 1 1.5 2 0 0.5 1 1.5 2
normalized frequency normalized frequency
RESULTS & DISCUSSIONS: Defining transfer functions and finding response using these transfer
functions has been simulated using MATLAB.
Responses can be studied with addition of controllers and their effect on performance.