A5 · Lesson 55 · Project: characterizing a capacitor discharge
From a noisy record to a time constant, an energy and a deadline
A capacitor of unknown value discharges through a known 1 kΩ resistor, and a logger records its voltage every half millisecond, with 1% noise on each reading. From that record alone you'll find the time constant and the starting voltage, the energy the resistor absorbed, the moment the voltage fell below 1 V, and the current partway through. Every part of the course comes in: logarithms and a straight-line fit, integrals of data, an exponential's tail, and a derivative of noisy samples.
- The plot shows against time for a discharge from 9 V. A pure exponential turns into a straight line, of slope and intercept .
- Change the time constant (in ms) and watch the slope change. The readout gives the slope.
- Noise in the readings scatters points about this line; a straight-line fit through all of them recovers the slope and intercept.
Predict
The fit gives , with in seconds. What are the time constant and the starting voltage?
10 ms and 9.0 V. The slope is , so s = 10 ms. The intercept is , so V. The resistor is 1 kΩ, so the capacitor is µF.
Name it
The plan
- Fit. Take and fit a straight line by least squares:
Then , and .
- Energy. The resistor absorbs . Integrate the record by Simpson's rule, add the tail past the end of the record from the fit, , and compare with the energy the capacitor started with, .
- Deadline. The fit says falls to 1 V at . The data say it at the first sample below 1 V, interpolated with the one before.
- Current. At 10 ms, compare from the data with from the fit.
Why fit in logs
Fitting a line to turns a curve fit into the straight-line formulas above. The price is that 1% noise on becomes about 0.01 of noise on at every sample, so late samples, where is small, count as much as early ones. With multiplicative noise like this, that's fair; with a fixed noise floor it would give the tail too much weight.
Worked example
A fit returns per second and . What are , and with = 1 kΩ, and when does the voltage reach 1 V?
Show the solution
- Time constant.
- Starting voltage.
- Capacitance.
- Time to reach 1 V.
Answer ms, V and µF, and the voltage reaches 1 V at 21.6 ms.
Worked example
The record is 50 ms long, five time constants of 10 ms. How much energy does it leave out?
Show the solution
- Energy in the tail. The tail past = 50 ms holds
- Compare with the total. Against a total of 0.405 mJ, that's 0.005%.
- Why so little. Five time constants capture all but of the energy, since the energy decays twice as fast as the voltage.
Answer the record leaves out J, 0.005% of the 0.405 mJ total.
Check
A straight-line fit to against (in seconds) has slope −100 and intercept 1.6. What is the time constant?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
With the same fit (slope −100, intercept 1.6), when does the voltage fall to 1 V?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
The starter makes the logged record t, v. Fit a line to by least squares (write the formulas yourself) and set tau, V0 and C (with R = 1000 Ω).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the record and your fit (copied into the starter), set E_data to over the record by Simpson's rule, E_tail to the fit's tail past the end, , and E_cap to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With the same record and fit, set t_fit to the time the fit says the voltage reaches 1 V, and t_data to the first crossing below 1 V in the data, interpolated linearly between that sample and the one before.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
At = 10 ms (sample 20), set i_data to the current from a central difference of the data, , and i_fit to from the fit. Then set true to the noise-free value, , and better to "fit" or "data", whichever is closer.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
How noisy were the readings? Using the fit from the starter, set res to the residuals , and noise to their standard deviation (the formula, since the fit used two parameters). For 1% noise on , it should come out near 0.01.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
The project found the current at 10 ms two ways, and the fit won by a wide margin. When would you trust the central difference instead?
The fit wins here because the data really are an exponential plus small random noise, so a two-parameter model fitted to all 101 samples averages the noise away, while a central difference uses just two samples and divides their noise by a small time step, magnifying it. The difference would be the better choice when the model is wrong or unknown: if the discharge had a second, slower component, or the resistor heated and changed value, the exponential fit would describe the wrong curve, however precisely, and its derivative would be wrong everywhere. A difference makes no assumption about the shape. With noisy data the honest compromise is to smooth or fit locally (a few neighboring samples) and differentiate that, trading a little bias for much less noise.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.