← Data representation

Sound as numbers

A computer can't store a sound wave itself. It measures the wave's height many times a second (sampling) and rounds each measurement to a level, so a recording is a long list of numbers. More samples and more levels sound closer to the real thing, but need more numbers.

A song is a wobbling wave of air. How does a computer turn that into numbers, and why are music files so big?

Sound is a wave: air pushed back and forth. A microphone turns it into a changing signal, but a computer can only store numbers. So it samples the wave: it measures how high the wave is at regular times, rounds each measurement to one of a set of levels, and stores those numbers. To play the sound back, it turns the numbers back into a signal.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Twice as many samples

A recording measures the wave **8** times each wave. You change it to **16** times each wave. The recording now holds…

TryTry it on the board and compare the result with your prediction.

Try: take more samples

Was your prediction right? Press ▶ to hear the original and the copy made from the numbers.

Try it yourselfYour edits are saved in this browser.

Move Samples a wave from 8 up to 16. How many numbers are stored now?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: from wave to numbers

Worked exampleBefore each step, say what you think comes next.
  1. sound→wave\text{sound} \to \text{wave}The microphone turns air movement into a signal that goes up and down.

Real music takes 44 100 samples every second, with 65 536 levels. Now count the numbers for 3 waves.

A recording takes 8 samples each wave, for 3 waves. How many numbers does it store?

Sam explains how sound is recorded. Click the line where the explanation first goes wrong.

What does using **more levels** change?

ModifyChange the problem on purpose and see what happens.

Vary: one setting at a time

Try it yourselfYour edits are saved in this browser.

Turn Levels down to 4. What happens to the steps? Play it.

Use the board. This ticks when you get there.

Put Levels back to 256, then push Samples a wave to 32.

Use the board. This ticks when you get there.

Now drop Samples a wave to 4. How close is the copy?

Use the board. This ticks when you get there.

Drop Samples a wave to 2. What do the numbers say? Play it.

Use the board. This ticks when you get there.

Which stores more numbers: 32 samples a wave with 16 levels, or 16 samples a wave with 256 levels?

PractiseA few on your own, to check you have it.

Samples and sizes

Music is sampled 44 100 times a second. How many samples are in a 10 second clip?

You halve the sample rate of a recording. What happens to the number of numbers stored?

Why are music files so much bigger than text files?

Review: an image is 2 pixels by 2 pixels, three numbers a pixel. How many numbers?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Just good enough

Then: why might a phone call use far fewer samples a second than music?

Try it yourselfYour edits are saved in this browser.
Need a hint?

Set Levels to 256 first, so rounding barely matters.

Another hint

Raise Samples a wave one at a time and watch how far off the wave the copy is.

Another hint

Stop at the first value below 10%.

With 256 levels, find the fewest samples a wave that keep the copy less than 10% off the wave.

Use the board. This ticks when you get there.

For teachers

Students sample a sound wave on a board, changing the samples a wave and the levels, to see that audio is stored as a list of measured, rounded amplitudes, and that more samples and levels sound closer but need more numbers (AC9TDI8K03 node 4). About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the boards yourself, with sound on: the play buttons use the browser's audio (headphones help in class).

The one idea: sound is stored as samples, measurements of the wave's height at regular times, each rounded to a level. More samples and more levels are closer to the real sound and need more data.

Simplifications to say out loud: the board shows a few samples a wave of one pure tone; real recordings take 44 100 or 48 000 samples a second with 65 536 levels (16 bits), and playback smooths the steps. The "% off the wave" counts the step shape too, so it never reaches 0 here. Two samples a wave landing on the crossings is a simplified hint at the sampling theorem.

Running the lesson

  1. Predict: students who chose "the wave is stored" hold Sam's misconception; come back to them after the Try.
  2. Try: play the original and the copy at 8 and 16 samples.
  3. Worked example: ask what level a sample at the very top of the wave gets.
  4. Vary: the 2-samples task usually surprises; ask why the copy is silent.
  5. Make: compare answers at 16 levels too (10 samples is then just over 10%).

The hard part (on purpose)

Students think the recording is the wave itself. Keep pointing at the dots: those are the only numbers the computer has; the steps are rebuilt from them.

When students get stuck

Stretch and support

Stretch: Phone calls use about 8 000 samples a second; music uses 44 100. Why is a phone call still understandable?

Support: Keep the counting rule on the board: numbers = samples a wave × waves (or samples a second × seconds).

Where it leads

Next: Bits and binary numbers, then How many patterns? (why one byte holds 0 to 255 and why 16-bit audio has 65 536 levels).

Code links: micro:bit and Arcade play tones from numbers; the micro:bit's microphone gives a sound level 0 to 255.

What each step is for

Now you can
Next lesson5. Bits and binary numbersA computer stores numbers with switches that are only off (0) or on (1). Put bits side by side, make each place worth double the one on its right (1, 2, 4, 8, 16), and add the places that hold a 1: 10110 = 16 + 4 + 2 = 22.