DEV Community

Cover image for The Nyquist Sampling Theorem: Why Sample Rate Decides What You Can Hear
NovaSolver
NovaSolver

Posted on • Originally published at novasolver.jp

The Nyquist Sampling Theorem: Why Sample Rate Decides What You Can Hear

Hold a strobe light over a spinning car wheel and the wheel can appear to crawl backward, freeze, or drift forward slowly. Nothing about the wheel changed — it is still turning at the same speed. What changed is how often you looked at it. Each flash is a sample, and when the samples come too slowly to keep up with the motion, your eye reconstructs a rotation that was never there.

That illusion is not a quirk of strobes. It is the exact same failure that ruins a digital recording, a vibration measurement, or an oscilloscope trace when the sampling rate is set too low. The rule that tells you how fast is fast enough is the Nyquist-Shannon sampling theorem, and it is one of the few results in engineering that draws a genuinely hard line.

Why this calculation matters

Every digital system that touches the physical world has to convert a continuous signal into a finite stream of numbers. Audio, accelerometers, radio receivers, control-loop sensors, medical instruments — all of them sample. The sampling rate you choose is not a tuning parameter you can adjust later. It is a design decision baked into the hardware and the data.

The reason this matters so much is that undersampling is not a degradation you can clean up. If you record an audio track at too low a rate, no equalizer, no filter, and no amount of processing will bring back the lost detail. Worse, the energy that was above the limit does not simply vanish — it reappears in your data disguised as a lower frequency that was never in the original. That false signal, called an alias, is indistinguishable from a real one once it is in the recording. The Nyquist theorem is what lets you choose a rate that prevents the problem before it happens, because there is no fixing it afterward.

The core method

The Nyquist-Shannon sampling theorem makes a precise claim. A signal that contains no frequency components above some maximum, f_max, can be reconstructed perfectly from its samples — but only if the sampling rate is more than twice that maximum:

f_s > 2 * f_max
Enter fullscreen mode Exit fullscreen mode

Here f_s is the sampling rate in samples per second (Hz), and f_max is the highest frequency present in the signal. The threshold 2 * f_max is called the Nyquist rate. Half of the sampling rate, f_s / 2, is called the Nyquist frequency — the highest frequency your sampled data can faithfully represent.

The strict inequality matters. Sampling exactly at 2 * f_max is not enough, because a sine wave caught at precisely two samples per cycle can land on its zero crossings every time and read as a flat line. Practical systems sample comfortably above the Nyquist rate to leave room.

When the rule is violated, the failure has a name and a formula. Any component at a frequency f above the Nyquist frequency folds back into the captured band and appears at an alias frequency:

f_alias = | f - round(f / f_s) * f_s |
Enter fullscreen mode Exit fullscreen mode

The picture to keep in mind is folding. The frequency axis gets creased at every multiple of f_s / 2, and anything beyond a crease is reflected back inside. A 30 kHz tone sampled at 44.1 kHz folds down and shows up around 14.1 kHz — a clearly audible whine that was never played. Once folded, it cannot be separated from a genuine 14.1 kHz tone, because mathematically they produce the identical set of samples.

The practical defense is an anti-aliasing filter: an analog low-pass filter placed before the converter that removes energy above f_s / 2 before sampling happens. You cannot filter aliases out after the fact, so you must filter the source before the fact.

A worked example

Consider a signal whose highest meaningful component sits at f_max = 20 kHz. This is a deliberate choice for audio, because roughly 20 kHz is the upper edge of human hearing.

Step 1 — apply the theorem. The sampling rate must satisfy:

f_s > 2 * f_max
f_s > 2 * 20 kHz
f_s > 40 kHz
Enter fullscreen mode Exit fullscreen mode

So any sampling rate above 40 kHz can, in principle, capture the full audible band without loss.

Step 2 — see why the real standard is higher. Compact Disc audio uses a sampling rate of 44.1 kHz, not 40 kHz. The extra 4.1 kHz is a transition band. A real anti-aliasing filter cannot drop from full transmission to full rejection instantly; it needs a slice of frequency space to roll off. Placing the Nyquist frequency at 22.05 kHz gives the filter room to attenuate everything above 20 kHz while still rejecting energy before it reaches the fold point.

Step 3 — check the failure case. Suppose a 30 kHz component slips past a weak filter and is sampled at 44.1 kHz. It folds back to roughly 44.1 - 30 = 14.1 kHz and contaminates the recording with an audible tone. This is exactly what the 44.1 kHz choice, paired with a proper filter, is designed to prevent.

The takeaway: 44.1 kHz is not an arbitrary number. It is "more than twice 20 kHz, with margin for a realistic filter" — the sampling theorem applied with engineering judgment.

Common mistakes

Reading the rule as "twice the highest frequency." The theorem says more than twice. Sampling exactly at 2 * f_max can alias a sine to zero. Treat 2 * f_max as a floor you must clear, not a target you can hit.

Confusing the highest frequency of interest with the highest frequency present. The theorem governs the highest frequency in the signal, including noise and harmonics you do not care about. If the signal carries energy at 80 kHz, sampling for a 20 kHz band of interest will still fold that 80 kHz energy into your data unless an analog filter removes it first.

Believing a faster processor can fix aliasing later. Aliasing happens at the instant of sampling. Once two frequencies have produced the same samples, no algorithm can tell them apart. The fix is always an analog anti-aliasing filter ahead of the converter.

Forgetting the filter's transition band. Setting f_s to exactly the Nyquist rate leaves a real filter no room to roll off. Allow margin so the filter can reach full attenuation before the fold frequency.

Assuming a higher sample rate is always better. Oversampling costs storage, bandwidth, and power. The goal is a rate comfortably above the Nyquist rate for the actual signal content — not the highest rate the hardware allows.

Try the interactive NovaSolver calculator

Folding diagrams are far easier to grasp when you can move the frequencies yourself and watch the alias appear. The Nyquist Sampling Theorem Simulator — Aliasing of Sampled Signals on NovaSolver lets you adjust the signal frequency f, the sampling rate f_s, the observation duration, and the bit depth N with sliders, and it returns the Nyquist frequency f_s/2, the perceived alias frequency f_alias, the quantisation SNR, and a clear sampling-state indicator — alongside a plot of the continuous sinusoid, its sample points, and the reconstructed wave.

Related calculators

The full set lives in the frequency response and stability tools hub.

Closing note

The Nyquist sampling theorem is short to state and unforgiving in practice. Sample faster than twice the highest frequency in your signal and perfect reconstruction is possible; sample slower and you permanently lose information while gaining false aliases that masquerade as real data. The two practical habits that follow are simple: know the true frequency content of what you are measuring, and put an analog anti-aliasing filter ahead of every converter. Get the sample rate right at design time, because it is the one thing about a digital signal you cannot renegotiate afterward.

Top comments (0)