Circut Simulation (Project)
Circut Simulation (Project)
Attached in this report the requested second phase of our course project.
As you requested, this phase includes selected designs of first and second order circuit systems,
detailed writing of the differential equations of each system, determination of their transfer
functions, the state-space representations, deriving analytical expressions of the output voltage of
each system and Simulations of the systems by selecting three different combinations using
SIMULINK & MATLAB for each mathematical representation.
Our group hopes this report meets a good representation of FOS& SOS. Please let us know your
feedback to help us improve our work.
Sincerely,
Group F
Four Undergraduates engineers.
Mechanical Design & Production Department,
Faculty of Engineering, Cairo University.
Enclosure: The second Phase of “Report on Modeling& Simulation of First and Second Order
Systems”
Faculty of Engineering – Cairo University
Mechanical Design and Production Engineering
Two-Semester System – 3rd Year
MDP 307: Modeling and Simulation of Dynamic
Systems and Robots– Fall 2019
Report On
(Modeling& Simulation of First and Second Order Systems)
(Phase Two)
Submitted to
A.P: Yasser H. Anis
Prepared by Group F
Mahmoud Ahmed EL-Sayed
Mahmoud Mohamed Tawhid
Anton Tamer Shafique
Ayman Hisham Mahmoud
I
3. Validate the results ----------------------------------------------------------------------------------- 15
Appendices ---------------------------------------------------------------------------------------------------- 17
References ----------------------------------------------------------------------------------------------------- 20
II
List of Figures
III
List of Tables
IV
Abstract
The procedure to design any needed function should be carried out by following six main
steps. First, you must transform the requirements to a physical system, then draw a functional
block diagram, after that is creating a schematic drawing of the system. To understand how the
system works you will come to the step number four, which focuses on developing a
mathematical model by writing the system equations, then by representing the system model
using one of representation methods, you will be able to analyze the system even by analytical
solutions or computer simulation.
In this Report we are going to build two simple RLC electric circuits, which will
represent a first and a second order systems respectively, using the previous procedure to
develop a mathematical modeling and representation for each system, then simulating each
system using three different combinations of R, L and Cs to study each system output. Then we
are exposed to test experimental validation for the same three combinations using a DAQ card.
V
Introduction
During the past century, our definition of a control system has become “A control system
consists of subsystems and processes (or plants) assembled for the purpose of obtaining a desired
output with desired performance”[1]. That’s the meaning of under control concept, looking at
your body -as a system- for example, it’s fully under control. Imagine you are going to throw an
arrow for the first time in your life, by aiming a target (the desired output) you will begin to set
your body (the system) to the most perfect conditions, using your subsystems, which are
assembled to the main system, like vision to estimate the aiming distance, the muscles to
estimate the most probable force to make the arrow able to reach the target, the feeling to
eliminate the affecting conditions like gravity, wind direction and so on. In this example your
purpose is to obtain a desired output -hit the target- and to obtain performance -like how fast you
will hit the target-. Systems like this could be classified into two types, first is the open loop
system which focuses on the desired output and just relies on the inputs, and second is the closed
loop system which also aims the desired output, but relies on the feedback to measure the
difference between the actual output and the desired one. We can consider each system which
fulfills these conditions as a control system, systems with mechanical components, systems with
electrical components, systems with hydraulic or pneumatic components, systems combining
those components together, and even a system without engineering background like servicing
system in one of the restaurants.
It’s important to look at the system with other configuration which determines the
behavior of the system and letting us know how to deal with the system. This configuration is the
order of the system, which is the number of derivatives (or integrals) needed to model the
dynamics of the system. When taking the Laplace transform of the model’s differential
equations, those derivatives will be replaced by the “s” variable and one can build the transfer
function between the input and the output. The largest exponent of “s” in the denominator (or the
number of poles) will also match the order of the system. In this report we will focus on the first
and the second order systems.
First order system is often a good mathematical model to represent the behavior of many
real-world systems. Examples include a temperature change in an oven due to heat input, R-C or
R-L circuit behavior, liquid level change in leaky tank and others. First-order systems do not
exhibit overshoot or oscillatory behavior and are not suitable models in certain cases[2]. A
second-order model is more appropriate in such cases. A second-order model is used to represent
systems that can exhibit a variety of responses to input stimulus, including overshoot, undershoot
or oscillatory behavior. Examples include R-L-C circuits, car suspension system and others.
First-order and second-order systems are easy to analyze and design. Hence, they are widely
used in preliminary analysis and design related to real-world systems. More complex models can
then be used to verify the design using simulation methods. Like we mentioned, the focus in our
report will be only on the first and the second order systems, and for specific, previously selected
two electric circuits one for FOS and the other for SOS.
Page | 1
Design of a first order circuit system (FOS)
1
𝑣𝑖𝑛 (𝑡) = 𝑖(𝑡)𝑅 + ∫ 𝑖(𝑡) . 𝑑𝑡 (1)
𝑐
1
𝑣𝑜𝑢𝑡 (𝑡) = ∫ 𝑖(𝑡) . 𝑑𝑡 (2)
𝑐
𝑎
Making it in the first order general formula :
𝑎+𝑠
1
𝑉𝑜𝑢𝑡 𝑅𝐶 1
𝐺(𝑠) = = 1 (5) Hence 𝑎=
𝑉𝑖𝑛 +𝑠 𝑅𝐶
𝑅𝐶
Page | 2
3. The State-Space Representation (A, B, C, D matrices)
𝑖
𝑣𝑐̇ = (6)
𝐶
𝑣𝑖𝑛 = 𝑖𝑅 + 𝑣𝑐 (7)
State equation:
1 1
[𝑣𝑐̇ ] = [− ] [𝑣𝑐 ] + [ ] [𝑣𝑖𝑛 ] (9)
𝑅𝐶 𝑅𝐶
Output equation:
𝑦 = 𝑣𝑜𝑢𝑡 = 𝑣𝑐
𝑦 = [1][𝑣𝑐 ] + [0][𝑣𝑖𝑛 ] (10)
1 1
𝐴 = [− ] 𝐵=[ ] 𝐶 = [1] 𝐷 = [0]
𝑅𝐶 𝑅𝐶
𝑣𝑜𝑢𝑡 (𝑡) = 𝑣𝑖𝑛 − 𝑣𝑖𝑛 𝑒 −𝑎𝑡 For the first order system
1
𝑣𝑜𝑢𝑡 (𝑡) = 𝑣𝑖𝑛 − 𝑣𝑖𝑛 𝑒 −𝑅𝐶𝑡 (11)
Page | 3
Design of a second order circuit system (SOS)
𝑑𝑖(𝑡) 1
𝑣𝑖𝑛 = 𝑖(𝑡)𝑅 + 𝐿 + ∫ 𝑖(𝑡) . 𝑑𝑡 (1)
𝑑𝑡 𝐶
1
𝑣𝑜𝑢𝑡 = ∫ 𝑖(𝑡) . 𝑑𝑡 (2)
𝐶
𝑉𝑖𝑛
𝐼= 1 (3)
[𝑅+𝐿𝑠+ ]
𝐶𝑠
𝑉𝑜𝑢𝑡
𝐼= 1 (4)
𝐶𝑠
𝑉𝑖𝑛 𝑉𝑜𝑢𝑡
From (3) & (4) 1 = 1
[𝑅+𝐿𝑠+ ] 𝐶𝑠
𝐶𝑠
Page | 4
𝑣𝑜𝑢𝑡 1
= 𝐺(𝑠) = [𝑅𝐶𝑠+𝐿𝐶𝑠2
𝑣𝑖𝑛 +1]
𝑏
Make it in the second order system general formula
𝑠 2 +𝑎𝑠+𝑏2
1
𝐿𝐶
𝐺(𝑠) = 𝑅 1 (5)
[𝑠 2 + 𝑠+ ]
𝐿 𝐿𝐶
𝑖
𝑣𝑐̇ = (6)
𝐶
𝑣𝐿
𝑖̇𝐿̇ = (7)
𝐿
𝑖 = 𝑖𝐿 (8)
𝑣𝑖𝑛 = 𝑖𝑅 + 𝑣𝐿 + 𝑣𝑐 (9)
𝑣𝐿 = 𝑣𝑖𝑛 − 𝑣𝑐 − 𝑖𝐿 𝑅 (10)
From (2), (3), (4) & (5)
𝑣𝑖𝑛 𝑣𝐶 𝑅
𝑖̇𝐿̇ = − − 𝑖𝐿 (11)
𝐿 𝐿 𝐿
Output equation:
𝑦 = 𝑣𝑜𝑢𝑡 = 𝑣𝑐
𝑣𝑐
𝑦 = [1 0] [ 𝑖 ] + [0][𝑣𝑖𝑛 ] (13)
𝐿
Page | 5
The State-Space Representation:
1
0 0
𝐶
𝐴 = [−1 −𝑅 ] 𝐵 = [1] 𝐶 = [1 0 ] 𝐷 = [0]
𝐿
𝐿 𝐿
Page | 6
Simulations for FOS Circuit (Using three combinations of R & C)
Combination R C
1 4.7 kΩ 100 µF
2 4.7 kΩ 220 µF
3 10 kΩ 100 µF
Figure 4: Recorded scopes for the three combinations of FOS using SIMULINK inspector
Page | 7
2. Transfer Function Simulation of 𝒗𝒐𝒖𝒕 (𝒕) for step input 𝒗𝒊𝒏 (𝒕) = 𝟓𝑽
100
𝑉𝑜𝑢𝑡 47
For Combination 1 …………𝐺(𝑠) = = 100
𝑉𝑖𝑛 𝑠+
47
500
𝑉𝑜𝑢𝑡 517
For Combination 2………….𝐺(𝑠) = = 500
𝑉𝑖𝑛 𝑠+
517
𝑉𝑜𝑢𝑡 1
For Combination 3………….𝐺(𝑠) = =
𝑉𝑖𝑛 𝑠+1
Figure 5: Transfer Function Simulation Using MATLAB for FOS (For step input 𝑣𝑖𝑛 (t)=5V)
100 100
For Combination 1…..𝐴 = [− ] 𝐵=[ ] 𝐶 = [1] 𝐷 = [0]
47 47
500 500
For Combination 2… .𝐴 = [− ] 𝐵=[ ] 𝐶 = [1] 𝐷 = [0]
517 517
Page | 8
For MATLAB Code see
Appendix B
Figure 6: State-Space Simulation Using MATLAB for FOS (For step input 𝑣𝑖𝑛 (t)=5V)
4. Analytical Time Response of 𝒗𝒐𝒖𝒕 (𝒕) for step input 𝒗𝒊𝒏 (𝒕) = 𝟓𝑽
100
− 𝑡
For Combination 1….…𝑣𝑜𝑢𝑡 (𝑡) = 5 − 5𝑒 47
500
− 𝑡
For Combination 2 ……𝑣𝑜𝑢𝑡 (𝑡) = 5 − 5𝑒 517
Page | 9
For MATLAB Code see
Appendix C
Figure 7:Analytical Time Response Using MATLAB for FOS (For step input 𝑣𝑖𝑛 (t)=5V)
Page | 10
Simulations for SOS Circuit (Using three combinations of R & C)
Combination R L C
1 10 KΩ 500 H 10 µF Under damped
2 10 KΩ 500 H 20 µF Critically Damped
3 10 KΩ 200 H 20 µF Over Damped
200
For Combination 1……….𝐺(𝑠) =
[𝑠 2 +20𝑠+200]
100
For Combination 2……….𝐺(𝑠) =
[𝑠 2 +20𝑠+100]
250
For Combination 3……….𝐺(𝑠) =
[𝑠 2 +50𝑠+250]
Figure 10: Transfer Function Simulation Using MATLAB for SOS (For step input 𝑣𝑖𝑛 (t)=5V)
Page | 12
For MATLAB Code see
Appendix E
Figure 11:State-Space Simulation Using MATLAB for SOS (For step input 𝑣𝑖𝑛 (t)=5V)
4. Analytical Time Response of 𝒗𝒐𝒖𝒕 (𝒕) for step input 𝒗𝒊𝒏 (𝒕) = 𝟓𝑽
For the FOS and SOS circuits using simulation of MATLAB via SIMULINK, transfer function,
State-Space or analytical time response simulations, the results are identical if we used small
time step ex (t=.01 sec).
1. Experimental Setup
By connecting resistance and capacitor in series, then making a wiring connection between the
ground port in ARDUINO and the resistance end point (1) and a wiring connection between 5V
port in ARDUINO with the capacitor end point (2). For monitoring the output voltage of
capacitor, we used wiring connection between the analog port 𝐴𝑜 in ARDUINO and the
capacitor point (3) and using ARDUINO code (Look Appendix G).
Page | 14
3. Validate the results
Figure 14:Monitoring Data Using ARDUINO Serial Plotter for Combination 1 Circuit
Figure 15: Monitoring Data Using ARDUINO Serial Plotter for Combination 2 Circuit
Page | 15
Figure 16: Monitoring Data Using ARDUINO Serial Plotter for Combination 3 Circuit
By Generating the data readings for the output voltage and manipulating it in EXCEL
The experiment validates the result we got from the simulation except there is small shift in slope
due to resistance in wires.
Page | 16
Appendices
Appendix A
MATLAB Code of FOS Transfer Function Simulation
syms s
R2 = 4700; R1 = R2; R3=10000;C3 = .0001; C1 = C3; C2=.00022;
num1=[1/(R1*C1)]; num2=[1/(R2*C2)]; num3=[1/(R3*C3)];
den1=[1 1/(R1*C1)]; den2=[1 1/(R2*C2)]; den3=[1 1/(R3*C3)];
sys1=tf(5*num1,den1); sys2=tf(5*num2,den2); sys3=tf(5*num3,den3);
stepplot(sys1,'r',sys2,'g',sys3,'b--')
legend('Combination 1', 'Combination 2', 'Combination 3')
grid on
Appendix B
MATLAB Code of FOS State-Space Simulation
Page | 17
Appendix C
MATLAB Code of FOS Analytical Time Response Simulation
syms s
R2 = 4700; R1 = R2; R3=10000;C3 = .0001; C1 = C3; C2=.00022;
num1=[1/(R1*C1)]; num2=[1/(R2*C2)]; num3=[1/(R3*C3)];
den1=[s+1/(R1*C1)]; den2=[s+1/(R2*C2)]; den3=[s+1/(R3*C3)];
r=5/s;
c1=r*(num1/den1); c2=r*(num2/den2); c3=r*(num3/den3);
N1=matlabFunction(ilaplace(c1)); N2=matlabFunction(ilaplace(c2)); N3=matlabFunction(ilaplace(c3));
t=[0:.01:10];
plot(t,N1(t),'r' , 'LineWidth', 2)
hold on
plot(t,N2(t),'g' , 'LineWidth', 2)
plot(t,N3(t),'b--' , 'LineWidth', 2)
xlabel('Time (seconds)')
ylabel('Amplitude')
title('Step Response')
legend('Combination 1', 'Combination 2', 'Combination 3')
grid on
Appendix D
syms s
L2 = 500; L1 = L2; L3=200;R3 = 10000; R2 = R3; R1 = R2; C1=.00001;C3 = .00002; C2 = C3;
num1=[1/(L1*C1)]; num2=[1/(L2*C2)]; num3=[1/(L3*C3)];
den1=[1 (R1/L1) 1/(L1*C1)]; den2=[1 (R2/L2) 1/(L2*C2)]; den3=[1 (R3/L3) 1/(L3*C3)];
sys1=tf(5*num1,den1); sys2=tf(5*num2,den2); sys3=tf(5*num3,den3);
stepplot(sys1,'r',sys2,'k',sys3,'b')
legend('Combination 1', 'Combination 2', 'Combination 3')
grid on
Appendix E
Page | 18
Appendix F
syms s
L2 = 500; L1 = L2; L3=200;R3 = 10000; R2 = R3; R1 = R2; C1=.00001;C3 = .00002; C2 = C3;
num1=[1/(L1*C1)]; num2=[1/(L2*C2)]; num3=[1/(L3*C3)];
den1=[s^2+s*(R1/L1)+1/(L1*C1)]; den2=[s^2+s*(R2/L2)+1/(L2*C2)]; den3=[s^2+s*(R3/L3)+1/(L3*C3)];
r=5/s;
c1=r*(num1/den1); c2=r*(num2/den2); c3=r*(num3/den3);
N1=matlabFunction(ilaplace(c1)); N2=matlabFunction(ilaplace(c2)); N3=matlabFunction(ilaplace(c3));
t=[0:.01:1.2];
plot(t,N1(t),'r' , 'LineWidth', 2)
hold on
plot(t,N2(t),'k' , 'LineWidth', 2)
plot(t,N3(t),'b' , 'LineWidth', 2)
xlabel('Time (seconds)')
ylabel('Amplitude')
title('Step Response')
legend('Combination 1', 'Combination 2', 'Combination 3')
grid on
Appendix G
ARDUINO Code
int const inv= A0;
float volt ;
float reading;
void setup() {
Serial.begin(2400);
}
void loop() {
reading= analogRead(inv);
volt= reading *5/1024;
Serial.println(volt);
delay(1);
}}
Page | 19
References
Page | 20