C11 · Lesson 20 · Instrument lab
What a scope, a counter, a meter and a power analyzer compute, in Python
Modern instruments are computers that sample and calculate. The scope's rise-time readout interpolates between samples, the counter divides counts by times, the cheap meter scales an average and calls it RMS, the power analyzer averages a product, and a frequency standard's data sheet quotes an Allan deviation. In this lab you'll write each of those calculations and test them on signals whose answers are known.
- The curve is the reading of an average-responding meter, which scales the average of |v| by the sine's form factor, , divided by the true RMS, for a train of pulses that are on a fraction D of the time.
- For such pulses the average of |v| is D and the RMS is , so the ratio is : 11% high for steady DC, and only 35% of the truth at a 10% duty cycle.
- A sine gives exactly 1, which is the only waveform such a meter is right for. That's the difference between a meter labeled "true RMS" and one that isn't.
Predict
A load draws a 5 A rms current from 230 V, lagging by 30°, plus a third harmonic. What does the harmonic add to the real power?
Nothing. Real power is the average of v·i, and a 150 Hz current against a 50 Hz voltage averages to zero over a cycle. It does increase the rms current, so the power factor falls: from 0.866 to 0.797 in the lab's test. Harmonic currents load the wiring without delivering energy.
Name it
What each instrument computes
- Rise time: find the signal's low and high levels, then the times where it crosses 10% and 90% of the way between them, interpolating linearly between samples. For a first-order step it's .
- Reciprocal frequency: take the rising-edge times inside a gate; the frequency is the number of whole periods between the first and last edge, divided by the time between them.
- Average-responding meters: compute , which equals the RMS only for a sine.
- Real power and power factor: , and .
- Allan deviation: average the fractional-frequency samples in blocks of m, then . It measures how much the frequency wanders between successive averages of that length.
Worked example
A first-order system has τ = 1 ms. What rise time should the scope report?
Show the solution
- 10% crossing. crosses 10% at
- 90% crossing.
- Rise time.
- Measuring it. Sampling every microsecond and interpolating recovers it to better than 0.1%.
Answer the scope should report a rise time of 2.197 ms.
Worked example
What does an average-responding meter read for a triangle wave of 1 V peak, and what is its true RMS?
Show the solution
- Mean absolute value. A triangle's mean absolute value is half its peak, 0.5 V.
- What the meter reads.
- True RMS.
- The error. The meter is 3.8% low, and it's worse on pulses and noise.
Answer the meter reads 0.555 V, and the true RMS is 0.577 V.
Check
What is the 10–90% rise time of a first-order step with τ = 1 µs?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
Write rise_time(t, v): the 10–90% rise time of a rising step, sampled at times t, interpolating linearly between samples.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write reciprocal_frequency(edges, gate): given rising-edge times, use the edges from the first one up to gate seconds later, and return the number of whole periods between the first and last used edge divided by the time between them.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write average_responding(v): what an average-responding meter, calibrated for sines, reads for the samples v.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write power(v, i): return (P, PF), the real power and the power factor of sampled voltage and current covering whole cycles.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write allan(y, m): the non-overlapping Allan deviation of fractional-frequency samples y for an averaging factor m.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why do stability specifications use the Allan deviation instead of the ordinary standard deviation of frequency readings?
An oscillator's frequency usually drifts, and many oscillators also have noise whose power grows at low frequencies. For such signals the ordinary standard deviation doesn't settle as more data is collected; it keeps growing with the length of the record, so it doesn't describe the oscillator. The Allan deviation compares each average only with the next one, so slow drift contributes only through the change between neighboring blocks, and the result converges. Plotting it against the averaging time shows which process dominates at each time scale: white noise falls as , flicker noise flattens out, and drift rises, which tells a designer how long to average and where a better reference would help.
Practice
Keep practicing
One kind of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.