Nyquist Sampling and Aliasing Calculator
Check the sample rate against the signal, see what an aliased tone turns into, and size the anti-aliasing filter.
What it does
Turn an analogue signal into a digital one and the first thing you can get wrong is the sample rate. Sample too slowly and the high parts of the signal fold back down and come out as notes that were never played. That is aliasing, and it is the single most common fault in a bad recording or a bad conversion.
The MIT signals and systems lecture notes state the rule and the reason in one breath. If the signal is band limited, meaning its spectrum is zero above some highest frequency, then it is uniquely determined by its samples as long as the sampling frequency is more than twice that highest frequency. That minimum is called the Nyquist rate, and sampling below it causes aliasing, which can be eliminated by pre-filtering to remove the frequency components that would otherwise alias.
The mechanism is easier to picture than to write down. Sampling takes the signal and multiplies it by a train of impulses, which copies the spectrum of the signal every sampling frequency. If the original spectrum is wider than the copies overlap, then a high frequency folds down and lands on top of a low one, and nothing downstream can tell the difference. The Berkeley graphics lecture makes the same point with pictures: a high frequency signal that is undersampled appears as a low frequency signal.
This page does the arithmetic. Give it the highest frequency in the signal and the sample rate, and it returns the Nyquist frequency, the sample rate the theorem asks for, how many samples per cycle you are getting at the top of the band, the cutoff an anti-aliasing filter needs, and the frequency that a signal above the Nyquist frequency will masquerade as. It also gives the dynamic range of the converter from its bit depth.
Two practical notes. The sampling theorem needs a signal that is strictly band limited, and real signals never are, which is why an anti-aliasing filter is used in front of every converter rather than trusting the maths. And the theorem gives a lower bound: sampling exactly twice the highest frequency leaves no margin at all, which is why converters are usually clocked a little higher, 48 kHz for audio instead of 44.1 kHz.
How to use
- Enter the highest frequency that matters in your signal, for example 20,000 Hz for audio.
- Enter the sample rate your converter runs at, for example 44,100 Hz.
- Read the Nyquist frequency, which is half the sample rate, and compare it with your signal.
- If the signal is above the Nyquist frequency, read the frequency it will fold down to, which is the tone you will actually hear.
- Read the sample rate the sampling theorem asks for, and remember that a real filter needs some margin on top.
- Read the anti-aliasing filter cutoff, and put the filter in front of the converter.
Formula
- f s
- Sample rate in hertz.
- f N
- Nyquist frequency, half the sample rate.
- f max
- Highest frequency in the signal.
- f alias
- Frequency a signal above the Nyquist frequency appears at.
- bits
- Resolution of the converter in bits.
The folding formula takes the signal frequency back into the band from zero to the Nyquist frequency, which is why a tone at 25 kHz sampled at 44.1 kHz lands at 19.1 kHz rather than at some arbitrary value. The dynamic range formula of 6.02 dB per bit plus 1.76 dB is the standard full scale sine wave result, and it is what sets the noise floor of a converter relative to its largest input.
Worked example
Example: a 25 kHz tone sampled at 44.1 kHz
Defaults: a highest signal frequency of 25,000 Hz, a sample rate of 44,100 Hz and a 16 bit converter.
- The Nyquist frequency is 44100 / 2 = 22,050 Hz.
- The signal at 25,000 Hz is above that, so it will alias.
- Folding it back: 44,100 - 25,000 = 19,100 Hz, which is the tone that will appear in the samples.
- The sampling theorem asks for at least 2 x 25,000 = 50,000 Hz.
- Samples per cycle at 25 kHz: 44,100 / 25,000 = 1.764, which is far too few to describe the wave.
- An anti-aliasing filter has to cut the signal off at 22,050 Hz, and a 16 bit converter gives a dynamic range of 6.02 x 16 + 1.76 = 98.08 dB.
- The tool shows 22,050.00 Hz, 19,100.00 Hz, 50,000.00 Hz, 1.764, 22,050.00 Hz and 98.08 dB.
Reference table
| Signal | Sample rate | Nyquist frequency | Frequency after folding | Rate needed |
|---|---|---|---|---|
| 25,000 Hz | 44,100 Hz | 22,050 Hz | 19,100 Hz | 50,000 Hz |
| 20,000 Hz | 44,100 Hz | 22,050 Hz | 20,000 Hz | 40,000 Hz |
| 20,000 Hz | 48,000 Hz | 24,000 Hz | 20,000 Hz | 40,000 Hz |
| 10,000 Hz | 32,000 Hz | 16,000 Hz | 10,000 Hz | 20,000 Hz |
| 8,000 Hz | 8,000 Hz | 4,000 Hz | 0 Hz | 16,000 Hz |
Limits
- The theorem assumes a signal with no energy above the highest frequency you enter, and real signals always have some.
- No filter design is modelled, so the page cannot tell you how sharp the anti-aliasing filter has to be.
- Quantisation noise is not modelled beyond the dynamic range figure, so a converter with 16 bits will not sound like a perfect copy of the input.
- Jitter and clock accuracy are not covered, and both matter in a high quality conversion.
Common mistakes
- Sampling exactly twice the highest frequency. The theorem only just holds there, with no margin for any energy above the band.
- Forgetting the anti-aliasing filter. The maths says a band limited signal is fine, and a real signal is never band limited.
- Thinking an aliased tone disappears. It does not, it turns into a different tone that is in the band and impossible to filter out later.
- Confusing samples per cycle with resolution. You need many samples per cycle to describe a waveform, not just two.
- Ignoring the converter's own bandwidth. A converter cannot sample frequencies it cannot pass, however fast it is clocked.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is the Nyquist frequency for a 44,100 samples per second converter?
22,050 Hz, which is half the sample rate. Everything above that in the input will fold back into the band.
A 25 kHz tone is sampled at 44.1 kHz. What does it turn into?
19,100 Hz, because 44,100 - 25,000 = 19,100 Hz. That is the alias, and it sits inside the band where it cannot be told apart from a real tone.
What sample rate does a 20 kHz signal need?
40,000 Hz by the sampling theorem, which is twice the highest frequency. In practice you want more than that, which is why audio converters run at 48 kHz.
Questions
What is the Nyquist rate?
Twice the highest frequency in a band limited signal. Sampling at that rate or faster is enough to reconstruct the signal exactly, in theory.
What is aliasing?
The appearance of a high frequency as a lower one after sampling below the Nyquist rate. It is unrecoverable, because the aliased tone is indistinguishable from a real one in the same band.
How do you stop aliasing?
With an anti-aliasing filter in front of the converter, cutting the signal off below the Nyquist frequency. Or by sampling fast enough that there is nothing above the Nyquist frequency to fold.
Why do audio converters run at 48 kHz?
Because 44.1 kHz is only just above the 40 kHz needed for 20 kHz audio, which leaves no room for the filter roll-off. 48 kHz gives margin.
Does the bit depth affect aliasing?
No. The bit depth sets the noise floor and the dynamic range, while aliasing is entirely about the sample rate. A converter can have plenty of bits and still alias.
Can aliasing be fixed after the fact?
Not in the sampled data, because the aliased tone is already sitting in the band. It has to be prevented before the converter, which is exactly what the anti-aliasing filter is for.
Sources
- MIT OpenCourseWare 6.003: lecture 21, sampling, the Nyquist rate and aliasing
- MIT OpenCourseWare RES.6-007: lecture 16, sampling and the sampling theorem
- Berkeley CS184: sampling, aliasing and antialiasing in computer graphics