14. MinBLEP Anti-Aliasing
Building sawtooths and squares that don't alias
The oscillators article drew a sawtooth by ramping a value from −1 to +1 and snapping back. It sounds right in a diagram. Generate it that way on a real synthesizer and it sounds wrong — a harsh, metallic buzz sitting on top of the note, changing pitch in the opposite direction as you play up the keyboard. That buzz is aliasing, and it is the single most important problem to solve when you synthesize classic waveforms digitally.
This article is about one of the most elegant solutions: the minimum-phase band-limited step, or MinBLEP. It fixes aliasing by correcting the waveform only at its discontinuities, leaving the smooth parts untouched. To get there we need to understand exactly why the naive approach fails, what a "band-limited step" is, and why the word minimum-phase earns its place in the name.
Why the Naive Sawtooth Aliases
Recall from Signals & Sampling that a sampled signal can only represent frequencies below the Nyquist frequency — half the sample rate. Any energy above Nyquist doesn't vanish; it folds back down into the audible range as a false, inharmonic frequency.
Now look at what a sawtooth actually contains. Its Fourier series has energy at every harmonic, with amplitudes falling off only as :
That sum is infinite. A mathematical sawtooth has harmonics stretching up forever, because the instantaneous vertical drop at the end of each cycle is a discontinuity, and a discontinuity requires infinitely many frequencies to represent. When you evaluate the ideal ramp at integer sample positions — the naive approach — every harmonic above Nyquist folds back down.
The Key Idea: Correct Only the Discontinuities
Here is the insight that makes BLEPs work. A sawtooth is almost band-limited. The linear ramp between resets is perfectly smooth — it contains no dangerous high frequencies. All of the aliasing energy comes from the instantaneous jumps: the vertical drop at the end of each cycle. Between those jumps, the naive waveform is already correct.
So instead of rebuilding the entire waveform from band-limited pieces, we can leave the naive oscillator alone and patch each discontinuity. Replace each instantaneous step with a band-limited step — a step that rises smoothly, containing only frequencies below Nyquist. That patch is small, local, and cheap.
Two closely related techniques grew from this idea:
- BLIT (Band-Limited Impulse Train) synthesizes waveforms by summing band-limited impulses and integrating them. It works, but every sample requires evaluating a sum of sincs, and features like hard sync are awkward.
- BLEP (Band-Limited stEP) takes the simpler route: run a cheap naive oscillator, then add a correction signal at each discontinuity. This is what we'll build.
What Is a Band-Limited Step?
An ideal step function jumps from 0 to 1 instantaneously. Its spectrum extends to infinity — that is exactly the problem. A band-limited step is the closest we can get to a step using only frequencies below Nyquist.
We can derive it in two moves. Start with the ideal "brick-wall" low-pass filter, whose impulse response is the sinc function. That sinc is a band-limited impulse. Now integrate it: the integral of an impulse is a step, so the integral of a band-limited impulse is a band-limited step.
where is the sine integral. In practice the infinite sinc is truncated to a few zero-crossings on each side and multiplied by a window (a Blackman window works well) to tame the truncation ripple, exactly as in the windowing article.
Notice the last row: we don't store the band-limited step itself, we store the residual — the difference between the band-limited step and the ideal step. Away from the jump the residual is zero, so adding it changes nothing there. Right at the jump it supplies the correction that turns the instantaneous edge into a smooth, alias-free one.
Why Minimum Phase?
If you build the residual from a symmetric windowed sinc, it is linear-phase: the correction is symmetric around the discontinuity, spreading equally into the past and the future. The problem is the past half. To correct a jump at time , a linear-phase BLEP needs to start modifying samples before — samples the oscillator has, in a real-time setting, already produced and sent to the speakers. That forces you to run the whole oscillator delayed by half the kernel length.
A minimum-phase version fixes this. Among all filters with the same magnitude response, the minimum-phase one packs its energy as early as possible — it is causal and front-loaded. The MinBLEP residual is (almost) zero before the discontinuity and does all of its work after it. No look-ahead, no bulk latency. That is precisely what you want for a live oscillator, and it is the reason the technique is called Min-BLEP rather than just BLEP.
| Property | Linear-phase BLEP | MinBLEP |
|---|---|---|
| Ringing | Symmetric (before & after the jump) | Concentrated after the jump |
| Latency | Half the kernel length | Essentially none |
| Causal | No (needs look-ahead) | Yes |
| Magnitude response | Identical | Identical |
Both remove the same aliasing. Minimum-phase just moves the "cost" (the ringing) to after the edge, where it doesn't require seeing the future.
Constructing the MinBLEP Table
The magic step is turning our symmetric windowed sinc into its minimum-phase twin without changing its magnitude spectrum. The standard tool is the real cepstrum, which lets us manipulate phase and magnitude independently. The recipe:
-
Windowed sinc
Generate a sinc spanning several zero-crossings, oversampled so we can later place it at fractional sample positions, and apply a Blackman window.
-
Take the log-magnitude spectrum
DFT the impulse, then take . Discarding the phase and keeping only magnitude is what lets us rebuild a new, minimum phase.
-
Fold the cepstrum
Inverse-DFT the log-magnitude to get the real cepstrum, then double the "causal" half and zero the "anticausal" half. This is the minimum-phase construction.
-
Exponentiate back
DFT the folded cepstrum and take the complex . Inverse-DFT gives a minimum-phase impulse with the same magnitude response as the original sinc.
-
Integrate & subtract
Cumulatively sum the min-phase impulse to get the band-limited step, normalize it to settle at 1, then subtract the ideal step to store the residual table.
This whole procedure runs once, at startup. The result is a small lookup table — a few hundred oversampled points — that captures the correction shape. At audio time we never touch a sinc or a DFT again.
Applying the MinBLEP at Runtime
Now the cheap part. Run an ordinary phase-accumulator oscillator. Each sample, advance the phase and emit the naive value. Whenever the phase wraps — a discontinuity — do three things:
- Find the sub-sample offset. The reset almost never lands exactly on a sample. If the phase wrapped to with increment per sample, the discontinuity happened a fraction of a sample before the current sample. This fractional offset is why the table is oversampled: we read it at to get the right shape for this particular edge.
- Scale by the jump height. A sawtooth reset drops by 2 (from +1 to −1), so we add . A square wave has two edges per cycle: a −2 jump at the half-way point and a +2 jump at the wrap, each getting its own BLEP.
- Mix the residual into the output. Add the scaled residual across the next handful of samples (the table's length in samples). Because the residual decays to zero, its influence ends after a few samples and the naive waveform takes over again.
The cost is tiny: only the few samples following each discontinuity get extra work, and discontinuities happen just once or twice per cycle. Everything in between is a plain, cheap ramp.
Try It
The demo below runs both oscillators side by side: the naive one (red) and the MinBLEP-corrected one (teal). Push the frequency up and watch the spectrum. In the naive trace, extra spikes appear between the true harmonics (the blue guide lines) and drift as you change pitch — that's aliasing. The MinBLEP trace keeps its energy on the harmonics and drives those alias spikes down by 10–30 dB. In the time domain you'll see the MinBLEP smoothing each hard edge into a short, band-limited transition with its characteristic one-sided ringing.
Try It — Naive vs. MinBLEP
Choose a waveform, sweep the frequency, and compare the naive oscillator with the MinBLEP-corrected version. Watch the alias spikes between the harmonics collapse when MinBLEP is on.
Key Takeaways
- A naive digital sawtooth or square aliases because its instantaneous jumps contain frequencies above Nyquist that fold back as inharmonic partials — sliding the "wrong way" as you change pitch.
- All the aliasing lives in the discontinuities. The smooth parts of the waveform are already fine, so we only need to fix the jumps.
- A band-limited step is the integral of a (windowed) sinc. We store the residual — band-limited step minus ideal step — which is zero except around the edge.
- The minimum-phase version (MinBLEP) concentrates its ringing after the discontinuity, making it causal and latency-free — ideal for real-time oscillators.
- The MinBLEP table is built once via a cepstrum-based minimum-phase transform; at runtime you just add a scaled, fractionally-offset copy of it at each discontinuity.
- Because a hard-sync reset is just another discontinuity, the same MinBLEP machinery cleans up hard sync too.
That completes our tour of sound synthesis. From oscillators and filters to envelopes, FM, wavetables, and now anti-aliasing, you have the full toolkit for building sound from first principles — and the signal-processing intuition to understand why each piece works.