Article
Sampling sound, pictures and other analog data
A singer's voice rises and falls smoothly, with no steps and no gaps. A computer cannot store something smooth. It can only store separate numbers. So how does a song get onto your phone?
The answer: the computer measures the sound again and again, and keeps only the measurements.
Analog and digital
Analog data changes smoothly. Between any two values there are more values. The temperature of a room, the loudness of a sound and the brightness of a light are all analog.
Digital data is made of separate steps, stored as bits. To put analog data in a computer, we must change it to digital. This is analog-to-digital conversion. It has two parts: take measurements, then write each measurement as a binary number. Here is the whole journey of a sound:
From a sound wave to bits
Smooth sound
no steps and no gaps
measure again and againSamples
e.g. 2.3, 5.8, 9.6
round each oneWhole numbers
2, 6, 10
write in binaryBits
0010 0110 1010
Sampling sound
Sampling means measuring an analog signal at regular times. Each measurement is a sample. The table shows a sound measured once every second. Each true value is rounded to the nearest whole number, and the whole number is stored in 4 bits.
| Time (s) | True value | Stored number | Stored bits |
|---|---|---|---|
| 0 | 2.3 | 2 | 0010 |
| 1 | 5.8 | 6 | 0110 |
| 2 | 9.6 | 10 | 1010 |
| 3 | 11.2 | 11 | 1011 |
| 4 | 8.7 | 9 | 1001 |
| 5 | 4.1 | 4 | 0100 |
Here is the stored sound as a picture. Each bar is the size of one stored number.
time 0 | ## 2
time 1 | ###### 6
time 2 | ########## 10
time 3 | ########### 11
time 4 | ######### 9
time 5 | #### 4Two settings decide how close the copy is to the original:
- The sample rate is how many samples are taken each second. A higher rate catches more of the changes between measurements. Real recordings take thousands of samples a second.
- The bit depth is how many bits each sample uses. With 4 bits there are 16 possible levels. With 8 bits there are 256. More levels mean less rounding.
A higher sample rate and a higher bit depth make a better copy, but they also make the file bigger. The copy is never perfect, because the values between samples are lost and every sample is rounded.
Check your understanding
A phone measures a sound 8,000 times each second. What does the number 8,000 describe?
Pictures are samples too
A photo is analog light. To store it, a camera measures the light at a grid of points. Each point is a pixel, and the grid is the picture.
Each pixel stores three numbers, one each for the amount of Red, Green and Blue light. This is RGB. If each number uses 8 bits, it can be from 0 to 255.
| Colour | Red | Green | Blue |
|---|---|---|---|
| Red | 255 | 0 | 0 |
| Green | 0 | 255 | 0 |
| Blue | 0 | 0 | 255 |
| Black | 0 | 0 | 0 |
Worked example
A tiny picture is 2 pixels wide and 2 pixels tall, and each pixel uses 3 numbers of 8 bits.
- The picture has 2 × 2 = 4 pixels.
- One pixel uses 3 × 8 = 24 bits.
- The whole picture uses 4 × 24 = 96 bits. That is 96 / 8 = 12 bytes.
A real photo has millions of pixels, so it needs millions of times more.
Check your understanding
A picture stores each pixel as three numbers (red, green and blue), and each number uses 4 bits. How many bits does one pixel use?
Common mistakes
- Thinking digital copies are perfect. Sampling throws away what happens between the samples, and rounding changes each value a little.
- Mixing sample rate and bit depth. The rate is how often you measure. The depth is how many bits each measurement gets.
- Counting levels as the number of bits. 4 bits give 16 levels, not 4.
- Forgetting the three colour numbers. One pixel is not one number. It is three.
On the exam
Expect questions that ask what changes when you sample more often or use more bits per sample: the copy is closer to the original, and the file is bigger. Be ready to say that digital data is an approximation of analog data. You may also need to multiply: samples, bits per sample and time, or pixels and bits per pixel.
Key words
Analog: data that changes smoothly and has no separate steps.
Digital: data stored as separate steps, which are bits.
Sampling: measuring an analog signal at regular times.
Sample rate: the number of samples taken each second.
Bit depth: the number of bits used for each sample.
Pixel: one point of a picture, stored as numbers.
RGB: a way to store a colour as an amount of red, green and blue.