2. Probability foundations for measurement

Every sensor reading is a random variable. When a thermocouple reports 23.47 °C, that number is one realization drawn from a distribution shaped by thermal noise, quantization, amplifier drift, and environmental disturbance. To reason about measurement uncertainty rigorously, we need a compact language for describing how a reading varies: random variables, probability density functions (PDFs), cumulative distribution functions (CDFs), and expectation. This chapter builds that language and connects each concept to concrete sensor data.

Random variables in the measurement context

A random variable (RV) is a function that maps each outcome of an experiment to a real number. In metrology, the experiment is "take one measurement," and the RV is the value the instrument returns. We distinguish two types:

  • Continuous RVs — voltage, temperature, pressure, strain. Any value in an interval is possible.
  • Discrete RVs — ADC counts, photon counts, packet loss counts. Values come from a countable set.

Notation matters. We write X for the RV itself and x for a specific observed value. A dataset of N samples is written x1, x2, …, xN; each is a realization of X. Keeping this distinction prevents the common error of treating a sample mean as if it were the underlying parameter.

Probability density functions

For a continuous RV, the probability density function fX(x) describes how probability mass is distributed along the real line. It satisfies two conditions:

  • fX(x) ≥ 0 for all x.
  • ∫−∞+∞ fX(x) dx = 1.

Crucially, fX(x) is not a probability. Probability is obtained by integrating over an interval:

P(a ≤ X ≤ b) = ∫ab fX(x) dx.

For a sensor with additive Gaussian noise, the standard model is

fX(x) = (1 / (σ√(2π))) · exp( −(x − μ)² / (2σ²) ),

where μ is the true measurand value and σ is the noise standard deviation. If a pressure transducer has μ = 100.0 kPa and σ = 0.4 kPa, then the probability that a single reading falls between 99.6 kPa and 100.4 kPa is approximately 0.683 — the familiar one-sigma interval.

Cumulative distribution functions

The cumulative distribution function is defined as

FX(x) = P(X ≤ x) = ∫−∞x fX(t) dt.

The CDF is monotone non-decreasing, ranges from 0 to 1, and is the natural tool for answering "what fraction of readings fall below a threshold?" — a question that appears constantly in tolerance analysis and pass/fail testing. For the Gaussian case, FX has no closed form, so we use the standard normal CDF Φ(z) with z = (x − μ)/σ.

Two practical identities follow directly:

  • P(X > x) = 1 − FX(x) — the upper tail, used for over-range alarms.
  • P(a < X ≤ b) = FX(b) − FX(a) — the interval probability.

Expectation and moments

The expectation (expected value) of a continuous RV is

E[X] = ∫−∞+∞ x · fX(x) dx.

E[X] is the probability-weighted average of all possible readings — the theoretical mean, not the sample mean. The variance is the second central moment:

Var(X) = E[(X − E[X])²] = E[X²] − (E[X])²,

and σ = √Var(X) is the standard deviation. Expectation is linear: E[aX + b] = aE[X] + b. Variance scales quadratically: Var(aX + b) = a²Var(X). These two rules let you propagate calibration gains and offsets through a measurement chain without re-deriving integrals.

Estimator vs. parameter. The sample mean x̄ = (1/N)Σxi is an estimator of E[X]. It is unbiased, but it is itself random — repeat the experiment and x̄ changes. Its standard deviation is σ/√N, which is why averaging reduces noise but never eliminates it.

From theory to sensor data: a worked example

Suppose a 12-bit ADC (0–4095 counts) samples a strain gauge amplifier whose output is nominally 2.048 V with Gaussian noise σ = 4 mV. The ADC LSB is 1 mV, so the quantization step is small relative to σ and the continuous model is reasonable.

  1. Model the RV. Let X be the ADC reading in millivolts. Assume X ~ N(2048, 4²).
  2. Compute an interval probability. P(2040 ≤ X ≤ 2056) = Φ(2) − Φ(−2) ≈ 0.954.
  3. Set a threshold. If the alarm trips at 2060 mV, P(false alarm per sample) = 1 − Φ((2060−2048)/4) = 1 − Φ(3) ≈ 0.00135.
  4. Average to reduce noise. With N = 16 samples, the mean has σx̄ = 4/√16 = 1 mV, so the same 2060 mV threshold now corresponds to z = 12 — effectively no false alarms.

This progression — model, interval probability, threshold, averaging — is the core workflow that later chapters extend to confidence intervals and uncertainty budgets.

Empirical PDFs and CDFs from real data

In practice you rarely know μ and σ a priori. You estimate them from data and compare the empirical distribution to a candidate model. A histogram approximates the PDF; the normalized cumulative sum approximates the CDF. A quick visual check: plot the empirical CDF against Φ((x − x̄)/s). Systematic curvature at the tails indicates skewness or heavy tails, meaning the Gaussian assumption is unsafe.

import numpy as np
from scipy import stats

# Simulated strain-gauge readings (mV), N = 500
rng = np.random.default_rng(42)
x = rng.normal(loc=2048.0, scale=4.0, size=500)

mu_hat, sigma_hat = x.mean(), x.std(ddof=1)
print(f"mean = {mu_hat:.2f} mV, std = {sigma_hat:.2f} mV")

# Empirical CDF vs. Gaussian CDF at a threshold
threshold = 2056.0
emp = np.mean(x <= threshold)
theo = stats.norm.cdf(threshold, mu_hat, sigma_hat)
print(f"empirical P(X<=2056) = {emp:.4f}, Gaussian = {theo:.4f}")

If the two numbers differ by more than a few percent for N = 500, investigate: check for outliers, drift, or a non-Gaussian noise source before proceeding.

Common pitfalls

  • Confusing PDF value with probability. fX(x) can exceed 1 for narrow distributions; only integrals give probabilities.
  • Assuming Gaussianity by default. Quantization noise is uniform; photon counts are Poisson; drift is often non-stationary.
  • Using σ of the sample instead of σ of the mean. The standard error is σ/√N, not σ.
  • Ignoring correlation. E[X+Y] = E[X]+E[Y] always, but Var(X+Y) = Var(X)+Var(Y) only when uncorrelated.
Reference-frame consistency. When you shift from ADC counts to engineering units, apply the gain and offset to the RV, not just to the mean. If Y = aX + b, then μY = aμX + b and σY = |a|σX. Mixing units between the PDF and the threshold is a frequent source of silent errors.
PDF f_X(x) — N(2048, 4²) mV x (mV) density ±1σ 68.3% μ = E[X] = 2048 CDF F_X(x) = P(X ≤ x) x (mV) F x = 2056 F ≈ 0.977 1.0 0.0 P(2040 ≤ X ≤ 2056) = F(2056) − F(2040) ≈ 0.977 − 0.023 = 0.954 E[X] = 2048 mV, Var(X) = 16 mV², σ = 4 mV, σ_x̄ = σ/√N

Key takeaways

  • A sensor reading is a random variable; distinguish the RV X from its realizations xi.
  • The PDF gives density, not probability; integrate to get probabilities.
  • The CDF answers threshold questions directly and is the bridge to tolerance and alarm analysis.
  • Expectation and variance are the first two moments that summarize a distribution; linearity of expectation and the variance scaling rule carry calibration gains and offsets through the chain.
  • Always validate the assumed distribution against empirical data before trusting derived probabilities.