← Research

Simulated, not yet builtDesigned by a genetic algorithmFiles to download

A warm op-amp preamplifier

A hi-fi line preamplifier that sounds like a tube stage but is built with op-amps. The resistor values were not picked by hand: a genetic algorithm found them, by simulating thousands of variants and comparing each with a simulated 12AX7 tube.

3D render of the through-hole circuit board: three op-amp sockets in a row, diodes, resistors, capacitors, two blue trimpots and a green screw terminal.
The through-hole board, rendered from the KiCad design (178 × 100 mm).
Code on GitHub Downloads

Where it stands

Designed, simulated and checked, but never built or measured. Every number on this page comes from simulation (ngspice, with the NE5532 op-amp model, on the circuit as it sits on the board). The claim is not that it sounds exactly like a tube. It is that, in simulation, it has the same harmonic fingerprint as a 12AX7 stage.

At a glance

WhatStereo line preamplifier stage for hi-fi, in front of an existing power amplifier
SoundThe mild warmth of a 12AX7 stage: mostly second harmonic (H2), growing with level
Gain10 dB (×3.2)
Frequency response20 Hz to 20 kHz within ±0.11 dB
Distortion at 1 V rms0.3%, almost all H2: −50.3 dB, against −50.0 dB for the tube
Signal to noiseabout 97.5 dB relative to 1 V rms (unweighted, 20 kHz bandwidth)
Parts3 × NE5532 op-amp, 12 × 1N4148 diode, 1% metal-film resistors, 2 trimpots
Supplyregulated ±15 V

The idea

Tube amplifiers are often called warm. Much of that comes from how a triode distorts: softly and asymmetrically, with mostly second harmonic, one octave above the note. At low levels the distortion is negligible, and the louder you play, the more H2 you get. The third harmonic, which sounds harder, stays much lower.

Op-amps are the opposite: extremely clean. This design adds just the tube-like part with a few diodes, an even-harmonic generator mixed with the clean signal. How much of what, and with which resistors, is a puzzle of eleven interacting values. A genetic algorithm solved it.

Harmonics of the op-amp preamplifier against a 12AX7 tube stage Second and third harmonic in dB below the fundamental, against output level from 0.1 to 7 volts. Both rise with level. The op-amp circuit's second harmonic follows the tube's within 0.4 dB. Its third harmonic runs 1 to 3 dB below the tube's, with the same slope. -100 -80 -60 -40 -20 0.1 0.2 0.5 1 2 5 output level (V rms, 1 kHz) dB below the fundamental H2 op-amp H2 tube H3 op-amp H3 tube
Second (gold) and third (grey) harmonic against output level. Dotted: a simulated 12AX7 stage. Solid with dots: this circuit, simulated with the NE5532 model. Both lines rise together, which is the point of the design.

How it works

Signal path of one channel The input goes to an amplifier that makes the signal V1. An inverter makes minus V1. V1 feeds a first branch of three diodes and minus V1 feeds a second branch of three diodes with a trimpot. The two diode signals are added to the clean signal in a summing amplifier, which is the output. Input100 kΩ U1Again ×2.95 U2Ainverter Branch A: +V13 diodes in series clean signal (−V1)passes straight on Branch B: −V13 diodes + trimpot U3Asum, 10 dB V1 −V1 Out
One channel. The two diode branches add the even-order distortion; the clean path carries the rest. The right channel is identical.
  1. Input. A film capacitor and a 100 kΩ resistor block DC and set the input impedance.
  2. Amplifier U1A. Non-inverting, gain 1 + 39k/20k = 2.95. A capacitor makes the DC gain 1 so offset is not amplified. Its output is the signal V1.
  3. Inverter U2A. Makes an upside-down copy, −V1.
  4. Two diode branches, the heart of the sound. Branch A gets +V1, branch B gets −V1 (through a resistor and the trimpot), and each ends in three 1N4148 diodes in series, biased with about 1 mA from a filtered +15 V. The voltage across a diode is logarithmic, ln(1 + x). Branch A sees +x and branch B sees −x, so the odd terms cancel when they are added: ln(1+x) + ln(1−x) ≈ −x². That is pure second harmonic, growing with the square of the level, as in a triode. The branches are deliberately not exactly equal, which leaves a small, controlled amount of H3, also like the tube.
  5. Summer U3A. Adds the clean signal and the two diode signals. One resistor sets the total gain to 10 dB, and a small capacitor keeps the op-amp stable at high frequency.
  6. Output. A 100 Ω resistor keeps it stable with long cables, and a capacitor blocks DC.

Why three diodes per branch? The larger the voltage across the chain, the less the weak diode signal has to be amplified afterwards, and so the less noise. Three diodes give three times the signal for only √3 times the noise. The algorithm chose three by itself. The diode bias comes from a filtered supply (about 7 Hz corner, over 40 dB of hum rejection at 100 Hz) because hum on that line would otherwise end up in the signal. The trimpot balances the two branches and so sets the amount of H3 (about ±3 dB), without noticeably changing H2 or the gain. Three NE5532 chips serve both channels: one stage per chip, with the left channel in one half and the right channel in the other.

Designed by evolution

The target: a simulated 12AX7

The reference is a classic common-cathode 12AX7 stage (250 V supply, 100 kΩ plate resistor, 1.5 kΩ cathode resistor), simulated with Norman Koren's well-known tube model at 170 V on the plate and 0.8 mA. Its fingerprint at 1 V rms output: H2 about −50 dB (0.3%), H3 about −96 dB. H2 rises 6 dB for every doubling of level, H3 12 dB, and H4 and above stay far below −90 dB. Those curves are what the algorithm has to match.

Eleven knobs

The topology is fixed. The algorithm picks eleven values: ten resistors from the E24 series (100 Ω to 1 MΩ) and the number of diodes per branch (1 to 4). That is about 1018 combinations, far too many to try.

Scoring a candidate

For every candidate, ngspice runs a transient simulation at six output levels (0.1 to 7 V rms, a 1 kHz sine), an AC analysis and a noise analysis. The cost, lower is better, adds up the deviation from 10 dB gain, the RMS difference in dB from the tube for H2 over all levels, the same for H3 with less weight, a penalty if H4 or H5 exceed the tube's, a penalty if the response strays more than ±0.2 dB between 20 Hz and 20 kHz, and a penalty if the signal to noise falls below 100 dB. Designs with a gain far from 10 dB are thrown out by a quick AC check, before the expensive simulation.

Evolution

A population of 48 designs, 40 generations, a genetic algorithm with simulated binary crossover and polynomial mutation on integers (the index into the E24 series), eight ngspice processes in parallel at 3 to 5 seconds per evaluation. After the run, a local search tries the neighbouring E24 values for each resistor. In total about 5,758 circuits were evaluated.

Cost per generation for the three genetic algorithm runs Cost of the best design in each generation, lower is better, on a logarithmic scale, for 40 generations. Run 1 ends at 9.7, run 2 at 11.5 and run 3, started from the first two, at 2.95. 3 10 30 0 10 20 30 40 generation cost of the best design 9.7 run 1: random start 11.5 run 2: failed 3.0 run 3: from runs 1 and 2
Cost (lower is better) of the best design in each generation of the three runs.
RunWhat happenedCost
1Random start. The algorithm switched branch B off: one diode chain alone turned out to be already tube-like. H2 stayed 5 dB too low.9.7
2Noise target relaxed, symmetric starting designs. Failed: a larger coupling capacitor made the simulation four times slower, and good designs ran into the time-out.11.2
3Corrected, and started from runs 1 and 2. Both branches active, H2 and H3 within about 1 dB of the tube.2.9

Run 3 shows why the second branch is worth having: with two nearly symmetric branches the algorithm can set H2 and H3 independently.

From evolved values to a buildable design

The summing resistor went from 1k2 to 1k27 (an E96 value) to land the gain exactly on 10 dB; it scales the clean and the distorted path equally, so the character stays the same. Branch B's resistor became a fixed 4k42 plus a 500 Ω trimpot, chosen from a sensitivity analysis (that resistor mostly affects H3, by about −0.5 dB per 1%). Then came the practical parts: the supply filter for the diodes, the output network, decoupling, and two channels on one board. The whole thing was simulated again with the NE5532 model.

Results

All of it is simulation of the circuit as it sits on the board, including supply filter, output network and a 10 kΩ load.

Output (V rms)THDH2 op-ampH2 tubeH3 op-ampH3 tube
0.10.03%−70.3 dB−70.0 dB< −110 dB< −110 dB
0.50.15%−56.4 dB−56.0 dB−109 dB−108 dB
1.00.31%−50.3 dB−50.0 dB−97.2 dB−95.8 dB
2.00.61%−44.3 dB−43.9 dB−85.3 dB−83.6 dB
4.01.24%−38.1 dB−37.9 dB−73.6 dB−71.5 dB
6.01.89%−34.5 dB−34.3 dB−67.3 dB−64.4 dB

H2 follows the tube within 0.4 dB over the whole range. H3 sits 1 to 3 dB below the tube, with the same slope, and the trimpot can move it by ±3 dB if wanted.

Frequency response of the preamplifier Gain in dB against frequency from 5 hertz to 500 kilohertz with a 10 kilohm load. It is flat at about 10 dB, within 0.11 dB from 20 hertz to 20 kilohertz, and rolls off gently outside that. 8 9 10 11 10 100 1k 10k 100k frequency (Hz) gain (dB) 20 Hz to 20 kHz
Gain against frequency into a 10 kΩ load. The green band is 20 Hz to 20 kHz.
FigureValue
Gain at 1 kHz10.03 dB
Frequency response, 20 Hz to 20 kHz±0.11 dB
H4 and H5below −99 dB up to 6 V rms
Signal to noise97.5 dB relative to 1 V rms
Supply hum rejection (+15 V, through the diode bias)41.6 dB at 100 Hz, 61.5 dB at 1 kHz
Maximum outputabout 7 V rms into 10 kΩ
Input impedance100 kΩ

Check with the real NE5532 model

The algorithm used a fast, generic op-amp model. As a check, the design was also run with the manufacturer's NE5532 macromodel: gain, flatness and harmonics agree to within 0.1 dB. Only the noise is about 1.5 dB higher, because the model is noisier (6.4 nV/√Hz) than the datasheet (5 nV/√Hz), so in practice the noise should come out slightly better.

Tolerances

How accurate would a home-built unit be? A Monte Carlo analysis simulated virtual boards with random errors: resistors ±1% and diode-to-diode spread (saturation current lognormal, about ±11 mV in threshold). 21 of 24 virtual boards gave a usable simulation; three ran into the simulator's time limit.

QuantitySpread without adjusting (σ)With the trimpot set (σ)
Gain±0.13 dB±0.12 dB
H2 at 1 V rms±0.09 dB±0.13 dB
H3 at 4 V rms±0.43 dB±0.01 dB

The circuit is robust. Even without measuring anything, a unit with 1% resistors lands within half a dB of the design. The reason: at a fixed bias current the shape of a diode's curve does not depend on its saturation current, so diode spread only shifts the DC voltage. A 1% error in any one resistor moves H2 by at most 0.1 dB and H3 by at most 0.5 dB.

Two boards

The same circuit, with the same values, exists as two board designs in KiCad: one with through-hole parts to solder yourself, and one with surface-mount parts, meant to be made and assembled by a board manufacturer so there is no soldering at all.

3D render of the through-hole board
Through-hole, to solder yourself.
3D render of the surface-mount board with green screw terminals
Surface-mount, for assembly by a manufacturer. The trimpots are missing from the render only because KiCad has no 3D model for them.
Through-holeSMD
Meant forsoldering yourselfassembly by the manufacturer
Board size178 × 100 mm129 × 72 mm
Op-amps3 × NE5532P (DIP-8, in sockets)3 × NE5532DR (SOIC-8)
Diodes1N41481N4148WS
Resistorsmetal film 1%, 0.25 Wthick film 1%, 0805
Connectionspin headersscrew terminals

Does the sound change with the SMD parts? Not measurably in the simulation, and not by the physics either. The 1N4148WS is the same silicon diode in a smaller package, and the NE5532DR is the same chip. Thick-film resistors make extra noise under DC, but the only resistors with real DC across them feed the diode chain, whose impedance is so low (about 55 Ω against 9 kΩ) that their noise is attenuated more than a hundred times. The ceramic input capacitor can distort under large AC voltage, but almost no voltage stands across it and there is no DC on it.

For setting up, the trimpot has a no-instruments method (set it to 280 Ω before soldering, which with the fixed 4k42 gives the design value 4k70) and a measured one (a 1 kHz sine at 4 V rms output, adjusted until H3 reads about −73.5 dB with a sound card and free software). The preamplifier expects a line source and a regulated ±15 V supply.

Neither board has been ordered, made or measured. Both pass the KiCad electrical and design-rule checks without errors, and that is all that can be claimed.

Limits

Download

Everything needed to have the board made, or to repeat the whole design process, is free to download.

FileWhat is in itSizeSHA-256
Through-hole board
warm-preamp-through-hole.zip
Gerbers and drill files for the board manufacturer, parts list, schematic PDF, board layers, 3D renders and the KiCad 10 project (178 × 100 mm).1.5 MB2cf56750c1f33859a3a3a1ab0a36cf4d30aa37220f2c3c44f7b81fc4a32ad29c
SMD board, ready to assemble
warm-preamp-smd.zip
The same for the surface-mount board (129 × 72 mm), plus the manufacturer's parts list and the placement file for assembly.1.3 MB1ea9087148231eb53f312c0e149ee9e8d9947c3a8a195b25432b7585fc223c9b
The software and the documentation
warm-preamp-software.zip
The Python code that ran the genetic algorithm, simulated and checked the design and generated the KiCad boards, the evolved designs, the SPICE models and the full documentation with its data.0.4 MB4cae57b5c280dda4c8e08d46be28257659fa397727088375b876532a93c8f883

Tools used: ngspice, pymoo, KiCad and Freerouting.

All research