Skip to content
Tactiverge

School/□ Systems Engineer/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?

About 35 min · 3 goals · Checked by automated tests

1.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.

2.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?

Can't use the interactive? Read a description instead

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.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

Which signal is discrete in time but NOT quantised?

Practice 2

A signal is sampled at fs = 1 kHz from t = 0. At what time, in seconds, is sample x[250] taken?

s

4.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.

5.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

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.

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.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 3 · a fresh version every time

x(t) = 3·cos(2π·2·t) is sampled at fs = 12 Hz, so x[n] = x(n/12). Find x[5] (to 2 decimal places).

Practice 4

What is the energy E = Σ x[n]² of the sequence x = [2, −3, 1, 0, 1]?

Practice 5

Code computes x[n] = sin(2π·5·n) for n = 0, 1, 2… and every value is (almost) zero. What went wrong?

Practice 6 · a fresh version every time

A voltage is v(t) = 3 + 5·sin(2π·100·t) volts. What is its RMS value, in volts (to 2 decimal places)?

V

7.Predict

A temperature sensor is read at fs = 4 Hz, starting at t = 0. At what time is sample x[10] taken?

Guess first. Being wrong here is how the surprise works.

8.Reflect

Concepts: Sampling rate and aliasing · Analog-to-digital conversion