Simulation of Simple
RC Circuits
Article 2
ARTICLE 1
Simulation of
Simple RC Circuit
CONTENTS
1.1 Introduction to Simple RC Circuit
1.2 Mathematical Modeling of RC circuit
1.3 Simulation with MATLAB
1.4 Simulation with SIMULINK
Appendix
1.1 Introduction to Simple RC circuit: We consider a circuit containing a dc voltage
source (battery) and a resister. The circuit contains only a dc voltage source V and
resister R is called a simple R circuit. In the simple R circuit the current and the voltage
are steady in all components.
Section 1.1
Introduction to simulation
For example when you turn on a flashlight current stare to flow almost immediately
through the bulb, batteries, and connecting metal parts. The current continues to flow
steadily until you turn of the switch. When you insert the capacitor in to the simple R
circuit, this picture changes. A capacitor introduces time dependence. The circuit that
contains a dc voltage source V, resister R and a capacitor C is called a simple RC circuit.
In simple RC circuit quantities change more gradually because of the capacitor. The Vc
builds up as charge accumulates on the plates of the capacitor. And the polarity of the
voltage Vc is such that it opposes the applied voltage V. In the simple RC circuit, we
change the capacitor charge by moving charge on or off the capacitor plate. Because the
charge and voltage are proportional in a capacitor it is not possible to change the voltage
across the capacitor with out changing the charge. Therefore, we conclude that the
voltage across the capacitor cannot change instantaneously, and this makes a simple RC
circuit a time dependent circuit.. As more time pass, the voltage Vc increase, so the
current through the capacitor ic decrease until such time as C if fully charged (Vc=V).
The main objectives of this article are:
To
learn (by simulation) how the voltage and the current changes with
time when the dc voltage source are switched into them
To
observe the effect of changes in circuit time constants on the
behavior of transient voltages
To
verify (by simulation) the equations the describe voltage and current
changes in simple RC circuits
1.2 System Analysis: Consider the electrical circuits of fig 1.1. If the out-put terminal
are connected to a high- impedance load, then the current through the resistor and the
current through capacitor are essentially equal.
s
Ein
Eout
Figure 1.1 Simple RC circuit
Article1
Simulation of Simple RC Circuit
Let i represent the current that pass through the resistor and the capacitor. For the
resistor, the current (i) is equal to the voltage difference (Ein - Eout) divided by the
resistance (R).
i
E in E out
R
(2.0)
For the capacitor, the current i is equal to the capacitor C times the instantaneous rate of
change of the capacitor voltage.
iC
dE out
dt
(2.1)
By equating the right-hand side of equation (2.0) and (2.1) we obtain that
RC
dE out
E out Ein
dt
(2.2)
We can easily see that equation (2.2) is a first order ordinary differential equation of type:
dx
x
dt
(2.3)
The general solution of the differential equation of (2.3) is given by*:
x e t e t dt Ke t
(2.4)
Where K is a constant and depend on initial condition of the system.
The quantity RC in equation (2.2) is called the time constant of the circuit and has the
units of time, in seconds, when R is in ohms and C is in farads. The conventional symbol
for a time constant is Greek letter Tau (). Let RC= , and compare equation (2.2) with
equation (2.3) we obtain the following relat
x Eout
Ein
(2.5)
We plug equation (2.5 ) in to equation (2.4) we obtain that
The proof is given in appendix A, and for more detail explanation the reader my consult any differential
equation book ,
Eout e
E out
Ein
e
E out
dt Ke
E out
(2.6)
Section 1.2
System Analysis
After some simplification we obtain
t
E out Ein (1 e )
(2.7)
From equation (2.1) and (2.7) it follow that current through the capacitor C is given by
t
Ein
e
R
(2.8)
Now we exam the significant of the time constant of the circuit. To do so we make the
table shown below with different values of .
t
iout in e
R
Ein 1
E
1
e 36.6 in
R
R
Ein 2
Ein
2
e 13.5
R
R
Ein 3
E
3
e 5 in
R
R
Ein 5
5
e 0
R
The table 1.1 shows the values of E
E out Ein (1 e )
Eout Ein (1 e 1 ) 63.2 Ein
Eout Ein (1 e 2 ) 86.5Ein
E out Ein (1 e ) 95Ein
Eout Ein
Table 1.1,
out ( the capacitor voltage ) with different values of
the time constant . From the table we observe the significant of the time constant . In
fact, one time constant after the application of the source voltage Eout ( the capacitor
voltage has risen to 63.2% of its steady- state value, and the current i has decay to 36.8%
of its initial value. In similar way, we can observe that at t = 2, Eout = 86.5% of it steadystate value and i=13.5% of its initial value. At t = 5 the capacitor is essentially fully
charged (Eou = Ein) and i 0, so we say that steady-state conditions have been reached
after an elapse of time equal to 5 time constants.
If we replace the voltage source Ein with a short-circuit, after the capacitor has been
allowed to charge fully, i.e., after the steady state condition have been reached when this
Article1
Simulation of Simple RC Circuit
happen, the charge on the capacitor flows from one plate through the resistance R to other
plate , and thus discharge. Note that the discharge current is opposite direction from
which that it followed when the capacitor was charging. When the capacitor discharges
the voltage Eout decay toward zero volts and the current decays toward zero amperes.
The equation that describe decay of voltage and current are respectively:
t
E out Ein e
(2.9)
Ein
e
R
(2.10)
1.3 System Simulation: In preceding paragraph we discussed the significant of the time
constant . Now by using the following MATLAB code we simulate the step response of
thevalue
step
response
the%Script
system with (1.1)
three different
of time
constant of E out with
different time constant
ein=1; % input value
t=0:0.1:10;% vector of time points
% for each value of the time constant tau, build,
%solve and plot the step response
for tau= 0.5:5:15.5
eout=ein*(1-exp(-t/tau));
subplot(2,1,1), plot(t,ein),
subplot(2,1,2),plot(t,eout),
xlabel ('time[sec]'), ylabel(Amplitude [Volt]')
title(' the step response with different value
of time constant')
grid
% identify the three-step response
text(1.5,0.8,'tau=0.5');
text(2.5,0.3,'tau=5.5');
text(5.5,0.5,'tau=10.5');
text(8.5,0.3,'tau=10.5');
6
% ishold on
if ishold~=1,hold on, end % put hold on after
the first curve
Section 1.3
System Simulation
Figure 1.2 The rise of the capacitor voltages when =0.5, 5.5,10.5,15.5
The following MATLAB code (script 1.2) computes the step response of the output
current (the capacitor current) with different values of time constant .
% Script (1.2) the step response of Iout with
different time constant
ein=1; % input value
R=10000;
t=0:0.1:10;% vector of time points
% for each value of the time constant tau,
build, %solve and plot the step response
for tau= 0.5:5:15.5 iout=(ein./R)*exp(-t/tau);
subplot(2,1,1), plot(t,in),
ylabel('Amplitude [Volt]')
title('Step input')
grid
Articler1
Simulation of Simple RC Circuit
% continue script (1.2)...
subplot(2,1,2),
plot(t,iout)
ylabel('Amplitude [Amp]')
title('Step response of the current with
different value of tau')
grid
% ishold on
if ishold~=1,hold on, end % put hold on
after the first curve
end
hold off % turn hold of after the last curve
%Script
(1.3)
Charge
and
discharge
step
%responses of the circuit. This program plots
%the step responses of the circuit when the
%capacitor charges and discharges.
ein=1; % input value (step)
t=0:0.1:10;% vector of time points
R=10000; % the value of the restore
% for each value of the time constant tau, plot
the step response
for tau= 0.5:5:20;
eout_charge=ein*(1-exp(-t/tau));% the
voltage across the capacitor.
subplot(2,2,1)
plot(t,ein);
ylabel('Amplitude [Volt]')
Figure 1.3 The decay of the capacitor current when =0.5,5.5,10.5,15.5
title('step input')
subplot(2,2,2)
plot(t,eout_charge)
Section 1.3
System Simulation
ylabel('Amplitude[Volt]')
title('The step responses')
if ishold~=1,hold on,end
eout_dis=ein*exp(-t/tau);
subplot(2,2,3)
plot(t,ein),
xlabel('time
[sec]'),ylabel('Amplitude[Volt]')
title('step input')
subplot(2,2,4)
plot(t,eout_dis),
xlabel('time
[sec]'),ylabel('Amplitude[Volt]')
title('The step responses')
if ishold~=1, hold on
end,
grid
end
9
hold off % turn hold of after the last curve
10
Article 1
Simulation of Simple RC circuit
Figure 1.4 The rise and decay of the capacitor voltage
Figure 1.4 shows the rise of the capacitor voltage during charge and the decay of the
capacitor voltage during discharge with different values of the time constants. More
precisely we pick the upper left corner to plot the rise of the capacitor voltage during
charge, and we pick the lower left corner to plot the decay of voltage on the capacitor
during discharge. We use the red, brown, blue and green colors to indicate the outputs
when = 15.5, 10.5, 5.5 and 0.5, respectively. By comparing the above graphs we can
easily observe that the circuit has fast rise (or decay) response when the time constant is
small, and it has slow rise (or decay) response when the time constant is big. So one can
adjusts the speed of the output response of a RC circuit by choosing the value of R and C.
Similarly the following MATLAB code, Script 1.3, evaluate the step response of the
capacitor current when the capacitor is charging and discharging .
11
Section 1.3
System Simulation
%Script (1.4) Charge discharge step responses of
%the
circuit.
This
program
plot
the
step
responses %of the capacitor current when the
capacitor %charge and discharge.
ein=1; % input value (step)
t=0:0.1:10;% vector of time points
R=10000;
% for each value of the time constant tau plot
the step response
for tau= 0.5:5:20;
iout_charge=(ein/R)*exp(-t/tau);% the voltage
% accross the capacitor.
subplot(2,2,1)
plot(t,ein);
ylabel('Amplitude[Volt]')
title('step input')
subplot(2,2,2)
plot(t,iout_charge)
ylabel('Amplitude[Amp]')
title('The step responses')
if ishold~=1,hold on,end
iout_dis=-1*(iout_charge);
subplot(2,2,3)
plot(t,ein),
xlabel('time [sec]'),ylabel('Amplitude[Volt]')
title('step input')
subplot(2,2,4)
plot(t,iout_dis),
xlabel('time [sec]'),ylabel('Amplitude[Amp]')
title('The step responses')
if ishold~=1, hold on
end,
grid
end
hold off % turn hold of after the last curve
12
Article1
Simulation of Simple RC circuit
Figure 1.5 The decay of the capacitor current during charge and discharge
We pick the upper left corner to plot the decay of the capacitor current during charge, and
we pick the lower left corner to plot the decay of the capacitor current during discharge.
We use the red, brown, blue and green colors to indicate the outputs when = 0.5, 5.5,
10.5, and 15.5 respectively. By comparing the above graphs we can easily observe that
the circuit has fast decay response when the time constant is small, and slow decay
response when the time constant is big.
13
Section 1.3
System Simulation
Now we apply the MATLAB Control Tool Box to analyze the circuit. To do so we need
to build the simulator block by using SIMULINK.To simulate a dynamic system with
SIMULINK we need to calculate the transfer function of the system in exam. The
frequency-domain algebraic equation is obtained by applying the Laplace transformation
to each term in equation (2.2).
deout
eout ein )
dt
(2.11)
Where L is the Laplace operator. Solving for the ratio Eout/Ein.
sE out E out Ein
(2.12)
Note: it is understood that e is a function of t and E is a function of s even thought the t
and the (s) are not used. We will often drop the (t) and the (s) in writing long expressions.
The transfer function of the electric circuit is given by
E out
1
E out 1 s
(2.13)
Thanks to MATLAB object- oriented programming capabilities, we can easily obtained
the three step responses of the electrical system by applying the following MATLAB
code The code tf (num, den) creates transfer function with numerator num and
denominator den.
% script (1.5) this program plot the step
response of the RC circuit with three different
time constant
sys1=tf(1,[1,0.2])% 1/1+5s
sys2=tf(1,[1,0.1])%1/1+10s
sys3=tf(1,[1,0.667])%1/1+15s
sys=[sys1, sys2, sys3];
step (sys) %the step response
14
Articler2
Circuit
Simulation of Simple RC
Step response for different value of time constant
For: tau=5
For: tau=15
For tau = 10)
1
0.9
0.8
0.7
A
M
P
L
I
T
U
D
E
0.6
0.5
0.4
0.3
0.2
0.1
0
30
60
900
30
60
900
30
60
90
Time
(sec.)
Now we use the simulation block diagrams to observe the step response in scope. The
three step responses obtained by using three different time constant are shown below.
Figures 1.1d. 1.2d, and 1.3d show the step response of the system when the time constant
is equal to 5, 10 and 15 respectively.
1
The block diagram for the step response for different value of time constant
0.2s+1
Output Point 1
Transf er Fcn1
1
Step Input Point
0.1s+1
Output Point 2
Transf er Fcn2
Scope1
1
0.0667s+1
Transf er Fcn3
Output Point 3
15
Section 1.3
Step response for different values of time constant
1
To:
Output
Point3
A
m
p
L
i
t
u
d
e
System Simulation
0.5
0
1
To:
Output
0.5
Point2
0
1
To:
Output
Point1 0.5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time (sec.)
We can also obtain the three step responses of the system by connecting the block
diagram as shown below.
In the block diagram shown above we used the transfer function method to simulate our
system. We can obtain the same result by using equation (1.2d). For commodity we
rewrite it below
sE out E out Ein
16
Article 1
Simulation of Simple RC Circuit
The block diagram for the step response for different value of time constant tau
1
0.2
s
Integrator
Gain
Gain1
Output Point1
0.2
1
0.1
Step Input Point
s
Integrator1
Gain3
Output Point2
Scope
Gain2
0.1
1
0.667
s
Integrator2
Gain4
Output Point3
Gain5
0.667
Step Response with different value of time constant tau
1
To:
Output
Point2
To:
Output
Point3
To:
Output
Point1
0.5
A
m 0
p 1
L
i 0.5
t
u 0
d 1
e
0.5
We already
visualize the effect of change in the
0
0
10
15
20
25
30
35
Time (sec.)
17
Section 1.3
Section 1.3
System Simulation
System Simulation
We already visualize the effect of change in the time constant of the transfer function on
the system. Now We create the script file called meshpolt.m to demonstrate the effect of
change in the time constant value on the step response of the system in 3-dimennsion.
% script (1.6) Meshplot.m
% This Matlab codes creates a mesh plot showing the
effect of increasing the time constant
n=[1:1:15];
y=zeros(2000,1); %
for i=1:14
num=1/n(i);
den=[1 num];
t=[0:.01:19.99]';
y(:,i)=step(num,den,t);
i=i+1;
end
mesh(fliplr(y),[-120 30])
xlabel( time), ylabel( inputs),zlabel(amplitiud)
title ( Meash plots showing Step Responce for 14 time constants)
18
With more sampling points the mesh plots look like shown below
time
inputs
19