1. Signals & Sampling
From continuous waves to discrete numbers
Every sound your computer plays, every photo your phone captures, every radio transmission decoded by your Wi-Fi chip — all of it passes through the same fundamental operation: converting a continuous, analog signal into a stream of discrete numbers. Understanding how that conversion works, and where it can go wrong, is the foundation of all digital signal processing.
What Is a Signal?
A signal is a quantity that varies over time (or space). A microphone converts air pressure into a varying voltage. A camera sensor converts light intensity into varying charge. A thermometer converts temperature into varying resistance. In each case, the signal is a continuous function — at every instant in time, it has some value.
Mathematically, we write a signal as x(t), where t is time and x is the value at that moment. A pure tone — like a tuning fork — produces a sinusoidal signal:
x(t) = A · sin(2π · f · t)
where A is the amplitude (how loud) and f is the frequency in Hertz (how many complete cycles per second).
Real signals — speech, music, images — are sums of many such sinusoids at different frequencies and amplitudes. The full range of frequencies present in a signal is called its bandwidth.
Sampling
Digital systems cannot store an infinite stream of continuous values. Instead, we take samples: we measure the signal's value at regular intervals and record those numbers. The gap between measurements is the sampling period T, and its reciprocal is the sample rate (or sampling frequency):
fs = 1 / T (samples per second, i.e. Hz)
For example, a sample rate of 44,100 Hz means we measure the signal 44,100 times every second, storing one number each time.
The key question is: how often do we need to sample to capture all the information in the original signal?
The Nyquist–Shannon Sampling Theorem
In 1949, Claude Shannon formalized the answer into what is now one of the most important theorems in engineering:
The threshold fs / 2 is called the Nyquist frequency or Nyquist limit. It is the highest frequency that can be faithfully represented at a given sample rate.
Intuitively: to distinguish one cycle of a wave from the next, you need at least two samples per cycle — one near the peak, one near the trough.
Aliasing
What happens when you violate the Nyquist criterion? High-frequency components fold back and appear as lower frequencies in the sampled signal. This phenomenon is called aliasing.
The mathematics: if you sample a frequency f at rate fs, and f > fs/2, the aliased frequency that appears is:
falias = |f mod fs - round(f / fs) · fs|
which simplifies in many cases to falias = |fs - f| (when fs/2 < f < fs).
Aliasing is not recoverable after the fact. Once the samples are taken, the original high-frequency information is gone.
Anti-Aliasing Filters
The solution is to prevent aliasing before it happens. A low-pass filter (also called an anti-aliasing filter) is placed before the analog-to-digital converter. It attenuates all frequencies above the Nyquist limit fs/2, so they cannot fold back into the sampled signal.
In a CD player's recording chain:
- The microphone captures the full analog signal (up to ~100 kHz or more).
- An anti-aliasing filter cuts everything above ~22 kHz.
- The filtered signal is sampled at 44,100 Hz.
Modern systems often oversample — sampling at a much higher rate than necessary (e.g. 192 kHz), then digitally filtering and downsampling. This makes the analog filter design easier, since there is a large margin before any aliasing could occur.
Reconstruction
Given a set of samples, how do we recover the original continuous signal? The Nyquist theorem guarantees it is possible (when the theorem is satisfied), and even tells us how.
Ideal reconstruction uses the sinc function: each sample is replaced by a scaled sinc pulse, and all these pulses are summed:
x(t) = Σ x[n] · sinc(fs · t − n)
where sinc(x) = sin(πx) / (πx). The sinc function has the remarkable property of being 1 at one sample point and 0 at all others, so each sample contributes exactly its own value at its own time, and the overlapping tails fill in the values between samples.
In practice, sinc interpolation requires an infinite-length filter, so real systems use finite impulse response (FIR) filters — windowed approximations that are very close to ideal. For most applications the difference is inaudible or invisible.
CD Audio: A Worked Example
Compact Disc audio uses a sample rate of 44,100 Hz. Why that number?
- Human hearing extends from roughly 20 Hz to 20,000 Hz.
- The Nyquist theorem requires fs > 2 × 20,000 = 40,000 Hz.
- 44,100 Hz was chosen to provide a margin above 40 kHz, and also for historical reasons related to video tape storage rates used in early digital recording.
With 44,100 Hz sampling, the Nyquist limit is 22,050 Hz — safely above the top of human hearing. The anti-aliasing filter cuts in above 20 kHz, the remaining frequencies are sampled cleanly, and reconstruction reproduces everything a human ear can detect.
- 8,000 Hz — telephone audio (only needs to cover 300–3,400 Hz for voice intelligibility)
- 22,050 Hz — AM radio quality; Nyquist limit 11,025 Hz
- 44,100 Hz — CD audio; covers full human hearing
- 48,000 Hz — professional video and broadcast audio
- 96,000 / 192,000 Hz — high-resolution audio; large oversampling margins
Key Takeaways
- A signal is a continuous function of time; sampling converts it to a discrete sequence of numbers at regular intervals.
- The sample rate fs (in Hz) determines how many measurements are taken per second.
- The Nyquist–Shannon theorem: you must sample at more than twice the highest frequency in the signal (fs > 2 · fmax).
- The Nyquist frequency fs/2 is the highest frequency that can be faithfully represented at a given sample rate.
- Aliasing occurs when fs < 2 · fmax: high frequencies fold back and appear as spurious low frequencies. It cannot be undone after sampling.
- Anti-aliasing filters remove frequencies above fs/2 before sampling to prevent aliasing.
- Perfect reconstruction from samples is possible via sinc interpolation; practical systems use FIR filter approximations.
- CD audio (44,100 Hz) samples fast enough to cover the full range of human hearing (20–20,000 Hz) with margin to spare.
Try It — Sampling Visualizer
Drag the sliders to change the signal frequency and the sample rate. Watch what happens to the reconstructed signal as you bring the sample rate below twice the signal frequency.