Lab Manual
Lab Manual
To Study the analog (op amp based) simulation of linear differential equations using Mat lab-
Simulink.
APPARATUS REQUIRED
PROCEDURE
1. To build a SIMULINK model to obtain response of a amplifier, the following procedure is followed:
3. From the continuous block in the library drag the transfer function block.
4. From the source block in the library drag the step input.
6. From the math operations block in the library drag the summing point.
8. Connect all to form a system and give unity feedback to the system.
9. For changing the parameters of the blocks connected double click the respective block.
RESULT
Thus the (op amp based) simulation of linear differential equations has been verified by using Mat-lab
Simulink.
PROGRAMME
A.OPEN LOOP RESPONSE (FIRST ORDER SYSTEM)
T.F=4/(s+2)
2
Step Response
2
1.8
1.6
1.4
1.2
Amplitude
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3
Time (sec)
3
APPARATU REQUIRED
1. A PC with MATLAB package.
THEORY
State Variable approach is a more general mathematical representation of a system, which, along with the
output, yields information about the state of the system variables at some predetermined points along the flow
of signals. It is a direct time-domain approach, which provides a basis for modern control theory and system
optimization. SISO (single input single output) linear systems can be easily defined with transfer function
analysis. The transfer function approach can be linked easily with the state variable approach.
The state model of a linear-time invariant system is given by the following equations:
Ẋ (t) = A X(t) + B U(t) State equation
Y(t) = C X(t) + D U(t) Output equation
Where A = n x n system matrix, B = n x m input matrix,
C= p x n output matrix and
D = p x m transmission matrix,
4
PROGRAM:
B. Close Loop Response
1. Response of Step input
n=[4];
d=[1 2];
sys=tf(n,d);
sys=feedback(sys,1,-1)
step(sys)
2. Response of Impulse input
n=[4];
d=[1 2];
sys=tf(n,d);
sys=feedback(sys,1,-1)
impulse(sys)
Step Response
0.7
0.6
System: sys
Time (sec): 0.192
0.5 Amplitude: 0.456
0.4
Amplitude
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec)
d=[1 6 16];
sys=tf(n,d);
impulse(sys)
Step Response
0.35
0.3
0.25
0.2
Amplitude
0.15
0.1
0.05
0
0 0.5 1 1.5 2 2.5
Time (sec)
Impulse Response
0.45
0.4
0.35
0.3
0.25
Amplitude
0.2
0.15
0.1
0.05
-0.05
0 0.5 1 1.5 2 2.5 3
Time (sec)
n=[4];
d=[1 6 16];
sys=tf(n,d);
sys=feedback(sys,1,-1) ;
impulse(sys)
Step Response
0.25
0.2
0.15
Amplitude
0.1
0.05
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
Time (sec)
Impulse Response
0.45
0.4
0.35
0.3
0.25
Amplitude
0.2
0.15
0.1
0.05
-0.05
0 0.5 1 1.5 2 2.5
Time (sec)
7
RESULT
Thus the digital simulation of time response characteristics of a first and second order linear system with step
and impulse inputs were simulated using MATLAB and outputs are observed for respective inputs.
8
• Write MATLAB code to collect and process the data you want to record. This could involve reading
data from sensors, performing calculations, or simulating a system.
• As you collect data, append it to the data storage structure you initialized earlier. Ensure that the data
is formatted correctly for the chosen storage format.
• Periodically save the collected data to a file using MATLAB's file I/O functions. The specific function
you use will depend on the chosen storage format.
• Plot the collected data to visualize the system's response to the input signal.
Matlab code solution:
function Real time simulation( )
% Mechanical system parameters
m = 1; % Mass (kg)
k = 10; % Spring constant (N/m)
c = 0.5; % Damping coefficient (Ns/m)
% Initial conditions
initial_displacement = 0.1; % Initial displacement (m)
initial_velocity = 0; % Initial velocity (m/s)
% Time vector
t_start = 0;
t_end = 10;
dt = 0.01;
t = t_start:dt:t_end;
% Numerical integration using Euler's method
displacement = zeros(size(t));
velocity = zeros(size(t));
displacement(1) = initial_displacement;
velocity(1) = initial_velocity;
for i = 2:length(t)
acceleration = -k/m * displacement(i-1) - c/m * velocity(i-1);
9
Result :
AIM:
To design and simulate a mathematical model for a linear mechanical system.
APPARATUS:
1. MATLAB R2021
2. Simulink -
FORMULA:
𝑑2 𝑑 𝑑
𝑑2 𝑑 𝑑 𝑑
M1 = M2 = 5 kg
K1 = 2 N/m
K2 = 6 N/m
f1 = 2N/m/s
f2 = 3N/m/s
The transfer function in s domain for the corresponding differential equation is:
𝑦2(𝑠) 5𝑠2 + 5𝑠 + 11
=
𝑓(𝑠) 25𝑠4 + 40𝑠3 + 91𝑠2 + 27𝑠 + 30
BLOCK DIAGRAM/CODE:
1. Code:
>>num=[5 5 11];
>>den=[25 40 91 27 30];
>>G=tf(num,den);
>>kp=dcgain(G);
>>ess=1/(1+kp);
>>step(G);
12
2. Simulink model:
OBSERVATIONS:
1. Code:
num =
5 5 11
den =
25 40 91 27 30
G=
5 s^2 + 5 s + 11
--- - - - - -
ess =
0.7317
13
2. Simulink:
14
MEASUREMEN VALUES
TS
60.484%
Overshoot
0.806
Preshoot
5.563
Undershoot
1.8585
seconds
Rise Time
1.848
seconds
Fall Time
45.5 seconds
Settling Time
0.347
Final Value
0.7317
Steady state Error
INFERENCE:
• The differential equations for a linear mechanical system were established and it
was realized using Simulink.
• The corresponding transfer function graph was plotted for step input, in Simulink
and MATLAB, and the properties were analyzed.
• The damping effect of the spring system was established, and the corresponding
data was tabulated.
RESULT:
Thus, the mathematical model of the linear mechanical system was simulated, and the
corresponding parameters were noted.
15
Aim:
To design and simulate a mathematical model for a series RLC electrical circuitand analyze
the response graph.
APPARATUS:
1. MATLAB R2021
2. Simulink -
FORMULA/DERIVATION:
In a series RLC circuit, the resistor acts as the dissipating element, while the conductor and
inductor act as energy storing elements. We utilize the transfer function, and by giving the
input as a unit step signal, we can model the systemand obtain the respective graph.
Here, let:
• L = inductance (H)
• R = resistance ( R)
• C = capacitance(F)
16
• q = charge
𝐿𝑑𝑖(𝑡) 1
𝑉𝑠 (𝑡) − − 𝑖(𝑡)𝑅 − ∫ 𝑖(𝑡)𝑑𝑡 = 0
𝑑𝑡 𝐶
,
𝑑𝑡
𝐿𝑑 𝑑𝑞(𝑡) 𝑅𝑑𝑞(𝑡) 1
𝑉(𝑡)𝑠 = ( )+ + ∫ 𝑑𝑞
𝑑𝑡 𝑑𝑡 𝐶
𝑑𝑡
𝐿𝑑2𝑞(𝑡) 𝑅𝑑𝑞 𝑞
𝑉𝑠 (𝑡) = + +
𝑑𝑡2
𝑑𝑡 𝐶
𝑑2𝑞(𝑡) 𝑑𝑞(𝑡)
1
𝐿 = 𝑅( )+ 𝑞(𝑡) = 𝑉𝑠 (𝑡)
𝑑𝑡2 𝑑𝑡 𝐶
𝑄(𝑠) = (1/𝐿)
𝑉 (𝑠) 𝑅𝑠 1
𝑠 𝑠2 + 𝐿 + 𝐿𝐶
17
BLOCK DIAGRAM/CODE:
• L=1 H
• C= 0.05 F
Code:
>>R=3;
>>L=1;
>>C=0.05;
>>num=[1./L];
>>den=[1 (R/L) 1./(L*C) ];
>>G=tf(num,den);
>>step(G);
2. Simulink model:
18
OBSERVATIONS:
1. MATLAB code:
2. Simulink:
19
MEASUREMENTS VALUES
30.921%
Overshoot
0.658%
Pre shoot
9.302%
Undershoot
317.030 ms
Rise Time
INFERENCE:
• We know that current lags in the inductor, leads in capacitor and is in phase in
resistor.
• Here, the graph is divided into transient and steady state regions, where the
transient state is influenced by initial conditions(R,L,C), while the steady state
component remains unchanged.
• Hence from the graphs, we can observe the underdamping of the wave,
before reaching a steady state value. By changing the values of R, L and C, we
can change the damping ratio and in turn the response as well.
RESULT:
Thus, for a series RLC electrical circuit, the transfer function was obtained,
and the corresponding Simulink model and MATLAB codewas designed. For
a step input, the resultant graph was plotted andanalyzed.
20
APPARATUS:
1. MATLAB R2021
2. Simulink -
FORMULA/THEORY:
A process reaction curve will be generated in response to a disturbance. This process
curve is then used to calculate the controller gain, integral time, and derivative time. It
is performed in open loop so that no control action occurs,and the process response can
be isolated.
To generate a process reaction curve, the process can reach steady state or as close to
steady state as possible. Then, in open loop, so that there is no controlaction, a small step
disturbance is introduced, and the reaction of the process variable is b recorded.
For an oscillatory reaction curve, the dimensionless equation for model 1 will be
adopted. To distinguish between process models that do not have a processzero (where 𝑎̅
= 0) and those which do have a zero (where 𝑎̅≠ 0) the following lemma is needed.
21
22
23
BLOCK DIAGRAM:
1. Simulink model:
OBSERVATIONS:
1. Simulink:
Process A:
Process B:
24
p 14.4 14.3
7.
CALCULATIONS:
1. Process A:
1 1.005 − 1
𝜒= 𝑙𝑛 ( )
10.33 − 24.73
1.206 − 1
𝝌 = 𝟎. 𝟐𝟓𝟖
ln(1.206 − 1)2
𝜍=√
𝜋2 + (𝑙𝑛1.206 − 1)2
25
𝝇 = 𝟎. 𝟒𝟒𝟗
14.4
𝑟=
√4𝜋2 + 14.42 ∗ 0.2582
𝑟 = 𝟏. 𝟗𝟕𝟐
26
1.9727
𝜃 = 10.33 + ln(1.206 − 1)
0.449
𝜽 = 𝟑. 𝟑𝟗
2. Process B:
1 1.01 − 1
𝜒= 𝑙𝑛 ( )
8.331 − 22.73
1.385 − 1
𝝌 = 𝟎. 𝟐𝟓𝟕
14.199 ∗ 0.257
𝜍=
√4𝜋2 + 14.1992 ∗ 0.2572
𝝇 = 𝟎. 𝟓
14.199
𝑟=
√4𝜋2 + 14.1992 ∗ 0.2572
𝑟 = 𝟏. 𝟗𝟓𝟒
) )
𝑒−0.5∗8.531
𝒂′ = 𝟏. 𝟓𝟑𝟗
27
( ))
6.28
1 − 1.539 ∗ 0.5
𝜽 = 𝟒. 𝟔𝟓𝟕
28
1. ς 0.449 0.5
2. χ 0.258 0.257
3. τ 1.9727 1.954
4. a’ 0 1.539
5. θ 3.39 4.657
𝑒−3.39𝑠
3.88𝑠2 + 1.771𝑠 + 1
(1 + 1.539𝑠)𝑒−4.6575
3.818𝑠2 + 1.954𝑠 + 1
INFERENCE:
• From the graphs, we can analyze the process curve and obtain the necessary
parameters.
• The damping ratio for both the processes reinforce the fact that the curves are
underdamped.
• The delay time θ is higher for process B and it is indicative for the fact that
process reaction curve for process B takes longer than that of A.
RESULT:
Thus, using Simulink, it was possible to obtain the process reaction curves of thegiven
process. The parameters were obtained from the graph and additional values were
calculated as well. Thus, the resultant equations of the processes were modelled from these
values as well.
29
AIM
To check the stability analysis is using Routh Hurwitz Criterion for the given system
or transfer function using MATLAB Software.
APPARATUS REQUIRED
PROCEDURE
➢ Open the MATLAB software using a MATLAB icon Open a blank M- File or
Simulink file (File, New, M file) Type the given program in M file
➢ Run the program using debug option or using F5 key
➢ Find the stability of the system in the output graph and compare it
with theoretical value
RESULT
Thus the stability analysis is using Routh Hurwitz Criterion for the given system or
transfer function using MATLAB Software was executed.
30
PROGRAM
num=[0 4 5];
den=[1 4 21];
sys1=tf(num, den);
rlocus(sys1)
grid
title('Root locus plot of system G(s) = (4s+5)/(s2+4s+21)')
31
AIM
To Check the stability analysis of the given system or transfer function of rootlocus
using MATLAB Software.
APPARATUS REQUIRED
PROCEDURE
➢ Open the MATLAB software using a MATLAB icon Open a blank M- File or
Simulink file (File, New, M file) Type the given program in M file
➢ Run the program using debug option or using F5 key
➢ Find the stability of the system in the output graph and compare it
with theoretical value
RESULT
Thus the designs of root locus for the given transfer function using MATLAB Software
was executed.
32
PROGRAM
%Bode Plot for the Transfer Function=10/(s3+8s2+12s)
nu=[10];
de=[1 8 12 0];
sys=tf(nu,de);
bode(sys);
grid on;
Bode Diagram
50
0
Magnitude (dB)
-50
-100
-150
-90
-135
Phase (deg)
-180
-225
-270
-2 -1 0 1 2 3
10 10 10 10 10 10
Frequency (rad/sec)
33
To Design the bode plot for the given system and also determine the gain and phase
margin using MATLAB Software.
APPARATUS REQUIRED
PROCEDURE
➢ Open the MATLAB software using a MATLAB icon Open a blank M- File or
Simulink file (File, New, M file) Type the given program in M file
➢ Run the program using debug option or using F5 key
➢ Find the stability of the system in the output graph and compare it
with theoretical value
RESULT
Thus the design of bode plot for the given system using MATLAB Software was
executed.
34
PROGRAM
1. Lag Compensator
K=9600
d1=conv([1 4 0],[1 80]) % used to formulate the polynomial
G=tf(K,d1) % generate the transfer function.
margin(G)
pmreq=input('Enter Required Phase Margin') % enter 33 as given in
question
pmreq=pmreq+5
phgcm=pmreq-180
wgcm=input('Enter new gain cross over frequency') % from the first
bode plot use the mouse pointer and locate wgcm corresponding to
phgcm.
[Beta,p]=bode(G,wgcm)
T=10/wgcm
Zc=1/T
Pc=1/(Beta*T)
Gc=tf([1 Zc],[1 Pc])
sys=Gc*G/Beta
margin(sys)
2..LEAD COMPENSATOR
clear variables;
% plant G parameters
s = tf('s');
a = 2.5; b = 27;
%% a) Gain K for PO=10
PO = 10; % percentage overshoot
zeta = log(100/PO)/sqrt(pi^2+ (log(100/PO))^2 ); % damping ratio
PM_d = round(100*zeta)+1; % PM desired at the nearest round value
h = tand(180-90-PM_d);
omega_c = roots([1 (a+b)/h -a*b]); % new omega_c
K = omega_c(2)*sqrt(omega_c(2)^2+a^2)*sqrt(omega_c(2)^2+b^2); % new
gain K
G = K/( s*(s+a)*(s+b) ); % Plant G
figure;
margin(G);
35
36
To design the lag, lead compensators and evaluation of closed loop Performance using
MATLAB Software.
APPARATUS REQUIRED
PROCEDURE
➢ Open the MATLAB software using a MATLAB icon Open a blank M- File or
Simulink file (File, New, M file) Type the given program in M file
➢ Run the program using debug option or using F5 key
➢ Find the stability of the system in the output graph and compare it
with theoretical value
RESULT
Thus the design of lag, lead compensators and evaluation of closed loop Performance
37
% Proportional Controller
Kp=600;
num1=[Kp];
den1=[1 10 20+Kp];
t=0:0.01:2;
figure(2);
step(num1,den1,t)
grid;
OUTPUT
% Proportional Controller
38
APPARATUS REQUIRED
PROCEDURE
12. To build a SIMULINK model to obtain response of a P, PI, PID Controllers, the
following procedure is followed:
14. From the continuous block in the library drag the transfer function block.
15. From the source block in the library drag the step input.
16. From the sink block in the library drag the scope.
17. From the math operations block in the library drag the summing point.
18. From the discrete block in the library drag the PID controller.
19. Connect all to form a system and give unity feedback to the system.
20. For changing the parameters of the blocks connected double click the respective
block.
RESULT
Thus the effect of P, PI, PD, and PID controller has been verified by using Matlab
coding.