AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

From waves to numbers

Week 27 · 4.4 Data representation · 3 lessons
2

Take a sample

Computing 9: Topic 4.4, pp. 335–340
GoalExplain how a sound wave is sampled, what the sample rate is, and why a higher rate gives a more accurate recording.
New words
sample · a measurement of a sound wave at one moment in timesample rate · the number of samples taken each secondaccurate · close to the original
Explanation

To store a sound wave, the computer measures it at regular moments. Each measurement is a sample, and each sample is stored as a binary number. The sample rate is the number of samples taken each second. Between two samples the computer knows nothing about the wave, so it keeps the last value until the next sample. When the samples are played in order they form a stepped copy of the wave. A higher sample rate puts the measuring moments closer together, so the copy follows the wave more closely and the recording is more accurate. The price is more data to store. A recording for music uses tens of thousands of samples every second, so we use smaller numbers in our examples.

Worked examples
0510150123456789101112heightheld valueoriginal
Sampling a wave at 13 moments, 0 to 12. The line is the original height. The bars show what the computer keeps if it takes a sample every 4 moments, at moments 0, 4, 8 and 12 (heights 3, 12, 2 and 10): it holds each value until the next sample. Notice how far the bars are from the line, for example at moments 2 and 6.
Sample taken everySamples storedTotal gap from original
4 moments444
2 moments714
1 moment130
Comparing three sample rates on the same wave. For each moment, find the gap between the original and the held value, and add the gaps. Sampling every 4 moments gives a total gap of 44. Sampling every 2 moments gives 14. Sampling at every moment copies the wave exactly, so the gap is 0, but 13 values must be stored instead of 4.
SampleHeight4-bit binary
at moment 030011
at moment 4121100
at moment 820010
at moment 12101010
From samples to numbers. Suppose the heights are stored as 4-bit binary numbers. The four samples from example 1 are stored as 0011, 1100, 0010 and 1010. The number of samples in a recording is the sample rate times the time. A recording with a sample rate of 8 000 per second and a length of 5 seconds has 8 000 × 5 = 40 000 samples. If the rate is doubled to 16 000, the same 5 seconds need 80 000 samples.
Class activity

Sample a wave on paper (no computer). On squared paper draw a smooth wave that goes up and down three times, over 24 squares across. First take a sample every 6 squares: mark the height at each sample, then draw the stepped copy, holding each height until the next sample. On a second sheet, take a sample every 3 squares. Lay both stepped copies over the original and decide which is closer. Write how many samples each used. If you have a computer or tablet, an adult can help you copy your two sets of heights into a spreadsheet and draw a chart of each.

Practice
1
Work out the number of samples in each recording: sample rate times length. Complete the table.
RecordingSample rate (per second)LengthNumber of samples
(a)8 0003 s?
(b)16 0003 s?
(c)8 00010 s?
2
A wave has the heights shown. A sample is taken every 4 moments. (a) Write the held values. (b) Work out the total gap from the original. (c) The same wave is sampled every 2 moments, which gives a total gap of 15. Which rate is more accurate, and what is the cost?
Moment012345678
Original height48129526117
Held value (sample every 4)4???5???7
3
Write each sample height as a 4-bit binary number.
Sample height4-bit binary
5?
9?
14?
2?
4
Recording A uses a sample rate of 4 000 per second and recording B uses 20 000 per second, for the same song. Which one will sound more like the original, and which file will be bigger? Explain.