1 Sound, amplitude, and frequency
Sound is air pressure oscillating around its resting value. A microphone converts that pressure variation into a voltage that varies the same way, so in either form the signal is one continuous, smoothly changing quantity. The simplest sound, a pure tone, is described by two parameters: amplitude (the size of the swing, heard as loudness) and frequency (the number of swings per second, in hertz, heard as pitch).
is the pressure (or voltage) at time ; is the amplitude; is the frequency in Hz. The factor converts cycles to radians: counts elapsed cycles, and expects an angle parameterization ↗. The time one full cycle takes is the period, ; at 440 Hz each cycle lasts ms. The period appears as the readout beside the plot.
Drag the sliders and press play; both retune the live tone. Doubling the frequency, for instance from 220 Hz to 440 Hz, produces the same note one octave higher, because pitch perception is logarithmic in frequency. The slider's 50–1,000 Hz span is a small slice of human hearing, which covers roughly 20 Hz to 20,000 Hz.
2 Sampling
A computer cannot store a continuous function; it stores a finite list of numbers. The wave's amplitude is therefore measured at regular instants. Each measurement is a sample, and the number of measurements per second is the sample rate . A sample records the wave's instantaneous amplitude as a single number; frequency information exists only in how successive samples change.
is the continuous signal, and is its -th sample, with square brackets marking the discrete sequence. is the time of that sample, since consecutive samples are seconds apart.
Drag both sliders. With many samples per cycle the dots clearly trace the wave. As the rate drops toward 2 samples per cycle, the dots become too sparse to determine which wave produced them, and the readout turns red at that threshold. The next lesson examines exactly what goes wrong there.
3 Nyquist and aliasing
The Nyquist–Shannon sampling theorem states the condition for sampling to be faithful: the sample rate must exceed twice the highest frequency present in the signal.
is the sample rate, and is the highest frequency in the signal. Equivalently, every frequency component needs more than two samples per cycle. Half the sample rate, the highest representable frequency, is called the Nyquist frequency.
Violating the condition does not produce silence or noise. It produces a different, valid-looking signal. A sinusoid (lesson 1's pure tone under its formal name) above the Nyquist frequency yields exactly the same samples as some sinusoid below it, so after sampling the two are indistinguishable, and playback reproduces the lower one. This substitution is called aliasing. Film cameras have the same problem in time: a wagon wheel rotating faster than half the frame rate appears to spin slowly or backwards.
Real converters prevent aliasing with an anti-aliasing filter: a low-pass stage, a circuit that passes frequencies below its cutoff and rejects those above, placed in front of the sampler to remove everything above Nyquist. The filter must come before the sampler, because after sampling an alias is indistinguishable from a genuine low-frequency component, and no later processing can tell them apart. Real filters also cannot cut off abruptly: they need a transition band in which to roll off from passing to blocking. That margin is why CDs sample at 44,100/s: the gap between audible 20 kHz and Nyquist at 22,050 Hz holds the filter's transition band.
In the demo below the sampler is fixed at 4,000 samples/s, so Nyquist sits at 2,000 Hz. Start the digitized tone, then sweep the slider; the tones retune live. Past 2,000 Hz the input frequency keeps rising while the played-back frequency folds and descends.
4 Bit depth and quantization
Sampling discretizes time; storing each sample discretizes amplitude. A bit is one two-way choice, so of them together can label distinct things. With bits per sample the amplitude range is divided into levels (“buckets”), and every reading is rounded to the nearest level. The rounding error, at most half a bucket, stays in the signal permanently and is heard as a low-level distortion called quantization noise. Each added bit doubles the level count, halves the maximum error, and improves the signal-to-noise ratio by about 6 dB decibels ↗:
SNR is the power ratio between a full-scale sinusoid, one using the largest swing the -bit range can represent, and the quantization error, expressed in decibels. The 6.02 arises as follows: the error is approximately uniform over step; each added bit halves the step and therefore halves the error amplitude; and halving an amplitude changes a level by dB. The 1.76 dB constant comes from comparing a sinusoid's average power with uniform noise's average power.
The melody below loops continuously through a quantizer whose depth follows the slider; sweep the slider while the melody plays. At 12 bits the noise is inaudible; by 4 bits there is a clear hiss; at 1–2 bits the waveform is heavily distorted. Pitch and timing are unaffected throughout, because both are determined by the sample clock (lessons 2 and 3); quantization degrades only amplitude accuracy.
5 ADC → DAC: the round trip
This lesson runs the whole pipeline. On the way in, the ADC (analog-to-digital converter) samples and quantizes, turning a waveform into a list of numbers. On the way out, the DAC (digital-to-analog converter) reconstructs: it holds each number steady for one sample period, producing a staircase voltage, and a reconstruction filter then removes the staircase's sharp edges, which in spectral terms means everything above Nyquist. The filter's output is not an arbitrary smoothing of the staircase; it is uniquely determined. A signal is band-limited when it contains no frequencies above some ceiling; lesson 3's condition guaranteed the original was band-limited below Nyquist, and the sampling theorem supplies the uniqueness that this lesson relies on: exactly one waveform band-limited below Nyquist passes through the stored samples, namely the original. That waveform is the filter's output. Written out, the ideal reconstruction is:
are the stored samples, and is a pulse that equals 1 at and 0 at every other integer. The argument measures how many sample periods separate time from sample . Each sample contributes one sinc pulse centered on itself, and the adds them, one term per stored sample, across all of them. At any sample instant every other pulse is zero, so the sum passes through each sample exactly, and between samples the pulses interpolate the unique band-limited curve. (This formula is the idealized version of what hold-then-filter approximates; real DACs adjust their filters to compensate for the staircase's slight droop.)
With generous rate and depth, the output panel below reproduces the input panel. Lower either slider and an earlier lesson's failure appears: too few samples produces the aliasing of lesson 3, and too-coarse levels produce the quantization noise of lesson 4.
6 Bitrate
The plain numbered samples this course has been producing are called PCM (pulse-code modulation). The storage and bandwidth cost of uncompressed PCM follows directly from the course's two parameters:
is the sample rate in samples per second, is the bit depth in bits per sample, and channels counts the independent signals recorded together: one for mono, two (left and right) for stereo. The product is in bits per second, before any compression. The two parameters are independent: sample rate sets the frequency ceiling (lesson 3), and bit depth sets the signal-to-noise ratio (lesson 4).
For CD audio the formula gives 44,100 × 16 × 2 = 1,411,200 bits per second. Per minute that is 1,411,200 × 60 = 84,672,000 bits; eight bits make a byte, so dividing by 8 gives 10,584,000 bytes, about 10.6 MB of storage for every minute of stereo CD audio. Telephone audio (8,000 samples/s, 8 bits, mono) comes to 8,000 × 8 × 1 = 64,000 bits per second, roughly a twentieth of the CD rate; sampling at 8,000 samples/s caps speech below 4 kHz, which is why calls lack the high-frequency content that distinguishes “f” from “s”. (A real voice stacks many tones at once; that structure is the next course's subject.) Configure a format below and read off its cost.
★ Final quiz
The quiz draws ten questions from a larger bank, so a retake produces a fresh set. Your best grade is saved with your course progress, and every answer comes with its reasoning.