subch.us pedal lab · notes

What the lab is doing

The Pedal Lab does not imitate pedals; it solves their circuits. This is the reading behind it: where the device equations come from, how the solver finds the answer 48,000 times a second, and, the part that matters if you want to use the lab, what each component does to the sound and why. Every figure on this page was computed by the same engine the lab runs, not drawn.

  1. SPICE and its models
  2. The diode: Shockley's equation
  3. The transistor: Ebers-Moll
  4. The op-amp macro-model
  5. The delay line: SPICE's T element
  6. Kirchhoff in a matrix: MNA
  7. Capacitors through time: companion models
  8. Newton-Raphson
  9. Why it runs in real time
  10. What the parts do to the sound
  11. Sources

SPICE and its models Berkeley, 1973

SPICE, the Simulation Program with Integrated Circuit Emphasis, was written at UC Berkeley by Laurence Nagel under Donald Pederson and released to the public in 1973; the 1975 rewrite, SPICE2, is the ancestor of every circuit simulator in use today, including ngspice and LTspice. Nagel's thesis on SPICE2 is still the clearest description of how one is built: the device equations, the numerical integration, the Newton iteration and the tricks that keep it converging. Almost everything the lab does is in that document.

"SPICE model" is used loosely for two different things. One is the equations a simulator uses for a kind of device: the diode law, Ebers-Moll or Gummel-Poon for a transistor. The other is a parameter set that fits those equations to one real part, the .model 1N4148 D(IS=2.52n N=1.752 …) lines you find in vendor libraries. The lab uses the classic equations with simplified parameter sets: enough to sound and bias like the real thing, small enough to solve per sample.

L. W. Nagel and D. O. Pederson, "SPICE (Simulation Program with Integrated Circuit Emphasis)", UC Berkeley ERL Memorandum M382, April 1973.

L. W. Nagel, "SPICE2: A Computer Program to Simulate Semiconductor Circuits", PhD thesis, UC Berkeley ERL Memorandum M520, May 1975. The primary source for the whole method.

The living descendant: ngspice, whose manual documents every model parameter, and whose source is where the convergence helpers below can be read in C.

The diode: Shockley's equation (1949)

A p-n junction passes a current that grows exponentially with the voltage across it. William Shockley derived the law from the physics of the junction in 1949; it is the whole reason a diode clips.

I = IS · ( e V / (n·VT) − 1 ) VT = kT/q ≈ 25.85 mV at 27 °C

IS, the saturation current, sets where the curve takes off: a germanium diode has a much larger IS than silicon, so it conducts at 0.3 V instead of 0.6. n, the ideality factor (1 to 2), sets how sharp the knee is. The lab's parameter sets: silicon 1N4148 (IS = 2.52 nA, n = 1.752, the widely copied vendor model), germanium 1N34A (200 nA, 1.3), Schottky BAT41 (16 nA, 1.05) and a red LED (5·10−18 A, 2.0; fitted to a 1.7 V forward drop). Series resistance and reverse breakdown are left out; at pedal currents neither matters.

The three diode curves the lab offers. Nothing much happens until the knee, then the current climbs by a factor of ten for every 60 to 100 mV. A clipper is that knee, used as a ceiling.

W. Shockley, "The Theory of p-n Junctions in Semiconductors and p-n Junction Transistors", Bell System Technical Journal 28(3), pp. 435–489, July 1949.

The transistor: Ebers-Moll (1954)

Jewell Ebers and John Moll described a bipolar transistor as two diodes back to back, base-emitter and base-collector, each with a current source that copies most of the other's current. In the transport form SPICE uses, two exponentials give two reference currents and everything else is bookkeeping with the forward and reverse current gains βF and βR:

ICC = IS(eVBE/VT − 1) IEC = IS(eVBC/VT − 1)
IC = ICC − IEC(1 + 1/βR) IB = ICC/βF + IEC/βR

That is the model the lab uses, with IS and β chosen for silicon (2N3904/2N3906-like: 6.7 fA, β 200) and germanium (AC128-like: 200 nA, β 80). SPICE's default is the richer Gummel-Poon model of 1970, which adds the Early effect, high-current roll-off and charge storage; those change tone subtly in a real fuzz but not the biasing or the clipping, and they cost Newton iterations, so they are out. The lab's germanium transistors also have no leakage current, which in a real Fuzz Face is why it drifts with temperature.

J. J. Ebers and J. L. Moll, "Large-Signal Behavior of Junction Transistors", Proceedings of the IRE 42(12), pp. 1761–1772, December 1954.

H. K. Gummel and H. C. Poon, "An Integral Charge Control Model of Bipolar Transistors", Bell System Technical Journal 49(5), pp. 827–852, May 1970. The fuller model SPICE defaults to.

The op-amp macro-model (1974)

Nobody simulates the forty transistors inside a 4558 to hear a Tube Screamer. Boyle, Cohn, Pederson and Solomon showed in 1974 how to replace an op-amp with a handful of ideal parts that reproduce its terminal behaviour: a transconductance for the input stage, one capacitor for the dominant pole, a buffer for the output. The lab's is the minimal version of that: an input stage that turns the differential voltage into a current, limited to ±Imax; that current charges a 30 pF compensation capacitor, which gives the open-loop pole; a stiff clamp holds the node between the supply rails; a unity buffer with 100 Ω drives the output. Three numbers you would read off a datasheet fall out of it: open-loop gain (gm·R), gain-bandwidth (gm/2πC, 3 MHz by default) and slew rate (Imax/C, 1 V/µs). The last one is audible: it is why a RAT's LM308 sounds different from a TL072 in the same circuit, and you can set it per op-amp in the lab.

G. R. Boyle, B. M. Cohn, D. O. Pederson and J. E. Solomon, "Macromodeling of Integrated Circuit Operational Amplifiers", IEEE Journal of Solid-State Circuits SC-9(6), pp. 353–364, December 1974.

The delay line: SPICE's T element

Delay and reverb pedals are built around a part that is not a circuit at all: a bucket-brigade device (a chain of thousands of capacitors that pass a sample of the signal along on each clock tick) or, since the late 1990s, a PT2399 digital delay chip. Neither can be stamped into a matrix. SPICE has had an answer since the beginning: the T element, an ideal lossless transmission line, which is exactly a delay: the voltage at one end is the voltage at the other end a fixed time ago. The lab's DL part is that, with a gain: a voltage source whose value is read out of a ring buffer written one sample at a time. In the small-signal analysis it becomes gain · e−jωτ, a pure phase shift, which is why a delay with feedback draws a comb on the frequency-response plot. What makes the Delay preset sound analog rather than like a computer is everything around the chip: the low-pass filters in the loop that darken every repeat, and the feedback resistor that decides how many there are.

The transmission line element is described in Nagel 1975 (above) and every SPICE manual since; in the ngspice manual it is the "T" device. On bucket-brigade delays: F. L. J. Sangster and K. Teer, "Bucket-Brigade Electronics: New Possibilities for Delay, Time-Axis Conversion, and Scanning", IEEE Journal of Solid-State Circuits 4(3), pp. 131–136, June 1969.

Kirchhoff in a matrix: modified nodal analysis (1975)

Kirchhoff's current law says the currents into any node sum to zero. Write that for every node, with each resistor's current as a conductance times a voltage difference, and you get a linear system G·x = b whose unknowns are the node voltages. Ho, Ruehli and Brennan's 1975 paper added the "modified" part: voltage sources (which have no conductance) get a row of their own with their current as an extra unknown. Every part is stamped into the matrix with a fixed pattern; the lab's engine.js is, at heart, a stamp for each of R, C, L, V, the pot, the diode, the transistor and the op-amp, followed by a solve.

C.-W. Ho, A. E. Ruehli and P. A. Brennan, "The Modified Nodal Approach to Network Analysis", IEEE Transactions on Circuits and Systems CAS-22(6), pp. 504–509, June 1975.

Textbook treatments: J. Vlach and K. Singhal, Computer Methods for Circuit Analysis and Design, 2nd ed., Van Nostrand Reinhold 1994; L. O. Chua and P.-M. Lin, Computer-Aided Analysis of Electronic Circuits, Prentice-Hall 1975.

Capacitors through time: companion models

A capacitor's current is C·dV/dt, which is not a conductance. The trick, in Nagel's thesis, is to replace the derivative with a finite difference across one time step h. With the trapezoidal rule the capacitor becomes a conductance 2C/h in parallel with a current source that remembers the previous sample's voltage and current; with backward Euler it is C/h and a simpler memory. That pair is the capacitor's companion model, and once it is stamped the capacitor is just another resistor, updated every sample. The lab lets you choose the rule. Trapezoidal is second-order accurate but warps frequency (a 1.6 kHz corner lands where tan(πf/fs)·fs/π says, which is why oversampling helps) and can ring on stiff circuits; backward Euler never rings but damps high frequencies. The op-amp's compensation cap, whose pole is far above the sample rate, always uses backward Euler for that reason.

Newton-Raphson 1669, 1690, and 1975

Everything above is linear except the exponentials, and the exponentials are the sound. To solve a system with a diode in it you guess the diode's voltage, replace the curve with its tangent line at the guess (a resistor plus a current source: the diode's own companion model), solve the now-linear circuit, and use the answer as the next guess. Near the answer each round roughly doubles the number of correct digits; from a good guess, two or three rounds do it. That is Newton's method, and the tangent-line idea is the same one you meet for finding a root of one equation:

vk+1 = vk − F(vk) / F′(vk) or, for many unknowns, J(vk) · Δv = −F(vk)
A 2 V source through 4.7 kΩ into one silicon diode. The residual is the current that does not add up at the diode's node; Newton follows the tangent to zero, re-evaluates, and repeats. From a bad start the first tangent step wants to overshoot; SPICE's pnjlim rule (Nagel's thesis, the chapter on nonlinear DC analysis; DEVpnjlim in ngspice's devsup.c) limits a step up an exponential to a logarithmic distance, which is what the lab does too. Without it, a step from the wrong side of the knee predicts currents of amps and the next tangent is useless.

Isaac Newton described the method for polynomials in De analysi (written 1669, published 1711); Joseph Raphson gave the iterative form we use in 1690; Thomas Simpson extended it to systems of equations and to calculus in 1740. Leonid Kantorovich proved in 1948 when it is guaranteed to converge, and how fast, which is the theorem circuit simulators lean on. The engineering half, how to make it converge on a real circuit from a cold start, is Nagel's again: limiting the junction steps, adding a tiny conductance (gmin) across every junction and from every node to ground so nothing floats, and ramping the supplies up from zero for the first operating point (source stepping). The lab does all three. It also does something SPICE does not need to: it starts each sample's Newton from a linear extrapolation of the last two samples, which saves about one Newton iteration in five (2.8 to 2.2 per sample on the Muff).

I. Newton, De analysi per aequationes numero terminorum infinitas (1669; published 1711); J. Raphson, Analysis aequationum universalis (1690); T. Simpson, Essays on Several Curious and Useful Subjects in Speculative and Mix'd Mathematicks (1740). Historical account: T. J. Ypma, "Historical Development of the Newton-Raphson Method", SIAM Review 37(4), pp. 531–551, 1995.

L. V. Kantorovich, "Functional analysis and applied mathematics", Uspekhi Matematicheskikh Nauk 3(6), pp. 89–185, 1948 (the Newton-Kantorovich theorem). Modern treatment: J. E. Dennis and R. B. Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations, SIAM Classics, 1996 (orig. 1983), chapter 5.

Convergence aids for circuits: Nagel 1975, chapter 6; ngspice source, src/spicelib/devices/devsup.c (DEVpnjlim).

Why it runs in real time

A Newton iteration on the whole matrix, per sample, at 96 kHz, in a browser, would not keep up. The lab does what Yeh, Abel and Smith called the DK method: since the linear part of the circuit only changes when you touch a value, its matrix is inverted once and kept; the nonlinear parts are pulled out as a handful of ports (each diode pair one, each transistor two), and Newton runs only on those port voltages, a 1×1 to 10×10 system instead of a 27×27 one. Every node voltage then follows from the stored inverse in one multiply. Their two papers work this through for op-amp, transistor and tube circuits; the lab follows Part I without the symbolic step. The heavy inner loop, the small Newton matrix and its solve, is also compiled from Rust to WebAssembly, with the JavaScript version kept as the reference it is tested against.

D. T. Yeh, J. S. Abel and J. O. Smith, "Automated Physical Modeling of Nonlinear Audio Circuits for Real-Time Audio Effects, Part I: Theoretical Development", IEEE Trans. Audio, Speech and Language Processing 18(4), pp. 728–737, May 2010 (author's PDF). Part II: "BJT and Vacuum Tube Examples", vol. 20(4), 2012.

D. T. Yeh, "Digital Implementation of Musical Distortion Circuits by Analysis and Simulation", PhD thesis, Stanford CCRMA, 2009.

What the parts do to the sound and why the values matter

Three ideas cover most of it. A capacitor in series with the signal path is a high-pass; a capacitor to ground is a low-pass; each has a corner at f = 1 / (2π R C) with whatever resistance it sees. A diode is a ceiling: the signal gets through until it reaches the diode's knee, then it stops growing, and where a wave stops growing it gains harmonics. And a transistor or op-amp stage has a gain set by a ratio of resistors and a headroom set by the supply, and which of the two runs out first decides whether the clipping is soft, hard, or lopsided. Everything below is one of those three in a particular place.

The diodes: what clips, and how hard

The same 2.5 V peak sine through the Clipper with three diode types. The ceiling is the forward voltage: germanium around 0.3 V, silicon around 0.6, an LED near 1.7. Lower ceiling means more of the wave is flattened (more distortion, less level); the LED is barely touched at this level and stays clean until you hit it harder.

Diode type is the single biggest tonal choice in a clipper. The forward voltage sets the threshold and therefore the output level and how much of the note is clipped; the ideality factor n sets how gradual the knee is: the current multiplies by ten every 2.3·n·VT, so a higher n is a rounder corner. Germanium's reputation for smoothness comes mostly from its lower threshold (the clip starts earlier and gentler relative to the signal) and, in real parts, from leakage that the model leaves out. Stacking two diodes in series doubles the threshold: more headroom, more open, louder. Try: Clipper, D1 and D2 to LED, input level to 2 V.

Remove one diode and only one half of the wave is clipped.
The harmonic content of those two waves. A symmetric clipper produces only odd harmonics (3rd, 5th, 7th…): the hollow, square-ish sound. Break the symmetry and the even harmonics (2nd, 4th…) appear, which the ear reads as warmer and thicker: octaves and octaves-plus-a-fifth above the note. This is why many pedals ship with an odd number of diodes, or two different types.

Resistors and capacitors: corners and ratios

The Clipper's Tone control is a pot in series with a 10 nF cap to ground: a low-pass whose corner moves as the pot turns. At 50 kΩ the corner is 1/(2π·50k·10n) = 318 Hz; at 5 kΩ it is 3.2 kHz. Ten times the resistance, one tenth the corner: this is why tone pots are big and why swapping the cap for 22 nF makes the whole knob darker.

A cap in series (coupling caps, the input and output caps on every pedal) blocks DC and rolls off lows below its corner with the resistance after it. Make it smaller and the bass thins: the Rodent's 22 nF input cap into 1 MΩ passes everything above 7 Hz, but the Fuzz's 2.2 µF is doing real work: the first transistor's input impedance is only about a kilohm, so the corner sits near 60 Hz, and the same cap at 100 nF would move it to 1.4 kHz and take the whole low end with it. A cap to ground is a low-pass. A resistor in series with the signal forms a divider with whatever follows: the Clipper's 4.7 kΩ is what meters current into the diodes, and a diode's voltage only grows about 60 to 100 mV for every tenfold increase in current. Make it 470 Ω and the diodes get ten times the current: the plateau rises (0.58 V instead of 0.48 with silicon) and the corner gets harder. Make it 47 kΩ and it is quieter (0.39 V) and rounder, closer to a compressor than a clipper. Try: Clipper R1 at 470 Ω and at 47 kΩ.

The Screamer: gain that the diodes take away

The Screamer's small-signal gain as Drive turns. The op-amp is non-inverting, so its gain is 1 + Rfeedback/Rleg, and the leg is 4.7 kΩ in series with 47 nF to ground. Below the leg's corner (1/(2π·4.7k·47n) = 720 Hz) the cap is open and the gain collapses to 1; above it the gain is set by the pot. That is the famous mid hump: the lows are left clean and the diodes only get to bite on the mids and highs. The 51 pF across the feedback starts rolling the top off a few kilohertz up at full drive (with 551 kΩ around it the corner is 5.7 kHz), which is part of why the pedal is smooth rather than fizzy.
Change the leg's cap to 220 nF and the corner drops to 150 Hz: the bass gets gain too, and gets clipped too. Muddier on a guitar, and closer to what people mean by "bass mod". Same circuit, one cap.

The diodes sit in the feedback loop. As the output tries to exceed their forward voltage they start conducting, which lowers the feedback resistance, which lowers the gain: the op-amp keeps working but its gain melts away smoothly as the wave grows. That is soft clipping. Drive is just the feedback resistor, so it is also the gain, so it is also how early the diodes engage. Try: Drive at 10, then swap D1/D2 to germanium: quieter and fuzzier, because the ceiling dropped by half.

The Rodent: gain that hits the rails, then the diodes

The same 0.3 V note through the Screamer (soft clipping, diodes in the feedback loop) and the Rodent (hard clipping, diodes to ground after an op-amp that has already hit its supply rails). Each scaled to its own peak so the shapes compare: the Rodent's corners are sharper, which means more and higher harmonics: fizz.

The Rodent's op-amp runs with up to two thousand times gain (1 + 100 kΩ / 47 Ω) and the 47 Ω + 4.7 µF leg gives most of that above 720 Hz (same idea as the Screamer's leg, more extreme). With that much gain, the op-amp output slams into its power supply long before the diodes: the wave is already square when it reaches D1/D2, which then set the final level. Two clippers in a row, the first one a brick. Filter is the variable low-pass after it, and it matters more here than in any other preset because there is so much high-frequency fizz to tame. Slew rate matters too: the original uses an LM308, which is slow; set the op-amp's slew to 0.3 V/µs in the editor and the tops of the square wave tilt, rounding the highs a little. Try: Distortion at 10, Filter at 0, then at 8.

The Fuzz: no headroom, on purpose

The Fuzz at two input levels, each scaled to its own peak. At 0.4 V it is a square wave with a lopsided duty cycle; roll the input back to 0.05 V (the guitar's volume knob) and the second transistor stops running out of supply on one side and the waveform opens up. This is the "cleans up with the guitar volume" behaviour players prize, and it comes from the circuit having almost no headroom and an input impedance of about a kilohm that the guitar's pickup (RS in the preset, 10 kΩ standing in for a pickup's resistance) has to drive: the pickup and the pedal form a divider, and the guitar's volume pot changes both the level and that divider.

Two transistors, DC-coupled, with a 100 kΩ resistor from the second emitter back to the first base to hold the bias. Fuzz bypasses more of the 1 kΩ emitter resistor with a 20 µF cap: less local feedback, more gain, more fuzz. Germanium vs silicon moves the bias voltages (look at the numbers on the schematic when you swap Q1/Q2) and the knee: silicon is brighter and harsher. The asymmetry you see is the sound; a Fuzz Face that is biased "correctly" symmetric sounds like a different pedal. Try: Q1 and Q2 to silicon PNP (the supply is negative, so they stay PNP), then R3 (the 470 Ω) at 1 kΩ.

The Booster: one stage, honestly

The Booster's gain is roughly the collector resistor over the emitter resistor (plus the transistor's own few tens of ohms): 10 kΩ / 390 Ω gives 25.5 dB stock. Raise R4 and the gain falls (18 dB at 1 kΩ, 8 dB at 3.3 kΩ); the emitter resistor is negative feedback and the stage gets cleaner and more linear as it grows. Lower it to 100 Ω and you have a 36 dB stage that clips at a whisper.
Driven with 0.3 V, the 100 Ω version runs out of supply on one side first (the collector cannot go above 9 V or below the emitter), so it clips lopsided: even harmonics, the "transistor" sound as opposed to the "diode" sound. The 1 kΩ version has the headroom to pass the note.

The bias divider (430k / 43k) puts the base near 0.8 V and the collector at 5.9 V, a little above mid-supply, which is roughly where a stage has equal room to swing both ways. Move it and one side clips first: a "misbiased" booster is a distortion pedal with a particular flavour. The supply: 9 V is the ceiling on everything; the editor lets you change V1. Running a booster or a fuzz at 18 V doubles its headroom and is exactly why some players do it. Try: R2 at 22 kΩ (base too low), then V1 at 18 V.

The Muff: two clippers and a scoop

The Muff's tone stack, alone. A 39 kΩ / 10 nF low-pass on one side (corner 408 Hz), a 4 nF / 22 kΩ high-pass on the other (1.8 kHz), and a 100 kΩ pot that blends them. At the middle both corners are in play and the mids between them fall away: the scoop. Note that it only takes away: the mids sit 9 to 14 dB down depending on the knob, and only the far ends of the band get through at full level. That is why the real pedal has a recovery stage after it, and why the stack alone sounds weak.

The full Muff is four common-emitter stages like the Booster's in a row (biased by a feedback resistor from collector to base rather than a divider), with a diode pair from collector to base on the middle two. Those diodes clamp each stage's output to about a volt of swing, so the stages saturate softly and the sustain comes from the second one being driven by an already square wave. Sustain is the level into the first clipper. The 470 pF caps across the diodes roll off the very top of each clipping stage; make them 1 nF and the fizz goes away with some of the bite. The 100 Ω emitter resistors set each stage's gain (about 40 dB); the 100 kΩ base resistors and 470 kΩ feedback resistors set the bias, and the clipping stages sit with their collectors low (around 1.1 V, because the diodes conduct DC), which is part of why a Muff clips the way it does. Try: D1–D4 to LEDs (open, loud, less sustain), then C4 and C6 to 1 nF.

A table to keep

ChangeWhat it doesWhy
Diode Ge → Si → LEDHigher ceiling: louder, cleaner, less compressionForward voltage 0.3 / 0.6 / 1.7 V
Remove one diodeWarmer, thicker, a little louderAsymmetry adds even harmonics
Series cap smallerLess bassHigh-pass corner rises, f = 1/(2πRC)
Cap to ground biggerDarkerLow-pass corner falls
Gain leg cap bigger (Screamer C2, Rodent C2/C3)Bass gets distorted too; muddier, fullerThe gain's high-pass corner falls
Feedback resistor / Drive upMore gain, earlier clippingGain = 1 + Rf/Rleg
Emitter resistor upCleaner, quieterMore negative feedback, gain ≈ RC/RE
Supply 9 → 18 VMore headroom, cleaner, tighterThe rails move away
Bias off centreLopsided clipping, even harmonicsOne rail is closer than the other
Op-amp slew lowerRounder highs on square wavesOutput cannot turn corners fast enough
Input level downCleans upLess of the wave reaches the knee

Sources primary where possible

The simulator and its methods

The devices

The circuits

Circuit topologies of classic pedals are widely published and are not protected; the names here are generic. Where this page says "the lab does X", the code is the authority: the figures are regenerated from it by notes/make-figures.mjs.