Download mathlab file for series rc circuit

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Nanogenerator wikipedia , lookup

CMOS wikipedia , lookup

Spark-gap transmitter wikipedia , lookup

Schmitt trigger wikipedia , lookup

Flexible electronics wikipedia , lookup

Crystal radio wikipedia , lookup

Multimeter wikipedia , lookup

TRIAC wikipedia , lookup

Operational amplifier wikipedia , lookup

Power electronics wikipedia , lookup

Integrated circuit wikipedia , lookup

Index of electronics articles wikipedia , lookup

Power MOSFET wikipedia , lookup

Two-port network wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Regenerative circuit wikipedia , lookup

Ohm's law wikipedia , lookup

Current source wikipedia , lookup

Valve RF amplifier wikipedia , lookup

Current mirror wikipedia , lookup

Opto-isolator wikipedia , lookup

Surge protector wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Rectiverter wikipedia , lookup

Network analysis (electrical circuits) wikipedia , lookup

RLC circuit wikipedia , lookup

Transcript
NUMERICAL ANALYSIS OF CIRCUITS CONTAINING
RESISTORS, CAPACITORS AND INDUCTORS
Numerical methods are often used to study mechanical systems. However, these same
methods can be employed to investigate the response of circuits containing resistors,
capacitors and inductors. A wide range of phenomena can be studied such as the
frequency response of filters and tuned circuits; resonance, damped and forced
oscillations; voltage, current, power, energy and phase relationships.
Resistors, capacitors and inductors are basic components of circuits. These
components are connected to a source of electrical energy. A simple model for the
source of electrical energy is to consider it to be a voltage source called the emf vS and
a series resistance called the internal resistance r. The potential difference applied to a
circuit is called the terminal voltage v. If a current is supplied from the electrical
energy source to a circuit, the terminal voltage is
v = vS – i r
In the computer modelling of circuit behaviour, the effects of internal resistance of the
source can be considered. Suitable electrical sources include step, on/off/on,
sinusoidal and pulsed functions.
For a resistor R, the voltage vR across it and the current iR through it are always in
phase and related by the equation
vR(t) = R i(t)
A capacitor consists of two metal plates separated by an insulating material. When a
potential difference vC exists across a capacitor, one plate has a positive charge +q and
the other plate a charge –q. The charge q is proportional to the potential difference
between the plates of the capacitor, the constant of proportionality is called the
capacitance (farad F).
q(t) = C vC(t)
Differentiating both sides of this equation with respect to t and using the fact that
i = dq/dt we get dvC/dt = iC / C. We can write this equation in terms of differences
rather than differentials
260ah.doc 15/05/17 3:51 AM
1
vC (t )  iC (t ) t / C
Thus, a capacitor will resist changes in the potential difference across it because it
requires a time t for the potential difference to change by vC. The potential
difference across the capacitor decreases when it discharges and increases when
charging. The larger the value of C, the slower the change in potential. If t is
“small”, then to a good approximation, the potential difference across the capacitor at
time t is
vC (t )  vC (t  t )  iC (t  t ) t / C
An inductor can be considered to be a coil of wire. When a varying current passes
through a coil, a varying magnetic flux is produced and this in turn induces a potential
difference across the inductor. This induced potential difference opposes the change
in current. The potential difference across the inductor is proportional to the rate of
change of the current, where the constant of proportionality L is known as the
inductance of the coil (henries H) and is given by the equation
vL = L di/dt
This equation can be expressed in terms of differences,
iL(t) = vL(t) t / L
Thus, an inductor will resist changes in the current through it because it requires a
time t for the current to change by i. If t is “small”, then to a good approximation,
the current through the inductor at time t is
iL (t )  iL (t  t )  vL (t  t ) t / L
260ah.doc 15/05/17 3:51 AM
2
SERIES RC CIRCUIT
R
vs
C
Kirchhoff’s Laws with the equation
vC (t )  vC (t  t )  iC (t  t ) t / C
can be used to compute the response of a series RC circuit for different applied emfs.
The first step is calculate the applied emf vs and then specify the initial values for the
variables for voltage v, current i, powers p and energies u.
vS(0)
vC(0) = 0
assume capacitor is initially discharged
i(0) = { vS(0) – vC(0) } / R
vR(0) = i(0) R
pS(0) = vS(0) i(0)
pR(0) = vR(0) i(0)
pC(0) = vC(0) i(0)
uS(0) = 0
uR(0) = 0
uC(0) = 0
Values at all later times are found by implementing the routine in the order shown
vC (t )  vC (t  t )  iC (t  t ) t / C
i (t )   vS (t )  vC (t )  / R
vR (t )  i (t ) R
pS (t )  vS (t ) i (t )
pC (t )  vC (t ) i (t )
pR (t )  vR (t ) i (t )
i t 1
uS (t )   pSi t  pS (t ) t
i 1
i t 1
uC (t )   pCi t  pC (t ) t
i 1
i t 1
uR (t )   pRi t  pR (t ) t
i 1
For accurate results the time increment t should be chosen so that
t << R C where R C is the capacitive time constant.
260ah.doc 15/05/17 3:51 AM
3
MATHLAB FILE FOR SERIES RC CIRCUIT
%m260ah.m
%1 feb 01
%numerical analysis of an RC circuit
tic
R = 500;
C = 1e-6;
tau = R*C;
dt = 1e-5;
%time constnat
%time increment
dt << RC;
%construction of a rectangular pulse
num = 500;
%number of points 1 to 500
T = 3;
%number of periods
ontime = 50; %percentage of time pulse is on - must be less than 100;
numT = round(num/T-0.5);
%number of points for period
ton = round(numT*ontime/100);
%on time expressed as number of
points
toff = numT - ton;
%off time expressed as number of points
vs = zeros(num,1);
vmax = 2;
%set voltages to zero
%set max on voltage
for c = 1 : T
vs(toff+numT*(c-1):toff+numT*(c-1)+ton) = vmax;
end
%zero variables
t = zeros(num,1);
i = zeros(num,1);
vr = zeros(num,1);
vc = zeros(num,1);
ps = zeros(num,1);
pr = zeros(num,1);
pc = zeros(num,1);
us = zeros(num,1);
ur = zeros(num,1);
uc = zeros(num,1);
%calculations
time = 0:dt:dt*(num-1);
for c = 2 : num
vc(c) = vc(c-1)+i(c-1)*dt/C;
i(c)= (vs(c)-vc(c))/R;
vr(c) = i(c)*R;
end
ps = vs .* i;
pc = vc .* i;
pr = vr .* i;
for c = 2 : num
us(c) = us(c-1)+ps(c)*dt;
uc(c) = uc(c-1)+pc(c)*dt;
ur(c) = ur(c-1)+pr(c)*dt;
260ah.doc 15/05/17 3:51 AM
4
end
%graphing
figure(1);
plot(time',vs);
axis([0 dt*num -2.5, 2.5]);
title('RC CIRCUIT');
xlabel('time t (s)');
ylabel('voltage (V)');
grid on;
hold on;
plot(time',vc,'m');
plot(time',vr,'k');
legend('Vs','Vc','Vr');
figure(2);
plot(time',ps);
title('RC CIRCUIT');
xlabel('time t (s)');
ylabel('power P (W)');
grid on;
hold on;
plot(time',pc,'m');
plot(time',pr,'k');
legend('Ps','Pc','Pr');
figure(3);
plot(time',us);
title('RC CIRCUIT');
xlabel('time t (s)');
ylabel('energy U (J)');
grid on;
hold on;
plot(time',uc,'m');
plot(time',ur,'k');
legend('Us','Uc','Ur');
toc
260ah.doc 15/05/17 3:51 AM
5
RC CIRCUIT
2.5
2
1.5
1
voltage (V)
0.5
0
-0.5
-1
-1.5
Vs
Vc
Vr
-2
-2.5
0
0.5
1
1.5
2
-3
8
2.5
time t (s)
3
3.5
4
4.5
5
-3
x 10
RC CIRCUIT
x 10
Ps
Pc
Pr
6
power P (W)
4
2
0
-2
-4
-6
0
0.5
260ah.doc 15/05/17 3:51 AM
1
1.5
2
2.5
time t (s)
3
3.5
4
4.5
5
-3
x 10
6
-6
9
RC CIRCUIT
x 10
Us
Uc
Ur
8
7
6
energy U (J)
5
4
3
2
1
0
-1
0
0.5
260ah.doc 15/05/17 3:51 AM
1
1.5
2
2.5
time t (s)
3
3.5
4
4.5
5
-3
x 10
7
PARALLEL TUNED LC CIRCUIT
R
vS
C
L
RL
Kirchhoff’s Laws with the equations
vC (t )  vC (t  t )  iC (t  t ) t / C
iL (t )  iL (t  t )  vL (t  t ) t / L
can be used to compute the response of a parallel tuned LC circuit for difference
applied emfs. The first step is calculate the applied emf vS and then specify the initial
values for the variables for voltages v, current i, powers p and energies u.
vS(0) = vR(0)
vp(0) = 0
iR(0) = vR(0) / R
assume capacitor is initially discharged
iRL(0) = vp(0) / RL = 0 iL(0) = 0 iC(0) = iR(0)
pS(0) = vS(0) i(0) pR(0) = vR(0) i(0)
uS(0) = 0
uR(0) = 0
uC(0) = 0
pC(0) = vC(0) i(0) pRL(0) = vRL(0) i(0)
uR(0) = 0
Values at all later times are found by implementing the routine in the order shown
vp (t )  vp (t  t )  iC (t  t ) / C
vR (t )  vS (t )  vp (t )
iR (t )  vR (t ) / R
iRL (t )  vp (t ) / RL
iL (t )  iL (t  t )  vp (t  t ) t / L
iC (t )  iR (t )  iRL (t )  iL (t )
pS (t )  vS (t ) iR (t )
pR (t )  vR (t ) i (t )
pRL (t )  vRL (t ) i (t )
pC (t )  vC (t ) i (t )
pL (t )  vL (t ) i (t )
For accurate results the tine increment t should be chosen so that
t << 1 / f
where f is the frequency of the emf.
260ah.doc 15/05/17 3:51 AM
8
MATLAB FILE FOR PARALLEL TUNERD CIRCUIT
%m260aj.m
%2 feb 00
%parallel tuned LC circuit with load resistor
%numerical analysis - leap frog method
%sinusoidal emf
tic
clear;
%data
R = 1000;
RL = 1e3;
C = 1e-8;
L = 3.8e-3;
vSo = 10;
f = 25e3;
period = 1/f;
%emf amplitude
%emf frequency
tmax = 4/f;
%max time interval for calculations and graphs
num = 500;
%number of data points 1 to 500
dt = tmax / (num-1);
t = 0 : dt : tmax;
vS = vSo .*sin((2*pi*f).*t);
%initialise values
vR(1) = vS(1);
vp(1) = 0;
%voltage across parallel combination
iR(1) = vR(1)/R;
iC(1) = iR(1);
iL(1) = 0;
iRL(1) = 0;
%calculations
for c = 2 : num
vp(c) = vp(c-1) + iC(c-1)*dt/C;
vR(c) = vS(c) - vp(c);
iR(c) = vR(c)/R;
iRL(c) = vp(c)/RL;
iL(c) = iL(c-1) + (vp(c-1))*dt/L;
iC(c) = iR(c)-iRL(c)-iL(c);
end
pRL = vp .*iRL;
pR = vR .*iR;
pS = vS .*iR;
pC = vp .*iC;
pL = vp .*iL;
figure(1);
plot(t,vp);
title('Parallel LC Tuned Circuit');
xlabel('time t (s)');
ylabel('potential difference
V
(V)')
hold on;
260ah.doc 15/05/17 3:51 AM
9
plot(t,vS,'m');
figure(2);
plot(t,pRL,'k');
title('Parallel LC Tuned Circuit');
xlabel('time t (s)');
ylabel('power
P
(W)')
hold on;
plot(t,pS,'b');
plot(t,pR,'m');
plot(t,pC,'g');
plot(t,pL,'c');
legend('RL','S','R','C','L');
%accuracy of model
dt << period
fo = 1/(2*pi*sqrt(L*C))
period
dt
%max power transferred to load
w = 2*pi*f;
z1 = R;
z2 = -j/(w*C);
z3 = j*w*L;
z4 = 1/(1/z2+1/z3);
zth = 1/(1/z1+1/z4);
zthreal = real(zth)
Thevenin circuit theorem
toc
Parallel LC Tuned Circuit
10
8
6
potential difference V (V)
4
2
0
-2
-4
-6
-8
-10
0
0.2
260ah.doc 15/05/17 3:51 AM
0.4
0.6
0.8
time t (s)
1
1.2
1.4
1.6
-4
x 10
10
Parallel LC Tuned Circuit
0.08
RL
S
R
C
L
0.06
power P (W)
0.04
0.02
0
-0.02
-0.04
0
0.2
260ah.doc 15/05/17 3:51 AM
0.4
0.6
0.8
time t (s)
1
1.2
1.4
1.6
-4
x 10
11