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 1/k1/k:

x(t)=2π∑k=1∞(−1)k+1ksin⁡(2πkft)x(t) = \frac{2}{\pi} \sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{k} \sin(2\pi k f t)

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 harmonics of a musical tone are spaced at multiples of the fundamental: f,2f,3f,…f, 2f, 3f, \ldots But aliased harmonics fold back at fs−kff_s - kf, so they move down as the real harmonics move up. The result is a cluster of inharmonic partials that clash with the note — and slide the wrong way as you change pitch. That "wrong way" motion is the unmistakable fingerprint of aliasing.
Diagram

Harmonics above Nyquist fold back down

Nyquist real harmonics (below Nyquist) aliases: folded down, inharmonic, sliding the wrong way
A high harmonic that would sit above Nyquist reflects off it and lands at a lower, inharmonic frequency (red). The higher the true harmonic, the lower its alias — so the aliases move opposite to the notes you play.

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.

blep(t)=∫−∞tsinc⁡(τ) dτ  =  12+1πSi⁡(πt)\text{blep}(t) = \int_{-\infty}^{t} \operatorname{sinc}(\tau)\, d\tau \;=\; \tfrac{1}{2} + \tfrac{1}{\pi}\operatorname{Si}(\pi t)

where Si⁡\operatorname{Si} 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.

Diagram

Sinc → integrate → band-limited step → residual

windowed sinc (band-limited impulse) integral = band-limited step residual = band-limited step − ideal step (this is what we add) the residual is zero away from the jump — a small, local patch
Integrating a windowed sinc gives a smooth, band-limited step (teal). Subtracting the ideal instantaneous step (orange) leaves the residual (red): a short correction that is zero everywhere except around the discontinuity. That residual is exactly what we add to the naive waveform.

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 nn, a linear-phase BLEP needs to start modifying samples before nn — 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.

Linear-phase vs. minimum-phase, same magnitude:
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:

  1. 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.

  2. Take the log-magnitude spectrum

    DFT the impulse, then take log⁡∣X[k]∣\log\lvert X[k]\rvert. Discarding the phase and keeping only magnitude is what lets us rebuild a new, minimum phase.

  3. 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.

  4. Exponentiate back

    DFT the folded cepstrum and take the complex exp⁡\exp. Inverse-DFT gives a minimum-phase impulse with the same magnitude response as the original sinc.

  5. 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:

  1. Find the sub-sample offset. The reset almost never lands exactly on a sample. If the phase wrapped to pp with increment Δ\Delta per sample, the discontinuity happened a fraction d=p/Δd = p / \Delta of a sample before the current sample. This fractional offset is why the table is oversampled: we read it at (i+d)×oversampling(i + d) \times \text{oversampling} to get the right shape for this particular edge.
  2. Scale by the jump height. A sawtooth reset drops by 2 (from +1 to −1), so we add −2×residual-2 \times \text{residual}. 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.
  3. 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 one bug everyone writes first. The residual from a discontinuity spills into future samples. If your output loop overwrites each sample with a fresh naive value after a previous edge has already added its correction there, you erase the correction and nothing improves. Compute the naive signal first, then accumulate BLEP residuals on top — never re-assign a sample you may have already patched.

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.

Hard sync for free. A phase reset forced by a second oscillator (hard sync) is also just a discontinuity. Drop a MinBLEP at the forced reset and hard sync — normally a notorious aliasing nightmare — comes out clean, using the exact same machinery. This generality is a big part of why MinBLEPs became a workhorse of virtual-analog synthesis.

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.

2200 Hz
Waveform (time domain) — a few periods
Frequency Spectrum (dB) — blue lines mark true harmonics

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.