DSP Toolbox · Distortion & Waveshaping

Nonlinearity — Distortion & Waveshaping

Change the mathematical relationship between input and output. Until now, many of our operations preserved the basic proportional relationship of the signal. Nonlinearity changes that — and can create frequencies that were not present in the input.

LINEAR: y = a × x NONLINEAR: y = f(x)
Start with a pure sine or load your own audio sample. Bending its input→output curve alters the shape of the waveform, generating brand new harmonics across the spectrum.

1. One experiment — three views

Listen while watching the transfer function, the resulting waveform, and its spectrum.

Signal Source
220 Hz
0 dB
0
−25 dB

Transfer function

X = input sample. Y = output sample. A straight line is linear; bending the line is waveshaping.

Waveform

Faint trace = raw input. Solid trace = processed output.

Spectrum

Sine source: fundamental + newly created harmonics, with predicted alias locations shown in red when oversampling is off. Loaded audio: actual processed spectrum.

Functiony = x
SourceSine (220 Hz)
2nd Harmonic—
3rd Harmonic—
READY · sine → function → output

Make it music

A sine wave makes the mathematics easy to see. Now load a real audio sample and try the same experiment.

AUDIO ↓ DRIVE ↓ OVERSAMPLING (UPSAMPLE 2x) ↓ NONLINEAR FUNCTION ↓ ANTI-ALIASING FILTER & DOWN-SAMPLE (2x → 1x) ↓ POST-DISTORTION LOW-PASS FILTER ↓ OUTPUT

Compare Soft Clip, Hard Clip, Asymmetric, Even Harmonics, Polynomial and the Inflator-style curve. They are all nonlinear functions, but different transfer curves reshape the signal differently and therefore create different spectra.

Push the Drive control, then switch Oversampling and the Post-Distortion LPF on and off. Notice how oversampling plus anti-alias filtering greatly reduces high harmonics folding back into the audible spectrum as aliasing.

2. First prove what linear means

Turn the sine down

x[n] → × 0.5 → y[n]

The samples get smaller, but the relationship remains proportional. A sine goes in; a smaller sine comes out. No new harmonics are created.

Now bend the rule

x[n] → f(x[n]) → y[n]

Different input values are no longer scaled by the same amount. The waveform changes shape. A periodic waveform that is no longer a pure sine requires additional harmonics to describe it.

3. Different curves → different distortion

Hard vs soft

Hard clipping abruptly stops the waveform exceeding a limit. Soft clipping bends progressively into saturation. Both are nonlinear, but they create different harmonic structures.

HARD: y = clip(gx, −1, +1) SOFT: y = tanh(gx)

Symmetry matters

If positive and negative halves are treated differently, the distortion becomes asymmetric. Watch the transfer curve lose its symmetry and notice the stronger even-harmonic content.

Instead of memorising “even harmonics = X”, change the symmetry and watch the spectrum respond.

4. Waveshaping doesn't have to mean fuzz

A nonlinear curve can be tiny and subtle or completely destructive. Saturation, clipping, harmonic enhancement, analogue-style colour, and inflator-style loudness and density enhancement all live somewhere in this family.

small bend ───────────────→ large bend subtle colour obvious distortion

The important abstraction is not the name on the plugin. It is:

What mathematical relationship are we applying between each input sample and its output?
Next · A problem we already know

5. We just created new frequencies. What happens at Nyquist?

Raise the oscillator frequency and add drive. The nonlinear function keeps generating harmonics:

f, 2f, 3f, 4f, 5f ...

Eventually some of those harmonics want to exist above Nyquist. A sampled system cannot represent them there.

Try toggling Oversampling above: watch how oversampling → nonlinear processing → anti-alias filtering → downsampling reduces spectral foldback.