Sound Lab
Computer science · Data representation

From sound waves to binary.

Change the settings. Inspect each sample. See how a continuous wave becomes digital data.

Interactive sound sampling

Sound sample illustration

Mono channel · 5-second recording · 1 Hz sine wave
30 SAMPLES
Original analogue waveQuantised samples
Analogue wave and quantised samplesThe graph updates when you change recording settings. Use the sample selector below for exact values.
16 amplitude levels

Click a sample dot or choose a sample below. Steps hold each stored value until the next sample; they are not an ideal reconstruction.

Time
Measured amplitude
Stored level
Binary code

Total samples
30
per channel
Amplitude levels
16
4 bits per sample
Bit rate
24 bits/s
1 channel · mono
Uncompressed data
120 bits
15 bytes
View all 30 samples and their binary codes

Each code uses exactly 4 bits. This lab maps the amplitude range −1 to +1 to unsigned levels 0–15 and rounds to the nearest level.

One channel. The first sample is at 0 s; the last is one sampling interval before the recording ends.
SampleTime (s)Measured amplitudeStored levelBinary codeStored amplitude
01

How much space does sound take?

For uncompressed sound, every sample uses a fixed number of bits. Multiply by the number of samples and channels.

Your recording, step by step

Size in bits = sample rate × bits per sample
× duration × channels
1. Samples per channel
2. Bit rate
3. Total bits
4. Convert bits to bytes
Raw sample data

This is the sample-data payload only. It excludes file headers, metadata and compression. Samples are packed consecutively in this model; actual audio formats may use larger storage containers.

The graph shows the mono channel.

Worked example from your materials

A 30-second voice message

A mono recording uses 8,000 samples per second and 16 bits per sample.

8,000 Hz16 bits30 s1 channel
8,000 × 16 × 30 × 1
= 3,840,000 bits
3,840,000 ÷ 8 = 480,000 bytes

480 kB using 1 kB = 1,000 bytes.
468.75 KiB using 1 KiB = 1,024 bytes.

What changes the size? Doubling the sample rate, bit depth or duration doubles the raw data size. Stereo uses two channels, so it also doubles the size compared with mono at the same settings.

02

Nyquist theorem: how often is often enough?

Capture the fastest part of the wave

The Nyquist–Shannon sampling theorem describes how often a band-limited signal must be sampled to allow ideal reconstruction.

fs > 2 × fmax

sample rate > twice the highest signal frequency

The classroom rule is “at least twice the highest frequency.” Treat exactly twice as the boundary: samples can miss a wave depending on its phase. Choose a rate above that boundary.

The Nyquist frequency is half the sample rate: fN = fs ÷ 2. A frequency above this limit can appear as a different, lower frequency. This is aliasing.

Ideal reconstruction assumes a band-limited signal and ideal samples. Real systems use an anti-aliasing filter and a margin above the limit. More bits reduce quantisation error; they cannot fix an insufficient sample rate.

Try it on the wave above

0.5 Hz5 Hz
1 Hz

This sine wave has one frequency. Its frequency is the highest frequency in the signal.

View the updated wave ↑
Highest frequency: 16 kHzThe textbook lower boundary is 2 × 16 = 32 kHz. In practice, choose a sample rate above 32 kHz and filter out unwanted higher frequencies.
Why 44.1 kHz for CD audio?To capture frequencies up to 20 kHz, the boundary is 40 kHz. CD audio uses 44.1 kHz, giving a Nyquist frequency of 22.05 kHz and some room for filtering.
03

The language of digital sound

Use these definitions to explain what changes in the lab.

The original wave 6 terms
Sound wave
A vibration that travels through a medium such as air as changing pressure. A microphone converts these pressure changes into an electrical signal.
Analogue signal
A signal whose value changes continuously. Both time and amplitude are continuous in the ideal original wave.
Amplitude
The size of a wave’s displacement from its centre line. Greater sound-pressure amplitude generally means greater loudness. The graph uses a normalised range of −1 to +1.
Cycle
One complete repetition of a wave, such as from one peak to the next.
Frequency and hertz (Hz)
Frequency is the number of cycles per second. 1 Hz means one cycle per second; 1 kHz = 1,000 Hz. Higher sound frequency is generally heard as higher pitch. For sample rate, Hz means samples per second.
Period (T)
The time for one complete cycle, in seconds. Period = 1 ÷ frequency. A 2 Hz wave has a period of 0.5 seconds.
Turning the wave into numbers 7 terms
Digital data
Discrete values represented using binary digits, 0 and 1. Computers store and process sound as digital data.
Sample and sampling
A sample is a measurement of the signal’s amplitude at one instant. Sampling means taking these measurements at regular time intervals.
Sample rate (sampling frequency)
The number of samples taken each second, per channel. A higher sample rate gives closer measurements in time and can capture higher signal frequencies.
Sampling interval
The time between consecutive samples. Interval = 1 ÷ sample rate in seconds, or 1,000 ÷ sample rate in milliseconds. A longer interval means fewer samples per second.
Sample resolution (bit depth)
The number of bits used to represent each sample. With b bits, there are 2ᵇ possible amplitude levels: 2 bits give 4 levels; 8 bits give 256 levels.
Quantisation
Assigning a measured amplitude to one of the available discrete levels. This lab rounds to the nearest level and stores that level’s binary code.
Quantisation error
The difference between the measured amplitude and its stored approximation. A higher bit depth provides finer levels and a smaller maximum rounding error.
Storing and playing sound 7 terms
Bit and byte
A bit is one binary digit. A byte contains 8 bits. Divide a size in bits by 8 to express it in bytes.
Bit rate
The number of bits used per second. For uncompressed sound: sample rate × bit depth × number of channels, measured in bits/s or bps.
Duration
The length of a recording in seconds. Increasing duration stores more samples but does not improve the quality of each sample.
Mono and stereo
Mono has one audio channel. Stereo has two channels, usually left and right. At otherwise identical settings, uncompressed stereo uses twice as many bits as mono.
Uncompressed file size
The raw sample-data size is bit rate × duration. A complete audio file can also contain headers and metadata. Compressed formats such as MP3 do not use this formula to predict their final file size.
Analogue-to-digital converter (ADC)
A device that samples an analogue electrical signal, quantises the measurements and encodes them as digital values.
Digital-to-analogue converter (DAC)
A device that converts digital values into an analogue electrical signal. Reconstruction filtering smooths the signal; speakers or headphones then produce sound.
Sampling limits 4 terms
Band-limited signal
A signal with no frequency components above a specified maximum frequency. The sampling theorem assumes that the signal is band-limited.
Nyquist rate and Nyquist frequency
The Nyquist rate is twice the highest signal frequency: 2 × fₘₐₓ. The Nyquist frequency is half the chosen sample rate: fₛ ÷ 2. These describe different quantities.
Aliasing
An ambiguity caused by insufficient sampling: a higher-frequency wave can produce the same sample values as a lower-frequency wave, so the stored data can misrepresent the original.
Anti-aliasing filter
A filter used before sampling to reduce frequencies at or above the Nyquist frequency. Raising bit depth alone does not remove aliasing.

Recording

A microphone changes sound waves into an analogue electrical signal. After filtering, an ADC converts that signal into digital data, which can be buffered in memory and saved.

Microphone → filter → ADC
→ main memory → secondary storage

Playback

The computer reads the stored data. A DAC and reconstruction filter produce an analogue electrical signal that drives speakers or headphones.

Storage → memory → DAC + filter
→ speakers or headphones