Sound is a smooth wave, but a computer can only store numbers. It measures the wave many times a second and stores each measurement in binary. You learn what the sample rate and the sample resolution are, and how they change the accuracy and the size of a recording.
about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
From a wave to numbers
When you speak, the air vibrates. A microphone turns the vibration into a smoothly changing signal: a sound wave. The height of the wave at any moment is its amplitude.
A computer cannot store a smooth curve. To convert sound into binary, the computer samples the wave. It measures the amplitude at regular moments, and stores each measurement as a binary number. The computer then processes these numbers.
A grey sound wave, one full cycle of a sine curve, drawn against time. Eight equally spaced dots mark the samples. Horizontal grid lines mark the 8 levels of a 3-bit sample, numbered 0 to 7 on the left. Each dot is rounded to the nearest level, and the levels of the samples are 4, 6, 7, 6, 4, 1, 0 and 1, with the 3-bit code of each written under it.
In the picture, the grey curve is the wave. The dots are the samples. Each sample is rounded to the nearest level, and the level is stored in binary. With 3 bits there are 23=8 levels, numbered 0 to 7.
Sample rate
The sample rate is the number of samples taken in one second. It is measured in hertz (Hz), where 1 hertz is one sample a second.
A higher sample rate measures the wave more often. The stored sound follows the real wave more closely, so the recording is more accurate.
But there are more samples to store, so the file is larger.
Two panels showing the same sound wave, two cycles of a wave whose height changes quickly. In the left panel the wave is sampled 6 times and the blue steps through the samples miss most of the shape. In the right panel it is sampled 40 times and the blue steps follow the wave closely. The labels say low sample rate and high sample rate.
The picture shows the same wave sampled at a low rate and at a high rate. At the low rate, quick changes in the wave fall between the samples and are lost.
Sample resolution
The sample resolution is the number of bits used for each sample. It is sometimes called the bit depth.
With b bits a sample can take 2b different levels. 8 bits give 256 levels, and 16 bits give 65536 levels.
A higher resolution means each sample is rounded less, so the recording is more accurate.
But each sample needs more bits, so the file is larger.
Both settings work the same way: as the sample rate and the resolution increase, the accuracy of the recording and the file size both increase.
The size of a sound file
Every second there are (sample rate) samples, and each one needs (resolution) bits.
bits=sample rate×sample resolution×length in seconds
A recording sampled 8000 times a second at 8 bits for 10 seconds needs 8000×8×10=640000 bits. Divide by 8 for bytes: 80000 bytes. The next course turns sizes like this into kibibytes and mebibytes.
Practise with new numbers
Try it in Python
The program samples one wave at a chosen rate and resolution. It prints each sample as a level and as binary, and then the number of bits stored.
Common mistakes
Mixing up the two settings. The sample rate is how often you measure. The sample resolution is how many bits each measurement has.
Forgetting the time. The size depends on the length of the recording too.
Thinking only one thing increases. Higher settings give better accuracy and a larger file.
Levels and bits. 4 bits give 24=16 levels, not 4 levels.
Remember these
Sound is sampled: the amplitude is measured at regular moments and each value is stored in binary.
Sample rate: the number of samples taken in a second.
Sample resolution: the number of bits per sample. b bits give 2b levels.
Higher rate or resolution: a more accurate recording and a larger file.
Bits = sample rate × resolution × seconds.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
What is meant by the sample rate of a recording?
How many different levels can a sample take with a resolution of 5 bits?
A sound is sampled 4000 times a second at 16 bits for 3 seconds. How many bits does it need?
A recording is made again with double the sample rate. Everything else is the same. What happens to the file size?
Give one reason to choose a higher sample resolution, and one reason not to.
Enroll free in Text, Sound and Images in Binary
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.