Skip to content

Differential equations and analog systems

Write the RC circuit's equation, read its time constant off a charging curve, split the answer in two, and see its discrete copy.

Before this3.4 · 5.3 · 6.1 · 3 more
Chapter 6 · Lesson 2 of 3

First, the picture

A tank fills from a reservoir through a narrow pipe. Watch the gap to full, and how fast the level climbs as the gap shrinks.

A tank and a capacitor, filling

The further from full, the faster it fills. RC = 1 s, battery 1 V.

0.00 / 8.00 s
Describe this picture

The reservoir, the pipe and the tank, with a small circuit beside them, and the voltage curve, for RC=1RC = 1 s and a 1 V battery. A point travels along the curve, with a bar from the point up to 1 V marked “gap”. Two readouts show “gap” in volts and “speed” in volts per second. At the start both show 1.000, and the caption says “The tank is empty, so the gap is biggest and it fills fastest.” At t=5t=5 s the caption says “Still not there: the gap shrinks but never closes.” The clip plays once by itself; when it ends, a handle ”↔ drag the point” appears, and the point can be dragged along the curve to try other moments.

A tank that fills more slowly as it fills

The page Difference equations (6.1) counted time in samples. A circuit has no samples, because its voltage changes at every instant. Here I write the rule for such a circuit, and at the end I show how it ties to the leaky integrator of 6.1.

Start with a tank. It is filled from a reservoir through a narrow pipe, the reservoir level is 1, and the tank starts empty. Water flows fast at first, because the difference in level is large. As the tank fills, the difference shrinks and the flow slows: the further from full, the faster it fills.

An electric circuit does the same. The tank is a capacitor, which stores charge, and the voltage across it plays the part of the level. The pipe is a resistor of resistance RR, and the reservoir is a battery. This is the RC circuit from Continuous-time convolution (5.3). There I drove it with a spike of current; here the battery pushes current through the resistor, and that current is the gap divided by RR.

I call the voltage still missing the gap. It is the battery voltage VV minus the capacitor voltage vv, so the gap is V−vV-v.

Go back to the picture at the top of the page. At the start the gap and the speed both read 1.000, the biggest of the run. At t=1t=1 s the voltage is 0.6320.632 V, and the gap and the speed have both fallen to 0.3680.368. At t=5t=5 s the gap is 0.0070.007 V, small but not zero. The two readouts show the same number only because RC=1RC=1 s.

Turning the picture into an equation

I need a symbol for the speed. Write v˙\dot v for dv/dtdv/dt, the slope of the voltage curve, in volts per second. Two facts about a circuit then give the equation. The voltage across the resistor is the gap, so the current is i=(V−v)/Ri=(V-v)/R (Ohm’s law). The current into the capacitor is i=C v˙i=C\,\dot v, where CC is its capacitance.

The same current flows through both, so C v˙=(V−v)/RC\,\dot v=(V-v)/R. Multiply by RR and move vv to the left. For a battery that stays at VV, or for any source voltage vin(t)v_\text{in}(t), this reads

RC v˙+v=vin.RC\,\dot v+v=v_\text{in}.

This is a differential equation: an equation that has the slope of the unknown curve in it. Its answer is a whole curve, one voltage for every instant, as the answer to a difference equation is a whole row of stems. In words, the slope is the gap divided by RCRC. That sentence is the picture at the top of the page: a big gap gives a steep curve, and a small gap gives a flat one.

The time constant

Two circuits can use the same equation and still behave very differently. A camera flash charges its capacitor in a few seconds, and a slow timer takes minutes. The difference is the product RCRC, the resistance times the capacitance, in seconds.

To see what RCRC does, draw the tangent at the start of the curve. Its slope is the starting speed, V/RCV/RC. If the curve kept that speed, it would reach VV after exactly RCRC seconds.

Watch where the tangent meets the 1 V line, and the marker on the curve directly below it, as RCRC grows.

One curve, stretched sideways

The tangent at the start meets 1 V one RC later.

0.00 / 7.00 s
Describe this picture

The charging curve and the line labelled “tangent”, starting at RC=0.5RC=0.5 s with the readout “RC = 0.50 s”. The tangent meets the 1 V line at 0.50.5 s, and a marker labelled “RC” sits on the curve directly below that meeting, at 0.6320.632, labelled 63.2%. During the run RCRC grows from 0.50.5 s to 22 s; the curve, the tangent and the marks stretch sideways together, and marks at 2, 3 and 5 time constants read 86.5%, 95.0% and 99.3%. When it ends, the handle ”↔ drag the 63.2% marker” appears, and dragging the marker sets RCRC.

The marker is at 0.6320.632: by one RCRC the curve has covered 63.2 % of the way. We call this time the time constant, and I write it τ=RC\tau=RC.

As RCRC grows, the curve, the tangent and the marks stretch sideways together, as one shape. This is the time scaling of Shifting, reversing and scaling time (2.1). When the clip ends, drag the marker to set RCRC yourself, and notice that the shape never changes. Only the horizontal scale does.

The same percentages appear at every circuit, counted in time constants:

TimeShare of the way covered
1τ1\tau63.2 %
2τ2\tau86.5 %
3τ3\tau95.0 %
4τ4\tau98.2 %
5τ5\tau99.3 %

The curve itself is v(t)=V (1−e−t/RC)v(t)=V\,(1-e^{-t/RC}) for t≥0t\ge0 when the battery is switched on at t=0t=0 with the capacitor empty. You can check it against the equation. The gap is V e−t/RCV\,e^{-t/RC}, and the slope of the curve is VRCe−t/RC\frac{V}{RC}e^{-t/RC}, which is the gap divided by RCRC. It also starts at 0, as the empty capacitor does. This agrees with the pulse example in 5.3, where RC=1RC=1 s gave y(t)=1−e−ty(t)=1-e^{-t} while the pulse was on.

The curve never reaches VV, because the gap V e−t/RCV\,e^{-t/RC} is positive for every tt. At 5τ5\tau it is 0.7 % of VV. That is small enough to ignore in practice, but the equation never says “full”.

How long does the curve take to reach 90 %? Then the gap is 10 % of what it started as, so e−t/τ=0.1e^{-t/\tau}=0.1. Here I use ln⁡\ln, the natural-log key on a calculator. It undoes ee: if e−t/τ=qe^{-t/\tau}=q, then t=−τln⁡qt=-\tau\ln q. (The log⁡10\log_{10} of How big is a signal (1.3) is the other key, used for decibels.) With q=0.1q=0.1 this gives t=2.303 τt=2.303\,\tau.

Natural part and forced part

Now start the capacitor already holding 0.50.5 V, and connect the 1 V battery. The gap is only half as big as before. Take a warm cup of tea: in a cold room it cools to the cold level, and in a warm room it cools to a warmer level. The room sets where it ends up, and the cup’s own start sets the rest.

Before you watch, make a guess. After one RCRC, will the capacitor have covered more than, less than, or exactly 63.2 % of its gap?

Where it is heading, minus the gap

The capacitor starts at 0.5 V; RC = 1 s, battery 1 V.

0.00 / 10.00 s
Describe this picture

The capacitor starts at 0.5 V, with RC=1RC = 1 s and a 1 V battery. The total is drawn first, a curve from 0.50.5 V up to 1 V. Then it separates into two pieces: the flat line at 1 V, tagged “forced: slope zero here”, and a fading piece below the axis, tagged “natural: minus the gap”, with a bar marked “gap 0.5” beside it showing the same length with the sign flipped. The last frame adds an inset titled “A different cut, at t = 1 s”, with the lines “stored charge leaking away 0.184”, “charge-up from empty 0.632” and “also 0.816”.

The total curve separates into two pieces: a flat line at 1 V, and a fading piece below the axis that is the gap with its sign flipped.

The forced part is the level the battery insists on. It is the only voltage at which the slope is zero, because RC v˙+v=VRC\,\dot v+v=V with v˙=0\dot v=0 gives v=Vv=V. The natural part is what the circuit does when the battery has no say. It solves the equation with the right side set to 0, RC v˙+v=0RC\,\dot v+v=0, which is called the free equation.

To find the natural part, try este^{st}. In Complex exponentials & phasors (3.4) the exponent had a spin, and este^{st} was a spiral. With no spin the spiral does not turn, and este^{st} is a plain decay, so here ss is a real number. Its slope is ddtest=s est\frac{d}{dt}e^{st}=s\,e^{st}, so the free equation becomes

RC s est+est=0.RC\,s\,e^{st}+e^{st}=0.

Divide by este^{st} and you get RC s+1=0RC\,s+1=0, so s=−1/RCs=-1/RC. The natural part is a constant times e−t/RCe^{-t/RC}. I call that constant bb, because CC is already the capacitance.

Adding the two parts gives v=V+b e−t/RCv=V+b\,e^{-t/RC}. The sum solves the full equation, because the equation is linear: the forced part leaves VV on the right, and the natural part adds nothing. The start value fixes bb. Here V=1V=1 and v(0)=0.5v(0)=0.5, so 1+b=0.51+b=0.5 and b=−0.5b=-0.5:

v(t)=1−0.5 e−t/RC.v(t)=1-0.5\,e^{-t/RC}.

The natural part, −0.5 e−t/RC-0.5\,e^{-t/RC}, is minus the gap: it is the gap bar from the start of this page with its sign flipped. At t=RCt=RC the gap has shrunk by the same 63.2 % as before. It closed 0.3160.316 of its 0.50.5, so the answer to the guess is exactly 63.2 %, and the voltage is 0.8160.816 V.

6.1 also cut an answer in two, but with a different cut. There the pieces were what the stored charge does alone (the zero-input response, with the source off) and what the source does from an empty capacitor (the zero-state response). Here the pieces are where the voltage is heading and the gap that remains. Both cuts add up to the same curve.

For this circuit at t=1t=1 s, the stored 0.50.5 V leaks to 0.5 e−1=0.1840.5\,e^{-1}=0.184 and the charge-up from empty is 1−e−1=0.6321-e^{-1}=0.632. Their sum is 0.8160.816, the same number as 1−0.1841-0.184. The last frame of the picture shows this cut too.

The same equation in a spring

The next instrument has no new idea. It shows that a different physical system gives the same kind of equation, with a second slope in it. I write x¨\ddot x for d2x/dt2d^2x/dt^2, the slope of the slope. For a mass on a spring it is the acceleration.

Take a mass mm on a spring of stiffness kk, with a damper of strength cc: a piston in oil that pushes back against the speed. Newton’s law says the mass times the acceleration equals the sum of the forces, −kx-kx from the spring and −cx˙-c\dot x from the damper. With xx the distance from rest (here xx is a position, not an input), this gives

mx¨+cx˙+kx=0.m\ddot x+c\dot x+kx=0.

Now take a circuit with a coil, a resistor and a capacitor in a row. A coil’s voltage is LL times how fast its current changes, vL=L di/dtv_L=L\,di/dt. It resists changes of current the way a mass resists changes of speed. With the capacitor current i=Cv˙i=C\dot v, the loop of voltages gives LC v¨+RC v˙+v=0LC\,\ddot v+RC\,\dot v+v=0 when the source is off.

The two equations have the same shape, so I pair the parts. The mass goes with the inductance LL, the damper with the resistance RR, and the spring stiffness with 1/C1/C. A car suspension is the mechanical one, and a radio tuner is the electrical one.

Watch the mass swing, and the two lines on the plot.

A spring and a circuit, one curve

A mass on a spring with a damper, and a coil, a resistor and a capacitor.

A mass on a spring, pulled aside. Next to it, a coil, a resistor and a capacitor.

0.00 / 8.00 s
Describe this picture

A mass on a spring with a damper, and next to it a coil, a resistor and a capacitor. The mass starts pulled aside and is released, with the caption “A mass on a spring, pulled aside. Next to it, a coil, a resistor and a capacitor.” It swings, and the swings shrink. The plot has a solid line labelled “mass position” and a dashed line labelled “capacitor voltage”, and the caption ends “The mass and the capacitor voltage trace one curve.”

The swings shrink, and the dashed capacitor voltage lies on the solid mass position: they trace one curve.

I chose m=1m=1 kg, c=1c=1 N⋅\cdots/m and k=25k=25 N/m for the spring, and L=1L=1 H, R=1 ΩR=1\ \Omega and C=0.04C=0.04 F for the circuit. Since 1/C=251/C=25, both equations become y¨+y˙+25y=0\ddot y+\dot y+25y=0, with yy standing for the distance or the voltage. Why it swings, and how fast the swings shrink, is the job of First- and second-order systems (6.3).

A circuit and its discrete copy

DSP students keep analog circuits around for a practical reason. Often a program has to imitate one, such as a smoothing filter in a sensor, and the program runs in steps. The leaky integrator of 6.1 turns out to be the exact step-by-step copy of the RC circuit.

Here is the setting. Hold the input constant over each interval of TsT_s seconds, and let x[n]x[n] be its value in interval nn. For a constant input that is the sample xc(nTs){x_c(nT_s)} of Sinusoids (3.2). Over one interval the gap shrinks by the factor e−Ts/RCe^{-T_s/RC}, because a gap that starts at gg is g e−t/RCg\,e^{-t/RC} after tt seconds, as in the natural part above. Call this factor aa.

Let y[n−1]y[n-1] be the voltage at the start of the interval. The gap at the start is x[n]−y[n−1]x[n]-y[n-1], and at the end it is aa times that, so the voltage at the end is

y[n]=x[n]−a(x[n]−y[n−1]).y[n]=x[n]-a\bigl(x[n]-{y[n-1]}\bigr).

Rearranged, this is exactly the leaky integrator of 6.1:

y[n]=a y[n−1]+(1−a) x[n],a=e−Ts/RC.y[n]=a\,{y[n-1]}+(1-a)\,x[n],\qquad a=e^{-T_s/RC}.

Because y[n−1]y[n-1] is the voltage at nTsnT_s, the output y[n]y[n] is the voltage at the end of interval nn: y[n]=v((n+1)Ts)y[n]={v\bigl((n+1)T_s\bigr)}. The empty capacitor, v(0)=0v(0)=0, is initial rest, y[−1]=0y[-1]=0.

Here is a concrete check. Take RC=1RC=1 s and sample every Ts=0.5T_s=0.5 s, so a=e−0.5=0.6065a=e^{-0.5}=0.6065. The plot in the next instrument is in seconds, not sample numbers. Output y[0]y[0] is worked out from the input held over the first half-second, so it is the voltage at the end of that half-second. The first stem stands at 0.50.5 s, and stem nn stands at (n+1)Ts(n+1)T_s.

We sample the circuit every 0.50.5 s with this recursion. Will the stems be on the curve, or only near it?

The circuit and its discrete copy

Sampled every 0.5 s by the leaky integrator of 6.1.

A circuit with RC = 1 s. Sample it every 0.5 s.

0.00 / 10.00 s
Describe this picture

The charging curve, labelled “circuit, RC = 1 s”. One after another, a stem drops onto the curve at t=0.5, 1.0, 1.5t=0.5,\ 1.0,\ 1.5 s and so on, labelled with its sample number nn and, under the axis, its value. Above the plot, the arithmetic of the newest stem is written out, and a caption says what the newest stem shows.

The second stem is the check. With four-digit numbers the recursion gives 0.6065×0.3935+0.3935=0.63220.6065\times0.3935+0.3935=0.6322, which is the value of the curve at t=1.0t=1.0 s, and the caption says so. The stems do not just resemble the curve. They are exactly on it, at the end of each half-second, up to the eighth stem at 0.9820.982.

For a step input, every x[n]=1x[n]=1, so the recursion gives y[n]=1−an+1y[n]=1-a^{n+1}, the step response of 6.1’s leaky integrator. In the circuit’s own terms, 1−an+1=1−e−(n+1)Ts/RC1-a^{n+1}=1-e^{-(n+1)T_s/RC}, which is v((n+1)Ts)v\bigl((n+1)T_s\bigr) from the continuous curve. The tie between the two systems is a single line, a=e−Ts/RCa=e^{-T_s/RC}.

Worked example

  1. Step response, RC=1RC=1 s. With V=1V=1 V, v(t)=1−e−tv(t)=1-e^{-t}. At t=1,2,3,4,5t=1,2,3,4,5 s it is 0.63212, 0.86466, 0.95021, 0.98168 and 0.99326 V, so the gap at t=5t=5 s is 0.006740.00674 V. The slope at t=1t=1 s is e−1=0.36788e^{-1}=0.36788 V/s, so the tangent there reaches 0.63212+0.36788×1=10.63212+0.36788\times1=1 at t=2t=2 s: one RCRC later, as at every point. Time to 90 %: e−t=0.1e^{-t}=0.1, so t=ln⁡10=2.3026t=\ln10=2.3026 s.
  2. A fast circuit. Take RC=2RC=2 ms switched onto 5 V. After one time constant, v=5 (1−e−1)=3.16v=5\,(1-e^{-1})=3.16 V. It reaches 90 % of 5 V, which is 4.5 V, at t=2.3026×2t=2.3026\times2 ms =4.61=4.61 ms.
  3. Pre-charged, natural plus forced. Try este^{st} in RC v˙+v=0RC\,\dot v+v=0: s=−1/RCs=-1/RC. The slope is zero at v=1v=1, the forced part. So v=1+b e−t/RCv=1+b\,e^{-t/RC}, and 1+b=0.51+b=0.5 gives b=−0.5b=-0.5: v(t)=1−0.5 e−t/RCv(t)=1-0.5\,e^{-t/RC}. For RC=1RC=1 s, v(1)=1−0.18394=0.81606v(1)=1-0.18394=0.81606 V. The other cut gives zero-input 0.5 e−1=0.183940.5\,e^{-1}=0.18394 plus zero-state 1−e−1=0.632121-e^{-1}=0.63212, which is also 0.816060.81606. The gap of 0.50.5 closed by 0.3160.316, which is 0.316/0.5=63.20.316/0.5=63.2 %.
  4. Spring and circuit, only the pairing. The spring has m=1, c=1, k=25m=1,\ c=1,\ k=25 and the circuit has L=1, R=1, C=0.04L=1,\ R=1,\ C=0.04, so 1/C=251/C=25. Both are y¨+y˙+25y=0\ddot y+\dot y+25y=0. The swing and its decay are worked out in 6.3.
  5. Discrete copy. With Ts=0.5T_s=0.5 s and RC=1RC=1 s, a=e−0.5=0.60653a=e^{-0.5}=0.60653. Then y[0]=1−a=0.39347=v(0.5)y[0]=1-a=0.39347=v(0.5). Next, y[1]=0.60653×0.39347+0.39347=0.63212=v(1.0)y[1]=0.60653\times0.39347+0.39347=0.63212=v(1.0). In general y[n]=1−an+1y[n]=1-a^{n+1}, so y[2]=0.77687y[2]=0.77687, y[3]=0.86466y[3]=0.86466 and y[7]=0.98168=v(4.0)y[7]=0.98168=v(4.0).

Where you’ll meet this

Many analog sensor inputs and audio outputs contain a resistor and a capacitor, so the equation of this page describes them. A microcontroller that smooths a sensor with y[n]=a y[n−1]+(1−a) x[n]y[n]=a\,{y[n-1]}+(1-a)\,x[n] is running this circuit in code, at the cost of two multiplications per sample. You choose aa from the time constant you want with a=e−Ts/RCa=e^{-T_s/RC}.

Later chapters build on this page. The filter that comes before a converter, to remove frequencies it cannot represent, is an analog circuit like this one; see Anti-aliasing and practical converters (10.4). Digital filters designed from analog circuits start from the equations here, in Analog prototype filters (20.1) and IIR design by the bilinear transform (20.2). And The Laplace transform (9.1), which turns este^{st} and a differential equation into algebra, extends the “try este^{st}” step of the natural part.

The next page, First- and second-order systems (6.3), takes the spring above and puts numbers on its swing.

The maths behind it · eigenfunctions and null spaces

The function este^{st} is an eigenfunction of d/dtd/dt: its derivative is ss times itself. That is why trying este^{st} in a linear equation with constant coefficients turns calculus into a polynomial in ss. The natural part solves the free equation, which is the null space of the operator. The forced part is one particular solution, and every solution is a particular one plus a null-space one, exactly as for Ax=b\mathbf{A}\mathbf{x}=\mathbf{b}. A second-order equation is a system with a 2×22\times2 matrix, and its eigenvalues are those values of ss.

The maths behind it · the exponential distribution

The charging curve 1−e−t/τ1-e^{-t/\tau} is the cumulative distribution function of the exponential distribution, the probability that a random waiting time is at most tt. Its mean waiting time is τ\tau. So 63.263.2 % of the waits are shorter than the mean, the same percentage as one time constant.

Reference card

QuantityFormulaNotes
RC circuit (voltage across CC)RC v˙+v=vinRC\,\dot v+v=v_\text{in}slope = (target − vv)/RCRC; v˙=dv/dt\dot v=dv/dt
Time constantτ=RC\tau=RCthe starting tangent reaches the target at τ\tau; 63.2 % of the gap in τ\tau
Step responsev(t)=V (1−e−t/τ)v(t)=V\,(1-e^{-t/\tau})63.2, 86.5, 95.0, 98.2, 99.3 % at τ\tau to 5τ5\tau; never exactly 100 %
Impulse responseh(t)=1RCe−t/RCu(t)h(t)=\tfrac1{RC}e^{-t/RC}u(t)as in 5.3
Time to share pp of the final valuet=−τln⁡(1−p)t=-\tau\ln(1-p)ln⁡\ln undoes ee; 90 % at 2.303 τ2.303\,\tau
Natural and forcedv=vforced+vnaturalv=v_\text{forced}+v_\text{natural}forced: slope zero, v=Vv=V. Natural: b e−t/τb\,e^{-t/\tau}, minus the gap; bb from v(0)v(0)
Two cuts of one answernatural plus forced, or zero-input plus zero-statesame total, different pieces
Mass, spring, dampermx¨+cx˙+kx=0m\ddot x+c\dot x+kx=0x¨=d2x/dt2\ddot x=d^2x/dt^2
Series RLC (across CC)LC v¨+RC v˙+v=vinLC\,\ddot v+RC\,\dot v+v=v_\text{in}m↔Lm\leftrightarrow L, c↔Rc\leftrightarrow R, k↔1/Ck\leftrightarrow1/C
Discrete copya=e−Ts/RCa=e^{-T_s/RC}, y[n]=a y[n−1]+(1−a) x[n]y[n]=a\,{y[n-1]}+(1-a)\,x[n]y[n]=v((n+1)Ts)y[n]={v((n+1)T_s)} for an input held over each interval; first stem at TsT_s

End of lesson 6.2

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look