Fuzzing out things and what saturation actually is
Sound is an alternating thing. An alternating flow. Audio signals are AC, and so is sound in the air: compression and decompression, over and over. Holding on to that one fact will carry you through most of what follows. I will assume you know audio on a surface level (you are a musician, an audiophile, or just curious) and that you remember the shape of a sine wave from school. It helps if you remember a little Calculus I, but we will not go deep into the math. I am not a mathematician or an electrical engineer, and I am not pretending to be one. Most of what follows stays light. The one exception is a section near the end, the deep end, where I go further into the electronics for the curious: it carries no more math than the rest, just more wiring, and it is clearly marked so you can stop before it and miss nothing. The topic, as the title says, is saturation.
Recently I had the chance to build an audio plugin aimed at audiophiles and music lovers in general: HF-1. It is an open source, browser-first simulation of a tube amp you can run your music through. I made it for people who want to enhance their listening while working at the PC, gaming, or just sitting with music on a Sunday afternoon. The target listener does not own a five thousand dollar tube amplifier for their headphones. HF-1 takes your system audio (Spotify, YouTube, all of it) through a virtual audio cable and hands it back to you more dynamic, more coloured, and overall more pleasant. The interface copies the feel of a classic stereo amp: you push the input, shape the tone with a deliberately basic four-knob EQ that does not even tell you which frequencies it touches, and listen. While redesigning the app I fell back into the saturation and waveshaping rabbit hole, unhappy with the crude algorithms I had picked at first. So I took the chance to revisit the topic, and I am writing this both to settle it in my own head and to leave a small teaching tool behind.
Blackboxing
Take an amplifier as a black box. Its job is to make a signal bigger, in voltage and current, than the one it started with, so it can drive passive speakers and high impedance headphones (impedance, Z, is just resistance in the AC world, and music is AC, remember?). When it comes to powering a speaker, the music itself is the current that moves the cone. You only need one cable to carry both the power and the music, because they are the same signal: the amp just makes it strong enough to do the work.
It is a black box, so you do not care how it does this. It just makes your music play. But some boxes make it play better than others. There is a "grit" to them. And one day, thanks to your nerd friend, you find out that if you swap that part that looks like a light bulb, your music might sound better at higher volumes. That bulb is quite literally reshaping your sound. And it is not that complicated to understand.
Peek inside the box
When you peek inside the box (or you do not have to, if yours has the tubes exposed) and ask how that glowing bulb shapes your sound, you walk straight into the realm of waveshaping.
Remember curves and lines on the cartesian graph from school? Some of you also remember curves that repeat themselves over and over. Periodic functions. The simplest one is f(x) = sin(x), the sine wave. That, more or less, is music. In this article I use a digital version of the most basic signal generator there is, one that makes a sine, because it is easy to follow. But everywhere you see a sine, picture your favourite song in its place, being transformed.
When your sine passes through a tube, and you push it hard enough, its points on the graph get remapped. The people who built your tube box did not actually want this: better tubes and better amps try to avoid every electrical artifact that shows up when you drive the signal too hot (look up push-pull amps, like the Marantz 8B). But somewhere along the way we started to like that imperfection.
So how do the points get remapped? Picture the tube as a transform function for your sine. The most basic shape that approximates it is tanh(x). The x axis is your input (signal amplitude, voltage), the y axis is your output (again amplitude, voltage). Written in full it is tanh(K·x), where K is a fixed number baked into the tube, its headroom: how hard you have to push before the curve starts to bend. A bigger K bends sooner (a hotter tube), a smaller one keeps more clean room. You will get K as a knob in a moment. Watch a single point ride across the curve and come out the other side:
If you stay within a certain range of volume, tanh(x) does almost nothing, because near zero it looks like the straight line f(x) = x. Your signal passes through clean.
But push the volume up and you start to touch the curved part, where tanh(x) flattens out toward its ceiling. The tube no longer lets your signal through untouched: it squeezes the peaks. In audio that is called soft clipping, softly remapping the amplitude of the wave.
A sine also goes negative, and that half is handled by the part of the curve sitting in the third quadrant, which remaps the negative values (x is the input, but so is minus x: that is not negative volume, just the part of the swing where the cone pulls in instead of pushing out, because sound is an alternating wave).
Where do harmonics come from
So the tube is compressing your sound. Fine. But compression is only half the story. Driving a signal hot through a tube brings a second guest: harmonics.
Fourier gives us the key idea: any complex wave can be seen as a sum of simpler sine waves added together. There is a beautiful visual explanation at jezzamon.com/fourier if you want to feel it rather than read it. Now picture this: if you reshape a sine by pushing it through tanh(x), then by Fourier there must be other little sines that, added together, make that new reshaped wave.
Where do they come from? Here is the honest version, because it trips people up. The tube does not contain tiny oscillators that "play" extra notes. Nothing generates new sines on purpose. The harmonics are simply the only way to describe the new shape: change the form of the wave and the story you have to tell about it now needs more sine terms. They are a consequence of the transformation, not a cause of it.
Here is a way to actually see it. Take the soft-clipped output (orange below) and pull it apart into the pure sines that make it up: the big fundamental, the original note (grey), and a little sine for each harmonic (blue). Watch the blue ones fade in as the clipping gets harder. The first of them, the 3rd harmonic, sits at the peaks in inverse polarity, pushing down exactly where the peak gets flattened: quite literally a little sine doing the clipping for you. Add the fundamental and all the little blue sines back together and you get the orange. Those little sines are the harmonics, and the bars below are the same thing drawn as a spectrum.
Those little waves are tied to the fundamental frequency. A 220 Hz sine (220 Hz being the fundamental) has its 2nd, 3rd, 4th, 5th harmonics at 220 times 2, 3, 4, 5 (440, 660, 880, 1100 Hz). Odd multiples are the odd harmonics (3rd, 5th, 7th), even multiples the even ones (2nd, 4th, 6th). Which of these a tube produces is the whole game, and it comes down to one word: symmetry.
Symmetry
From here on you have the whole instrument to play with: the lab. Press Play in the dock that just appeared at the bottom, pick a model in the tabs, and drive it. The top graph is the transfer curve, below it the wave going in and coming out, and at the bottom the harmonic spectrum. Three knobs shape the tanh model: K is the headroom we just met (how hard you push before the curve bends); Asymmetry leans the curve off-center, which we unpack under Asymmetry just below; and Knee hardness sharpens the bend from a soft round-off to a hard clip. Everything you read from here, you can hear and see in the lab. It also lives behind the sliders button in the dock, so you can pull it back up at any point further down without scrolling back here.
Odd and even symmetry
Look at tanh(x). It has a symmetry to it: flip it across both axes at once (rotate it 180 degrees around the center) and you get the exact same curve. Formally, f(-x) = -f(x). This is called odd symmetry, and it is no accident that the Taylor expansion of tanh(x) is built only from odd powers of x. In plain words: a function with odd symmetry treats its positive side as the mirror-opposite of its negative side. Push a sine through it and that symmetry is preserved in the output, and that is exactly what forces odd harmonics to appear, and only odd ones.
Try it in the lab above with the tanh tab and bias at zero: the wave bends symmetrically and only the odd harmonics show up in the spectrum. Keep driving and the sine marches toward a square wave, the most odd-harmonic-heavy shape there is.
Now, not all symmetric shapes are equal. A square and a triangle are both odd-symmetric (both made of odd harmonics only), but they fall off at very different rates:
Why does the triangle decay faster? High harmonics are what draw sudden changes. The square's change is as sudden as it gets: the value jumps, teleporting from bottom to top, a vertical cliff that takes a long tail of strong high harmonics to render. The triangle never jumps, its line stays unbroken; the only abruptness is a kink at the peak, where the slope flips from rising to falling. A kink is a gentler break than a cliff, so the triangle's high harmonics die off much faster (as 1 over n squared, versus 1 over n for the square). The lesson carries straight back to tubes: a soft knee makes a rounded wave with few, fast-fading harmonics (warm), a hard knee makes sharp corners with a long buzzy tail (harsh).
Why exactly 1 over n squared, for the curious. A triangle is just the running total of a square: integrate a square wave and out comes a triangle. Integration is a smoothing step that divides every harmonic by its own number once more, so the square's 1 over n picks up another 1 over n and becomes 1 over n squared. (Frequency-domain version: a triangle is a rectangular pulse convolved with itself, and convolution multiplies their spectra, so the rectangle's 1 over n shape becomes a 1 over n squared one.) Every extra degree of smoothness costs the high harmonics another factor of n.
Even symmetry, and the diode. What if a curve is not odd-symmetric? Take the most extreme case: the absolute value, |x|, which folds the whole negative half up into the positive. That is what a perfect diode does, and it is called rectification.
A diode that only lets one half through, leaving the other at zero, is half-wave rectification:
These shapes are the exact opposite of odd-symmetric: instead of mirroring the negative half, they fold it up (or throw it away). Breaking odd symmetry that hard is what generates strong even harmonics (plus a DC offset, a constant pull away from zero). There is a neat tell here: full-wave rectification (|x|) folds the wave so completely that the original note disappears, the output is purely even harmonics sitting at double the frequency and up, so a 100 Hz tone comes out as 200 Hz and beyond. Half-wave (max(0, x)) only kills one side, so it keeps the original note and stacks the even harmonics on top. As audio, both are harsh and usually unwanted. But here is where the dots connect: rectification is not a villain, it is a job. The exact same math, a curve that only passes one direction, is how a power supply turns the AC from your wall into the steady DC a tube needs to run. We will come back to this when we talk about sag, because the power supply is its own little story sitting behind the music.
Asymmetry
A real tube lives between these extremes. It is not perfectly odd-symmetric like tanh, and not brutally folded like a diode. It is gently asymmetric, and that gentle lean is the source of its character.
The simplest way to model it is to take our tanh and slide it off-center with a bias term, b: tanh(K·x + b) - tanh(b). The bias parks the signal on a slightly lopsided part of the curve, so the top of the wave gets shaped a little differently from the bottom. That broken symmetry is exactly what wakes up the even harmonics, the 2nd above all. Watch the same drive ramp, now with bias: the orange (even) bars join the party.
This is the prized "tube sound". A single-ended triode (the 300B school of hi-fi) leans on a dominant 2nd harmonic that grows smoothly with level: warmth that is always present and thickens as you push. In the lab, switch from the tanh tab to the 3/2 triode tab: that curve is not invented, it comes from the actual physics of a triode (the Child-Langmuir law, where the curve is asymmetric by nature), and the only knob left is the bias, exactly the one real choice an amp designer makes. Push further to the Koren tab and you get a published model of a real 12AX7 measured inside a real circuit, the gold standard for this kind of simulation.
So: saturation, even and odd harmonics, all of it comes down to the symmetry or asymmetry of the transfer function that the tube imposes while it makes your signal bigger. Hold that, and the rest is detail.
Intermodulation, and the mud problem
Everything so far used a single sine. Real music is not one note, it is dozens at once. And the moment you push more than one tone through the same curve at the same time, a new artifact shows up that is not a harmonic at all: intermodulation distortion (IMD).
Here is the intuition. A nonlinearity does not just multiply each tone by itself (which makes clean harmonics at 2x, 3x the note). It also multiplies the tones by each other. Two notes at f1 and f2 produce extra tones at their sum and their difference, f1+f2 and f1-f2, and a whole family beyond. The catch: these new tones are usually not musically related to either note. On a single instrument that is subtle. On a dense mix it piles up into an inharmonic haze: the "mud" of digital distortion. The single worst offender is bass energy modulating everything above it, the low end smearing into the mids.
A real tube does this too, by the way. It is part of why heavy distortion on a full mix sounds worse than on one guitar. So if your goal is to enhance finished music, like HF-1 does, you want the warmth (the harmonics per note) without the cross-talk mud.
How I plan to deal with it in HF-1: go multiband. The idea is simple, and the real trick is always to treat the signal before you saturate it. Split the signal into a few frequency bands, run each band through its own tube curve, then add them back together:
┌──> [ low band ] -> tube ─┐
input ──> split ──> [ mid band ] -> tube ─┼──> sum -> out
└──> [ high band ] -> tube ─┘
Two tones in different bands never meet at the same nonlinearity, so they can never multiply: the cross-band IMD is gone. You still get full, musical IMD within a band, and crucially you kill the worst offender by giving the bass its own band so it stops smearing into everything else. You keep the honest, time-domain physical model (real harmonics, real bloom with level, plays nicely with sag), you just stop the mud. Three bands is a sweet spot, and you can even voice them differently (a gentler tube on the lows). The price is the phase shift of the crossover filters, which you keep clean with standard Linkwitz-Riley crossovers.
There is a more extreme path I will only mention: do the harmonic generation in the frequency domain (or with a Hilbert transform), synthesizing each note's harmonics directly so tones never multiply at all. That gets you literally zero IMD, voiced with Koren's coefficients, but you pay for it: it betrays the physical model, it can sound a little sterile, and it is fussy about phase and transients. For HF-1, multiband keeps things alive and honest while still cleaning up the mud, so that is the road I am taking.
The digital catch: sampling and Nyquist
There is one more thing that has nothing to do with tubes and everything to do with doing this on a computer. A real valve works on a continuous, smooth signal. A computer cannot store a smooth curve: it keeps a list of numbers, snapshots of the signal taken at a fixed rate. A CD samples 44,100 times a second; video and most pro audio use 48,000.
Why those numbers? The Nyquist-Shannon theorem: you can perfectly rebuild a continuous signal from its samples only if you sample more than twice as fast as its highest frequency. So 44,100 samples a second can carry everything up to 22,050 Hz, and 48,000 covers up to 24,000 Hz. Human hearing tops out around 20,000 Hz, so both comfortably cover everything you can hear. That ceiling, half the sample rate, is the Nyquist limit.
The figure below is the same idea shrunk to numbers you can see. Picture the window as one second of time. The sixteen evenly spaced ticks are the sample rate: sixteen samples a second, 16 Hz. The slider sets the signal's frequency in Hz, so its Nyquist limit is 8 Hz, half of sixteen. The grey wave is the true signal, the dots are the only thing the computer keeps, and the coloured line is what those dots reconstruct to.
sample rate 16 Hz · Nyquist limit 8 Hz · grey = signal, dots = samples, green/red = reconstruction
The reconstruction is the surprising part, and it is worth slowing down on. It is not straight lines connecting the dots. Below the Nyquist limit there is exactly one smooth, band-limited wave that passes through any given set of samples, and a specific interpolation (the sinc, or Whittaker-Shannon, reconstruction) finds it. Push the slider to 6 Hz: the dots look far too sparse, barely three per cycle, and you would swear they could not carry a clean sine. They do. Run them through that interpolation and out comes the exact original. That is the whole magic of the theorem: a handful of points per cycle is enough, as long as you stay under Nyquist and reconstruct properly.
Now push past 8 Hz. The dots fit a lower frequency just as well as the real one, and the reconstruction folds down to that impostor: an alias. And right at 8 Hz, exactly Nyquist, something sharper happens. If the samples land on the signal's zero crossings, every sample reads zero and the reconstruction is silence. That is not a trick of the drawing, it is real: sampling a sine at exactly twice its frequency can capture its full swing or capture nothing at all, depending only on where the samples fall. That ambiguity is exactly why the theorem demands more than twice the frequency, never exactly twice.
Why this bites a tube simulation
Remember that driving a tube hard generates harmonics, reaching high up the spectrum (a near-square wave has a very long tail). Any harmonic our curve generates above Nyquist cannot exist in the digital world, so it folds back down and lands on some frequency that is not a multiple of the note. That inharmonic junk is aliasing, and it is the sound of cheap digital distortion: brittle, fizzy, wrong.
Open the meters from the dock (the waveform button) and watch the spectrum: the green ticks mark where harmonics belong, anything between them is aliasing. To provoke it, raise the pitch and the drive, pick a hard knee, then toggle AA off and on in the dock. With anti-aliasing on, the curve runs at a higher internal sample rate so the harmonics have room to exist and get filtered before they can fold. With it off, the fizz creeps in between the ticks. Same curve, same math, the only difference is doing the nonlinear step at a higher rate (oversampling). It is the one tax every digital saturator has to pay.
Sag: the power supply has a memory
Everything up to now is memoryless: one fixed curve, same input gives the same output, always. A real amp is not like that, and this is where the rectifier from earlier comes back.
The energy that moves your speaker does not come from the input signal, it comes from the power supply. The signal only opens and closes the valve, deciding how much of the supply's energy gets through. That supply has to be steady DC, because the tube's operating point has to sit still. Your wall gives AC, so the amp rectifies it (those diodes, doing their one-way job) and smooths it with a big reservoir capacitor.
Now the punchline. Hold the Signal peak button and watch the supply (B+) sag: when the amp suddenly demands a lot of current, a tube rectifier (which has real resistance) cannot refill the reservoir fast enough, so the voltage dips for a few tens of milliseconds. For that moment the whole curve shrinks: less gain, less headroom. That breathing, that give under a hard hit, is sag, and it is the one place where our flat little curve grows a memory of what just happened.
The deep end: what a curve still cannot do
Sag was the first crack in "memoryless," and it is not the only one. A real tube has a handful of behaviors that no fixed curve, not even a measured Koren one, can reproduce, because they depend on what happened a moment ago or on which note you played. This is the deep end of the pool. If you came for the warmth and not the wiring, the section above was a fine place to stop.
The bias breathes. We set the operating point off-center once and walked away. A real stage cannot: the cathode sits on a resistor with a capacitor across it, and when you drive it hard, charge piles up and the bias drifts. The curve's lean shifts with how hard you are pushing, so the even-harmonic warmth blooms on a swell and settles when you back off, instead of sitting at one fixed amount. It is part of why a tube seems to "open up" when you lean into it.
The grid can choke. Push the grid positive and it starts to conduct, dumping charge into the coupling capacitor that carries the signal to the next stage. That charge shoves the bias hard negative for a moment, and the tube goes briefly silent right after the hit, a tiny gasp before it recovers. That is blocking distortion: the stutter you hear when a tube amp is driven well into the red.
The curve floats in voltage. We read the tube's current at one fixed plate voltage. In the real circuit the plate voltage and current are not free to pick each other: the plate resistor ties them together (Ohm's law on the load), so the operating point slides along a line, the load line. The honest transfer is where the tube's physics crosses that line, not a slice at one voltage. Solve it once, bake it into the table, and the shape gets a little truer for nothing at runtime.
It hears frequency. A real stage is not the same at 100 Hz and 10 kHz. The coupling capacitors roll the lows off between stages, and the Miller effect (the tube's sliver of grid-to-plate capacitance, multiplied by the stage's gain) rolls the highs off and bends them differently. So the harmonics you make depend on the note you played. A single memoryless curve, however well measured, plays the same at every pitch. To get this you have to weave filters around the nonlinearity, not just inside it.
None of these change what saturation is. They are the difference between something that sounds like saturation and something that feels like a tube: memory, and an ear for frequency, layered on top of the curve. Sag was the first; these are the rest.
What it takes to build a believable one
Pulling the whole thing together, here is the shape of a tube simulation that holds up:
- One fixed curve, calibrated once. Pick the headroom so your normal level sits where you want it, then leave it alone. Drive lives in the input gain, not in the curve.
- Asymmetry from bias. The even harmonics that read as warmth come from an off-center operating point, not from anything magic. Remove the DC it creates.
- Graduate to a measured curve when you care. The Koren model of a real tube inside a real circuit, baked into a lookup table, costs the same to run as a
tanhbut stops you guessing. - Soft knee, fast-fading harmonics. Low harmonics are the musical part. Hard corners throw energy into the high harmonics: harshness in the analog world, aliasing in the digital one.
- Oversample around the nonlinearity, or the foldback lands on the wrong frequencies.
- Treat the signal before you saturate it. Multiband splitting, so the bass gets its own band and stops smearing into everything else (IMD) under one shared curve.
- Give the supply a memory for sag, so the amp responds to how hard you hit it.
- Let the rest move too. Sag is only the first memory effect: the bias breathes with level, the grid can choke on a hard transient, and the real curve depends on the note. That layer is where sounds like saturation becomes feels like a tube.
- In and out, nothing else, for the user. A real amp has no "drive" knob: you push the input and set the output, and that is the whole control surface.
That last point is the whole philosophy of HF-1: hide the DSP, expose an amplifier. You push it, it pushes back, and your Sunday afternoon sounds a little warmer.
Further reading
- Norman Koren, Improved vacuum tube models for SPICE, the source of the measured tube curves.
- David Yeh, CCRMA, publications, including Automated Physical Modeling, Part II, on turning these into real-time DSP.
- An interactive guide to the Fourier transform, if the harmonics part stayed fuzzy.
- Rod Elliott, soft clipping.
