Lite / Engineering Complex Systems / Week 19
From a wave to a list of numbers
Your phone's microphone hears a smooth, endless pressure wave. Your phone stores a list of whole numbers. What happened in between?
Why should I care?
Every sensor reading a robot uses, every sound you stream and every heartbeat a smartwatch logs is a signal that was sampled. Before you can filter, compress or analyse a signal you have to know exactly what the numbers in the list mean: which instant each one belongs to, and what is lost between them.
- Distinguish continuous-time from discrete-time signals, and analog from quantised values.
- Write a sampled signal as x[n] = x(nT) and compute sample times and values.
- Compute the energy of a short sequence and the average power of a periodic signal.
Predict
A temperature sensor is read at fs = 4 Hz, starting at t = 0. At what time is sample x[10] taken?
- 10 s
- 2.5 s
- 0.4 s
- 40 s
Guess first, then reveal
The sample period is T = 1/fs = 0.25 s, so x[n] is taken at t = nT = 10 × 0.25 = 2.5 s. The index n counts samples, not seconds: you always need fs to turn it back into time.
Discover
In the Code Lab, define x(t) = 2·cos(2π·3·t), pick fs = 24 Hz and build the list x[n] = x(n/fs) for n = 0…23. Print t and x[n] side by side, then repeat with fs = 6 Hz. How many samples land in each cycle of the wave?
What the interactive shows (text version)
Without the Code Lab: for x(t) = 2cos(2π·3t) at fs = 24 Hz there are 8 samples per cycle, giving values 2, 1.41, 0, −1.41, −2, −1.41, 0, 1.41 repeating. At fs = 6 Hz there are only 2 samples per cycle, alternating 2 and −2: the shape between them is lost.
Understand
Two independent choices: time and value
A continuous-time signal x(t) has a value at every instant. A discrete-time signal x[n] exists only at the sample instants. Separately, a value can be analog (any real number) or quantised (one of a fixed set of levels). A digital signal is both discrete in time and quantised in value. The two steps are done by one chip, an ADC, but they cause different errors: sampling can cause aliasing, quantising adds rounding noise.
x[n] = x(nT)
Uniform sampling takes one value every T seconds; the sample rate is fs = 1/T. Sample n is the value at t = nT. The list x[0], x[1], x[2], … is all a processor ever sees. Square brackets mean an integer index; round brackets mean real time. Mixing them up is the commonest source of off-by-a-factor bugs in signal code.
Energy and power
For a sequence, energy E = Σ x[n]², the sum of squared samples (for a voltage across 1 Ω this is proportional to the energy delivered). Signals that go on for ever, like a sine wave, have infinite energy, so we use average power P = mean of x². A sinusoid of amplitude A has P = A²/2, and its RMS value √P = A/√2 is the steady voltage that would deliver the same power.
Explain it another way
Intuitive
Sampling is like a strobe light in a dark room: you only see the dancer at each flash. Between flashes you have to guess, and if the flashes are too slow your guesses will be wrong.
Technical
An ideal sampler multiplies x(t) by a train of impulses spaced T apart, keeping x(nT). A real ADC holds the input on a small capacitor (sample-and-hold) for a short aperture, then converts the held voltage to a code.
Mathematical
x[n] = x(nT), n ∈ ℤ, T = 1/fs. For x(t) = A·cos(2πft + φ), x[n] = A·cos(2π(f/fs)n + φ): only the ratio f/fs matters to the samples. Energy E = Σₙ |x[n]|²; average power P = lim (1/N)·Σ_{n=0}^{N−1} |x[n]|².
Applied
A heart-rate chest strap samples its ECG electrodes at a few hundred hertz. Its firmware stores samples with time stamps n/fs, and its software computes the power in a window to detect whether the strap is touching skin at all.
Worked example 1
x(t) = 3·cos(2π·2·t) is sampled at fs = 8 Hz. List x[0] to x[3].
f/fs = 1/4, so each sample advances the phase by 90°. x[0] = 3cos 0 = 3, x[1] = 3cos 90° = 0, x[2] = 3cos 180° = −3, x[3] = 3cos 270° = 0.
Worked example 2
What is the energy of x = [1, 2, −1, 0]?
E = 1² + 2² + (−1)² + 0² = 6. Squaring makes negative samples count just as much as positive ones.
Common mix-ups
Digital just means sampled.
✓ Digital means sampled in time and quantised in value: two separate steps with two separate kinds of error.The sample index n is the time.
✓ n counts samples. Time is n·T = n/fs, so the same n means a different instant at a different sample rate.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Pick any periodic quantity you can describe as a formula (a 50 Hz mains waveform, a 1 Hz breathing rhythm). Choose a sample rate, generate ten samples by hand or in code, and plot them as dots over the true curve. Explain in two sentences whether your sample rate shows the shape well.
Reflect
What information about a signal does a list of samples lose, and what extra number do you always need to keep alongside it?
Write your answer on paper or in your own notes. Lite never stores what you write.