52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

An equation to generate the output of a driven RC circuit.

Thu Feb 16, 2017 7:52 am

This is more about mathematics and electronics, but I'd like to use Mathematica to generate the graphs I need. It's probably something that others might also find useful.

Given: a voltage source Vo with an output of 0V - 5V at a frequency Fclk. One end of a resistor R is connected to Vo, the other end to a capacitor C, the second terminal of C being connected to 0V.

Required: an equation of the form v = f(t) that gives the voltage across the capacitor at time t.

Working: I've only ever solved for a steady voltage using some variant of the standard equation dv/dt = i/C. The standard text-book integration is over the interval (inf - t] and does not address varying voltages. My maths isn't good enough to know where to start with a solution, and I'd be most grateful for any pointers to info or suggestions for a solution.

User avatar
Gert van Loo
Posts: 2440
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 2:48 pm

What you have described is an RC low-pass filter.
Look up in wiki under RC filters. The -3dB point frequency is at 1/(2*PI*R*C).

52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 5:33 pm

The filter analyses I've seen treat the RC combination as a frequency-dependent network, and thus use the frequency domain as the abscissa rather than time, as I require.

The other analyses use a "step" approach. They use starting conditions to plot the v:t curve using the standard exponential function up to the first half-cycle of the waveform, then change the form of the equation to recalculate using the new voltage for the next half-cycle, and repeat this until a steady state becomes evident. This strikes me as rather inelegant, and I've no idea how to insert it into Mathematica to create the graph I want.

On the other hand, I don't know of any mathematical formalism that allows a "continuous" equation to be derived. There may be one in e.g. multivariable calculus, but my knowledge doesn't stretch that far.

The question may be better suited to a maths forum of some sort, and again I don't know of one. Any suggestions along this line would be equally welcome.

User avatar
Gert van Loo
Posts: 2440
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 6:13 pm

I don't understand what you exactly are looking for.
For an arbitrary input signal the voltage over the capacitor is a differential equation which can be
easily solved for some situations like a stead-state Vo or a know frequency.
For arbitrary input signals you have to solve the differential equation like a normal mathematical function.
I assume there are standard program to solve differential equations.

52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 8:09 pm

> can be easily solved for some situations like a stead-state Vo or a know frequency.

Quite so, but this has two independent variables - time and voltage - and is thus a more complex case than those typically found in textbooks and undergraduate courses.

There may well be standard solutions but I haven't found them.

52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 8:34 pm

Tried editing the above but it didn't happen. So ...

Better to say that there are two independent variables - time and current - and one dependent variable - the voltage across the capacitor. The current into and out of the cap is determined by the drive voltage applied to the resistor, which alternates over time.

Standard diff equns are of the form y = dx/dz so integrating with respect to z yields a function x = F(y), typically using a standardized integral.

One possibility is partial differential equations. I've only ever encountered them in the vector analysis of fields, usually dx/dt, dy/dt and dz/dt. Whether or not the technique could be applied here I'm not knowlegeable enough to say.

User avatar
Gert van Loo
Posts: 2440
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 9:55 pm

I've only ever encountered them in the vector analysis of fields
You see them a lot in quantum mechanics.
In principle they are not much different from normal ones if you have a conservative field.
In that case you can differentiate first to one and then the other.

52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 10:54 pm

I posted to a likely looking maths forum in the hope of finding a tame boffin who speaks the vernacular:

http://mymathforum.com/physics/339093-e ... rcuit.html

Meantime, it may be that any solution is going to be complex. If you look at what seems to be simple - the equation of a square wave - it's obviously not so:

http://mathworld.wolfram.com/SquareWave.html

You could perhaps modify this to include the consequences of the RC time constant, though I've no idea how.

User avatar
jojopi
Posts: 3007
Joined: Tue Oct 11, 2011 8:38 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 11:12 pm

52midnight wrote:I've only ever solved for a steady voltage using some variant of the standard equation dv/dt = i/C.
That equation holds in this case too, but now current also is a function of time. In Mathematica syntax:

Code: Select all

equation = v'[t] == i[t] / c
The actual current at any time is simply the potential difference across the resistor, divided by resistance. I take the liberty to rename your input voltage function from Vo to vi[t]:

Code: Select all

i[t] = (vi[t] - v[t]) / r
At this point I believe we have an ordinary differential equation. Everything is a function of time only, and only v[t] has derivatives applied to it. We can already "solve" the equation to get v[t] in terms of (integrals of) vi[t]:

Code: Select all

equation
DSolve[equation, v[t], t]
To plot the results we will have to define the vi[t] function and the remaining variables (I choose 1kΩ, 10nF, 16kHz), and also specify a known capacitor voltage at some point in time to eliminate the constant of integration.

Code: Select all

vi[t] = 2.5 + 2.5 * Sin[2Pi * t * fclk]
r = 1000
c = 10^-8
fclk = 16000
solution = DSolve[{equation, v[0] == 0}, v[t], t]
<<JavaGraphics`
Plot[v[t] /. solution, {t, 0, 1/1000}]
Disclaimer: I am not an expert with Mathematica, and my non-discrete mathematical skills are extremely rusty. I do think this result is correct though. Notice the output is attenuated ~3dB (in terms of power) at the values chosen, where 1/fclk is close to 2Pi*r*c.

At first reading, I wondered whether you intended your vi[t] to be a sawtooth function. I have not been able to model that situation yet.

52midnight
Posts: 22
Joined: Fri Nov 09, 2012 3:46 pm

Re: An equation to generate the output of a driven RC circui

Thu Feb 16, 2017 11:29 pm

Many thanks, jojopi. An unexpected gift!

> Everything is a function of time only

Yes, that's the quickest path to a solution that I anticipated, but didn't know how to find it.

I'll post back after I fire up the Rpi and try it out.

tenochtitlanuk
Posts: 151
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: An equation to generate the output of a driven RC circui

Fri Feb 17, 2017 12:06 am

I know you intend to use Mathematica, but it is indeed very easy to code/simulate in your language/GUI of choice.
I used initial conditions
t =0
dt =1E-6 ' time step 1 microsecond
C =10E-6 ' 10 microfarads
R =1E3 ' 1 kilo ohm ( so time constant is 10 ms)
f =1E2 ' 100 Hz
amp =5 ' 5 volts
and ( pseudocode)
while t <0.1 ' display 0.1 second of action...
I =( Vin( t) -Vout) /R
dQ =I *dt
Q =Q +dQ
Vout =Q /C
t =t +dt
wend
Various input wave shapes are easily generated- I used squares, pulses, sin, Fourier series, and got results like this animation..
Image
You can see the initial transient die away; the phase shift; the low-pass filtering. You'll learn a lot...
EDIT Use 'Show image' to see at full size.

scotty101
Posts: 2389
Joined: Fri Jun 08, 2012 6:03 pm

Re: An equation to generate the output of a driven RC circui

Fri Feb 17, 2017 11:40 am

This website explains first order filters quite well and uses some simple(non-complex) mathematics to work out the voltage output of the filter as frequency varies.

http://www.electronics-tutorials.ws/fil ... ter_2.html
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Mathematica”

Who is online

Users browsing this forum: No registered users and 3 guests