Year 9 · Audio-Visual · Part A: Storing information

Representing sound

In one line

A computer measures the height of a sound wave thousands of times a second and saves each measurement as a binary number. This is sampling.

1

Explain how a microphone, an ADC and a DAC turn sound into numbers and back again.

2

Describe sample rate and bit depth, and how each changes quality and file size.

3

Use the Nyquist rule to explain why CDs use 44,100 samples a second.

4

Calculate a sound file's size by hand, for mono and stereo.

AnalogueSmooth: any value is possible.
DigitalSeparate, countable steps.
ADC / DACAnalogue → digital, and back.
Sample rateMeasurements per second, in hertz (Hz).
Bit depthBits per measurement. Sets the levels.

What sound is: air that vibrates

A speaker cone, a guitar string or your voice box moves back and forth very fast. Each push squashes the air next to it. The squash travels outwards, like a ripple. When it reaches your ear, your eardrum wobbles too. That's hearing.

speaker squashed air = high pressure · spread-out air = low pressure time → amplitude = loudness one vibration (one cycle) = 1 peak + 1 dip
Top: the air itself. Dots bunch up, then spread out. Bottom: the same thing as a graph of pressure against time. The bunches are the peaks, the gaps are the dips. That graph is the "sound wave".
Part of the waveWhat it meansYou hear it as
Amplitude: how tall the wave isHow hard the air is pushedLoudness
Frequency: how many cycles per secondHow fast it vibratesPitch: high or low note
★Remember

Hertz (Hz) means "times per second". A note of 440 Hz vibrates 440 times every second. 1 kHz (kilohertz) = 1,000 Hz. People hear from about 20 Hz (deep rumble) to about 20,000 Hz (a very high whistle). The top limit drops as you get older.

Analogue and digital: the ADC and the DAC

A real sound wave is analogue: smooth, with any height at any moment. A computer can only store a list of whole numbers. That is digital: separate steps. So something must convert between the two.

Recording Sound Microphoneair → smoothvoltage analogue ADCmeasures itagain and again digital Numbers100 110 111 110100 010 001 010 stored in a file,sent, edited Playback Numbers100 110 111 … DACnumbers →voltage Amplifier+ speakervoltage → air Sound The DAC's output is in steps. Electronics smooth the steps before the speaker.
ADC = Analogue to Digital Converter. DAC = Digital to Analogue Converter. Read the name left to right: it says what goes in and what comes out.
AnalogueDigital
ValuesSmooth: any value, like 2.4371… voltsSteps: only certain values, like level 5 of 8
ExamplesReal sound, a vinyl record, a dimmer switchAn MP3, a CD, a file on a computer
CopyingEach copy adds a little noiseCopies are exactly the same numbers
e.g.Example

A phone call goes through this chain twice. Your phone's ADC turns your voice into numbers. The numbers travel across the network. The other phone's DAC turns them back into sound.

Sampling, step by step

The ADC can't store the whole smooth curve. So it takes samples: it measures the height of the wave at regular moments, and rounds each measurement to the nearest level it's allowed to store.

Grey curve: the real sound. Dots: the samples, each rounded to the nearest level (0 to 7). Orange steps: what the computer really stores. Under each sample: its level in denary and in 3-bit binary.
  1. Pick regular moments in time. Here: 8 moments, evenly spaced.

  2. At each moment, measure how high the wave is. The first one is about 3.8.

  3. Round it to the nearest level you're allowed. 3 bits give 8 levels, 0 to 7. 3.8 rounds to 4.

  4. Save the level as a binary number. 4 = 100.

  5. Repeat for the whole recording. Levels 4, 6, 7, 6, 4, 2, 1, 2 → 100 110 111 110 100 010 001 010.

  6. Size: 8 samples × 3 bits = 24 bits. Every recording is just a long list like this.

!Watch out

The rounding in step 3 always loses a little. The gap between the real height and the stored level is called quantisation error. You can make it smaller, but never zero. A digital recording is a very good copy, not a perfect one.

Sample rate: how often you measure

The sample rate is how many samples are taken each second. It's measured in hertz (Hz). More samples per second means the dots sit closer together, so the steps follow the real curve more closely.

Same wave, same levels. Only the sample rate changes. The right-hand version has 4 times as many samples, so it's closer to the real curve, and its file is 4 times bigger.
Sample rateSamples every secondUsed for
8 kHz8,000Phone calls
22.05 kHz22,050Old games, voice notes
44.1 kHz44,100CDs, most music
48 kHz48,000Film, TV and video
96 kHz96,000Recording studios
!Watch out

Two different things are measured in hertz. The pitch of a sound (how fast the air vibrates) and the sample rate (how often the ADC measures). A 44,100 Hz sample rate does not mean a 44,100 Hz note.

Bit depth: how precisely you measure

The bit depth is how many bits store each sample. Same rule as colour depth: n bits give 2ⁿ levels. More levels means smaller gaps, so each sample is rounded less.

Same sample rate. Left: 2 bits = 4 levels (the grid lines). Right: 4 bits = 16 levels. Twice the bits per sample, twice the file, and four times as many levels.
Bit depthLevels (2ⁿ)Sounds like
3 bits8Very rough, crackly
8 bits256Phone calls, old game music
16 bits65,536CD quality
24 bits16,777,216Studio recording
▶

Explorer: original vs what's stored

One second of a made-up sound. It has a slow wobble (2 Hz) and a faster wiggle (5 Hz). Change the settings. The red shading is the error: everything the recording got wrong.

Real soundWhat gets played backA sampleError
Levels
Bits per second
Average error
?Why?

Why does low bit depth sound "hissy" or "crunchy"? Every sample is rounded. The rounding errors jump about at random, and random wobbles sound like hiss. Each extra bit halves the size of the gaps, so it halves the error.

The Nyquist rule: how fast is fast enough?

To capture a vibration, you must catch it going up and coming down. That needs at least two samples per vibration. Sample any slower and something strange happens: a high note turns into a wrong, lower one.

Grey: a fast vibration (9 cycles). Dots: only 10 samples, far too few. Join the dots and you get the dashed red wave: just 1 slow cycle. That's called aliasing. It's the same reason car wheels look like they spin backwards in films.

By hand: why do CDs use 44,100 Hz?

  1. The highest pitch people hear is about f = 20,000 Hz.

  2. Nyquist: sample at least twice as fast. r ≥ 2 × 20,000 = 40,000 Hz.

  3. Before sampling, a filter must remove sounds above 20,000 Hz, or they'd alias into wrong notes. Real filters can't cut off sharply, so they need a little room.

  4. 44,100 is 40,000 plus about 10% spare for that filter.

  5. The exact number 44,100 also fitted the video-tape recorders used to master the first CDs in 1980. History, not physics.

By hand: phone calls

  1. Phone networks sample at 8,000 Hz.

  2. Turn Nyquist round: the highest pitch it can capture is half the sample rate. 8,000 ÷ 2 = 4,000 Hz.

  3. Speech is understandable up to about 3,400 Hz, so voices work. But music on hold sounds dull: everything above 4,000 Hz is cut.

★Exams

The Nyquist rule is beyond the AQA 8525 and OCR J277 GCSE specs. They expect: "a higher sample rate gives a closer match to the original sound, and a bigger file". It's here because it answers the question every class asks: why 44.1?

Calculating a sound file's size

Every second has r samples. Every sample has d bits. Stereo has two channels, so double it. Multiply by the number of seconds. That's the size in bits.

By hand: 3 minutes of CD audio

  1. Gather the numbers. r = 44,100 Hz, d = 16 bits, c = 2 (stereo). t = 3 minutes = 3 × 60 = 180 seconds. Always turn minutes into seconds first.

  2. Bits per second, one channel: 44,100 × 16 = 705,600.

  3. Both channels: 705,600 × 2 = 1,411,200 bits every second. (Music fans call this "1,411 kbps".)

  4. Whole song: 1,411,200 × 180 = 254,016,000 bits.

  5. Bytes: ÷ 8 = 31,752,000 bytes.

  6. MB: ÷ 1,000,000 = about 31.8 MB. An MP3 of the same song is 3–4 MB because it's compressed (Topic 7).

▶

Sound file size calculator

Size
Compared with the same length on CD

★Remember

bits = sample rate × bit depth × seconds × channels. Then ÷ 8 for bytes, ÷ 1000 for KB, ÷ 1000 for MB. OCR J277 writes it without channels (it assumes mono). AQA 8525 writes "rate × resolution × seconds". Add × 2 only when the question says stereo.

Mono, stereo, and the quality–size trade-off

Mono = one channel: one list of samples, played from every speaker. Stereo = two channels, left and right, recorded by two microphones. Each channel is a whole list of its own, so stereo is twice the size.

Mono 1 mic 100 110 111 110 100 010 001 010 Stereo left mic right mic L: 100 110 111 110 100 010 001 010 R: 011 101 111 111 101 011 001 001
Stereo stores a separate sample for each ear at every moment. The small differences between left and right let your brain place the sound in space.
You change…QualityFile size
Double the sample rateCaptures higher pitches, closer to the curve× 2
Double the bit depth (e.g. 8 → 16)Far more levels, much less hiss× 2
Mono → stereoSound has left and right× 2
Double the lengthSame quality× 2
Halve any one of themWorse (or shorter)÷ 2
▶

Listen: hear sample rate and bit depth

Turn your volume down first. A short tune of 4 notes, then a high whistle at 3,000 Hz. Pick the settings, then press Play.

Sample rate
Bit depth

An ADC you can build: Arduino and micro:bit

An Arduino has its own ADC built in. analogRead(A0) measures the voltage on pin A0 (0 to 5 volts) and gives back a whole number from 0 to 1023. That's a 10-bit ADC: 2¹⁰ = 1024 levels. It's exactly the bit-depth idea, in a chip.

The voltage on pin A0 (analogue) The number analogRead gives (digital) 512 = 1000000000(10 bits) One step = 5 ÷ 1024 ≈ 0.0049 V. The knob at 2.5 V lands on step 512.
The ADC cuts 0–5 V into 1024 equal steps. It reports which step the voltage reached. To get volts back, multiply the step number by the size of one step.

By hand: the reading is 512. How many volts?

  1. One step is 5 ÷ 1024 volts. Keep it as a fraction for now: V = 512 × 5 ÷ 1024.

  2. Multiply first: 512 × 5 = 2,560.

  3. Then divide: 2,560 ÷ 1024 = 2.5 V. Half the reading range → half of 5 V. ✓

  4. LED brightness: analogWrite takes 0 to 255. 512 ÷ 4 = 128, about half brightness.

e.g.Year 9 link: the micro:bit v2

The micro:bit has a 10-bit ADC too: pin0.read_analog() gives 0 to 1023. Its pins run on 3.3 V, so one step is 3.3 ÷ 1024 V. The v2 also has a built-in microphone. microphone.sound_level() takes one sample of loudness, from 0 to 255 (8 bits).

from microbit import *
# take 20 samples a second and send them to the plotter
while True:
    level = microphone.sound_level()   # 0 to 255: one 8-bit sample
    print((level,))                    # a tuple, so the editor can plot it
    sleep(50)                          # 50 ms gap = 20 samples per second
?Why?

Why only 20 a second? This measures how loud the room is, not the wave itself. Change sleep(50) to sleep(500) and claps start to go missing between samples. That's a low sample rate, made visible.

Common mix-ups

The mistakes nearly everyone makes the first time. Read the left side, then the right.

People think

Bit depth means bits per second.

Actually

Bit depth is bits per sample. Bits per second = sample rate × bit depth (the "bit rate").

People think

A 44,100 Hz recording plays a 44,100 Hz note.

Actually

Sample rate is how often the ADC measures. Pitch is how fast the air vibrates. Both use Hz.

People think

16-bit sound has 16 levels.

Actually

2¹⁶ = 65,536 levels. 4 bits would give 16.

People think

A higher sample rate makes it louder.

Actually

Loudness is the wave's amplitude. Sample rate changes how accurately it's captured.

People think

Stereo is better quality, so it's the same size.

Actually

Stereo is two full lists of samples: twice the size.

People think

The size formula gives bytes. Or: put the length in minutes.

Actually

It gives bits, and the length must be in seconds.

People think

Digital audio is a perfect copy of the sound.

Actually

Every sample is rounded (quantisation error) and anything between samples is lost. It's very close, never perfect.

Check yourself

Quick questions first. Then endless practice: a wrong answer shows you the working, step by step.

[ {"q":"Sample rate means…","o":["How many samples per second","How many bits per sample","How loud it is"],"a":0,"w":"Measured in hertz: samples per second."}, {"q":"A bit depth of 4 gives how many levels?","o":["4","8","16"],"a":2,"w":"2⁴ = 16."}, {"q":"Turning a microphone's voltage into numbers is done by…","o":["An ADC","A DAC"],"a":0,"w":"**A**nalogue to **D**igital **C**onverter."}, {"q":"The highest pitch you want to record is 10,000 Hz. The smallest sample rate that works is…","o":["5,000 Hz","10,000 Hz","20,000 Hz"],"a":2,"w":"Nyquist: at least 2 × 10,000 = 20,000 Hz."}, {"q":"Mono → stereo, everything else the same. The file…","o":["stays the same","doubles","halves"],"a":1,"w":"Two channels = two full lists of samples."}, {"q":"10 seconds, 1,000 Hz, 8 bits, mono. The size is…","o":["80,000 bits","10,000 bits","8,000 bytes"],"a":0,"w":"1,000 × 8 × 10 × 1 = 80,000 bits (= 10,000 bytes)."}, {"q":"An Arduino reads 1023 from analogRead. The voltage is about…","o":["0 V","2.5 V","5 V"],"a":2,"w":"1023 is the top step: 1023 × 5 ÷ 1024 ≈ 4.995 V, almost 5 V."}, {"q":"Which change makes the playback closest to the real sound?","o":["Lower sample rate","Higher sample rate and bit depth","Stereo instead of mono"],"a":1,"w":"More samples and more levels follow the curve more closely."} ]