C1127 of 30
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C11 · Lesson 27 · Measurement lab

Statistics, uncertainty and RMS in Python

Modern measurements end up as lists of numbers, from a data logger, a scope's memory or a script that steps an instrument through settings. Turning those numbers into results with honest uncertainties is a few lines of code, and writing them yourself makes clear what the instrument's built-in "mean", "std dev" and "RMS" readouts actually compute. In this lab you'll write three: the mean and its standard error, uncertainty propagation through any formula, and the true RMS and crest factor of a sampled waveform.

  • A pulse train of height A and duty cycle D, sampled. The readouts are what your rms_and_crest will return: the true RMS, AD, and the crest factor, 1/D.
  • Shrink the duty cycle: the RMS falls slowly while the crest factor climbs. A meter rated for a crest factor of 3 misreads pulses below about 11% duty.
  • The dashed line is the RMS level: the DC voltage that would heat a resistor equally.

Predict

Four readings are 1, 2, 3 and 4 V. What is the standard error of their mean?

Name it

Mean and standard error

For N readings, the mean is x¯=∑xi/N, the sample standard deviation is

s=∑(xi−x¯)2N−1

(N − 1 because the mean itself was estimated from the data), and the standard error of the mean is s/N.

Propagation by computer

For a result f(x1,…,xn) with independent uncertainties σi, the quadrature rule of lesson 2 needs the partial derivatives. A program can estimate each one numerically with a central difference,

∂f∂xi≈f(…,xi+h,…)−f(…,xi−h,…)2h

with a small step h scaled to xi, and then combine ∑(∂f/∂xi⋅σi)2. It works for any formula, however messy.

True RMS and crest factor

For samples vk, the RMS is ∑vk2/N over a whole number of periods, and the crest factor is the largest |v| over the RMS. That's exactly what a true-RMS meter or a scope's RMS measurement computes.

Worked example

A resistance is found as V/I with V = 5.00 ± 0.02 V and I = 2.000 ± 0.010 mA. What does numerical propagation give?

Show the solution
  1. Sensitivity to V. ∂R∂V=1I=500Ω/V
  2. Sensitivity to I. ∂R∂I=−VI2=−1.25×106Ω/A
  3. Combine in quadrature. uR2=(500×0.02)2+(1.25×106×10−5)2 so uR=100+156Ω=16Ω
  4. Compare with lesson 2. That's 16 Ω on 2500 Ω, matching lesson 2's 0.64%.

Answer R = 2500 ± 16 Ω.

Worked example

Samples of a 5 V pulse train with 10% duty: what are the RMS and crest factor?

Show the solution
  1. RMS. Vrms=0.1×25V=1.58V
  2. Crest factor. CF=51.58=3.16

Answer 1.58 V RMS, and a crest factor of 3.16.

Check

A set of 5 readings has a sample standard deviation of 1. What is the standard error of their mean?

Check

What is the RMS of a pulse train of height 2 V and duty cycle 0.25?

Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.

Check

Write mean_and_error(xs): return the mean of the list xs and its standard error, using the sample standard deviation (divide by N − 1).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write propagate(f, x, sx): f is a function of len(x) arguments, x the measured values and sx their standard uncertainties. Return the propagated uncertainty of f, using central-difference derivatives and quadrature.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write rms_and_crest(v): return the true RMS of the samples v and the crest factor (largest |v| over the RMS).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does the sample standard deviation divide by N − 1 instead of N?

Practice

Keep practicing

5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.