Aliasing you can hear
Play a sine above half your sample rate and it does not disappear and it does not sound high. It comes back down. This page sweeps a tone past that line so you can hear the fold, watch it in the spectrum, and then switch on the filter that is supposed to prevent it.
- Your sample rate
- unknown Hz
- Nyquist
- unknown Hz
- Tone asked for
- 440 Hz
- Tone you hear
- 440 Hz
The sample rate is not this page's to choose. It is whatever your device handed the browser, and every number above follows from it.
The one line the whole page is
A sine at frequency f, sampled at rate fs, gives exactly the same
sequence of numbers as a sine at
alias(f, fs) = |f − round(f / fs) × fs|
Write f as k·fs + r, with k = round(f/fs), so
r lands between −fs/2 and +fs/2. Then
sin(2πfn/fs) = sin(2πkn + 2πrn/fs), and since k and
n are whole numbers, the first term is a whole number of turns and contributes
nothing. What is left is a sine at r. A negative r is the same tone
upside down, which is why the absolute value is there and why the fold changes the pitch and
nothing else.
The frequencies where the sine vanishes
At every whole multiple of fs/2 a sine starting at phase zero is sampled exactly on
its zero crossings, and the recording is silence. Slide to Nyquist
and listen: nothing. That is not a bug in the page and it is not a limit of your hardware. A cosine
at the same frequency comes out at full level, alternating between +1 and −1. The silence
belongs to the phase, not to the frequency, and it is the reason every measurement here has to
know about those points instead of asking for the loudest bin and taking whatever it gets.
Turning the filter on
An anti-alias filter has to sit before the sampler. Once a tone has folded there is nothing left in the recording that separates it from a tone that was always down there, so a filter applied afterwards removes the alias and the honest signal at that pitch with the same hand.
Web Audio has no such place, so this page makes one. The tone is generated at eight times your sample rate, the filter runs there, and every eighth filtered value is kept. That is a model of sampling rather than sampling itself, and it is honest up to four times your sample rate. Above that the tone folds inside the model before the filter ever sees it.
The filter is a Butterworth cascade built from the same second order sections Web Audio's
BiquadFilterNode uses in lowpass mode. What each order buys, and what it costs, at
your rate:
| Order | at 1.5 × Nyquist | at 2.5 × Nyquist | at 4 × Nyquist | cost at 0.98 × Nyquist |
|---|---|---|---|---|
| measured once the audio engine starts | ||||
The decibels an octave in the menu above are the ANALOG figures, and this filter is a little steeper than that. The bilinear transform squeezes the whole infinite analog frequency axis into the band below Nyquist, so an octave near the top of the band covers more of the analog curve than an octave near the bottom. Measured between two and four times the corner, every order comes out about 1.2 times its analog slope. The menu is therefore conservative, which is the direction that does not overstate the filter.
The last column is the part a checkbox does not tell you. A Butterworth is three decibels down at its own corner and keeps falling, so a corner placed below Nyquist takes real signal off the top of the band, and a steeper filter takes more of it. There is no order that gives a wall at Nyquist and leaves the band underneath untouched, which is why oversampling converters exist.
This page checks itself
not run yet
The check renders the tone through the same audio graph you are listening to, into an offline context, takes a transform of the result, and compares the peak against the arithmetic above and against a table computed in Python before this page was built. Three routes to the same number. If they ever disagree the line above turns red and says by how much.
| Rate | Asked | Formula | Rendered | Python | Off by |
|---|