Introduction to measurement#
A measurement turns a physical quantity into numbers a computer can store. Each step on the way sets a limit you can see in the data.
Download this page as a notebook to run its code in JupyterLab. Running the notebooks explains how to set it up.
From physical quantity to data#
A measurement chain has four steps:
A transducer turns the quantity, such as pressure or temperature, into an electrical signal.
A data acquisition (DAQ) system or an instrument measures that signal.
Its analog-to-digital converter (ADC) reads the signal at a fixed rate, as numbers.
Software stores each number with a timestamp.
Sensors and instrumentation covers the first two steps. This page covers the two limits that the third step adds to every measurement: how often it samples, and how finely it reads each sample.
Sampling rate#
To capture a signal, sample faster than twice the highest frequency in it. Content above half the sample rate shows up in the data at false, lower frequencies. This is aliasing, and it can’t be undone afterwards, so an anti-aliasing filter goes before the ADC.[1] Choose the rate before you record, because no later step can restore what the sampling left out. Measurement quality shows an alias in a plot.
Resolution#
An ADC reads a signal as a whole number of steps, so it rounds each reading to the nearest step. That adds an error of up to half a step.[2] More bits make the steps smaller:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from learning.style import set_matplotlib_style
set_matplotlib_style()
t = np.linspace(0, 1, 1_000) # s
signal = 2.5 + 2.0 * np.sin(
2 * np.pi * 3 * t
) # V: a 3 Hz signal between 0.5 V and 4.5 V
def read(x, bits, full_scale=5.0):
"""Round x, in volts, to the nearest step of an ADC with a 0 to full_scale range."""
step = full_scale / 2**bits
return np.round(x / step) * step, step
fig, ax = plt.subplots()
ax.plot(t, signal, color="0.5", label="True signal")
rows = []
for bits in (3, 8):
reading, step = read(signal, bits)
ax.step(t, reading, where="mid", label=f"{bits}-bit reading")
rows.append(
{
"bits": bits,
"step (mV)": step * 1e3,
"largest error (mV)": np.abs(reading - signal).max() * 1e3,
}
)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Voltage (V)")
ax.legend()
plt.show()
pd.DataFrame(rows).round(1)
| bits | step (mV) | largest error (mV) | |
|---|---|---|---|
| 0 | 3 | 625.0 | 312.0 |
| 1 | 8 | 19.5 | 9.7 |
The largest error in each row is no more than half its step. A 3-bit ADC can’t show the signal’s shape, and an 8-bit one shows it almost exactly. Resolution is only one source of error, and a fine step doesn’t make a reading accurate: Measurement quality compares resolution with accuracy and noise.
In Nominal#
Once the readings have timestamps, upload them to Nominal to chart them against your other data. A CSV file needs one timestamp column, and every other column becomes a channel.[3] This code uploads a CSV file of a temperature reading, and gives its channel a unit:
from nominal.core import ChannelDataType, NominalClient
client = NominalClient.from_profile("default")
dataset = client.create_dataset("Bench temperature")
# temperature.csv has a "timestamp" column in ISO 8601 and a "temperature" column
dataset.add_tabular_data("temperature.csv", timestamp_column="timestamp", timestamp_type="iso_8601")
dataset.add_channel("temperature", ChannelDataType.DOUBLE, unit="Cel")
The unit is a UCUM symbol, such as Cel for degrees Celsius, so workbooks can convert between units.[4] The client’s add_tabular_data and add_channel methods are the ones used above.[5] To send values as they’re measured instead, see Telemetry ingestion.
Further reading#
Sensors and instrumentation, on what sits before the ADC.
Measurement quality, on accuracy, resolution, noise and sampling.
Frequency domain, on what a sampled signal contains.