Freedom Odds
ChucK Tube Amp
Introduction
I figured out how to make a tube amp model in ChucK, and I'm writing it up here for others to enjoy and possibly even make their own tube amp models.
It wasn't easy - it took me about two days of off and on effort and I had to call upon the expertise of the electro-music.com forum community.
After all of that I think I have a good first attempt at a tube model in ChucK.
Let's work through my example, which is just about the easiest tube model you can make.
It's not a very accurate model, but remember it's just a first attempt.
Gathering Information
To get started, you will need to scour the web for information, which is kind of fun and interesting to do if you don't rush it too much.
I'll add some links to get you started later, but for now just know that what you are looking for is hobbyist tube amp building sites.
At first I looked for tube amp modeling sites, but all I found was commercial programs that model tube amps!
I guess that's because most of the work in the field is proprietary and held as closely guarded secrets by the software industry.
But we don't like to keep secrets, do we?
We share information freely because it's our hobby and it's fun!
Look for sites that have schematics, Spice tube models, and/or circuit analysis of tubes and soak in as much as you can on the subject.
Choose a Circuit
I chose the common cathode amplifier for it's simplicity and ease of analysis, but you can choose any amp you are capable of analyzing and programming.
See the illustration to the above right for an illustration of the model.
It has an input network that basically forms a high-pass and a low-pass filter, plus does DC blocking of the input signal.
In ChucK we have HPF and LPF models so I removed the resistors and capacitor and replaced them with the filter models.
The rest of the model is simplified by removing the capacitors, which is a major simplification that tube amp purists would scoff at, but hey - it needs to be doable by me now.
I can always add more details later.
Choose a Tube Model
Next select a tube amp model.
I chose the Leach model and went a step further to simplify it a little bit so that the analysis would be easier by setting the input current to zero.
That's an ideal tube with no input current, which is impossible physically but we're not looking for super-accuracy here, just a tube-like sound.
The Leach model is: Ia = K * (mu * Vgk + Vak)^(3/2) for cases where the interior term mu * Vgk +Vak is greater than zero, and zero for cases where that interior term is less than or equal to zero.
You'll also need to find some model parameters for your particular tube.
I didn't look for a particular tube because I could only find loosely scattered information about common cathode tube specs using the Leach model, sigh, so I just approximated.
You can use values of K = 10^(-6) and mu = 100.
There, I saved you a few hours of browsing with those two numbers.
Perform Circuit Analysis
You'll need to know a bit about electronic circuit analysis for this step.
Obtain circuit analysis equations from the circuit diagram.
The equations I found were as follows.
KCL: (Vo-Vaa)/Ra + Vo/Rl + Ia = 0.
Ohm: Vk = Rk*Ia
KVL: -Vg + Vgk + Vk = 0
KVL: -Vo + Vak + Rk*Ia = 0
Once you have these characteristic equations for your tube amp circuit, you are well on your way to having a workable tube model.
But you can't solve them because the definition of the tube's output current, Ia, has Vak inside the 3/2 exponent, and you get transcendental equations.
We need to use a numerical analysis technique to solve transendental equations, so that's what we'll do.
Solving Equations
We'll do the solving in a ChucK program.
Here is the source code for the equation solver.
Reading the code, you'll notice that it sweeps out a table of solution values.
This is the transfer function of the tube.
We have removed Ck and Co, and Ci was modeled by the filter stages so we have no time-dependence to our model.
A purist would argue that is a crude model and that's correct - we're going for a crude model here and we can make the model better later.
The important thing about a transfer function model is that once we have the table we no longer need to do iterative calculations which saves a lot of CPU time.
Anyway, get the output table and you have your tube model for use in any software, just interpolate between the points.
We will create a ChucK model next.
The ChucK Model
Now that we have a table-based transfer function model of the tube amp, let's put that model to use.
Here is the source code for the tube amp demonstration program.
You'll see that I used half-wave rectifiers and an inverter to split up the positive and negative sides of the waveform.
That's because the Gen7 Ugen in ChucK only works on values from 0 to 1, so we need to operate on the negative side flipped upside down.
Again, that's not exactly kosher from a modeling standpoint but we are going for the general effect of that "warm" sound, not precise modeling.
We've oversimplified the model so much that negative values don't work here so we just do to the negative side what we do to the positive side to get our sound.
When running the demonstration program, press "a" to get the undistorted sine waveform, and "b" to get the distorted tube-amp waveform.
Note that the model needs some way to deal with signals that are greater than one, that is also not modeled yet!
Links
Here is an excellent paper on deriving a better tube amp model than the one I present here.
Here is a thorough discussion on spice models, plus other great pages - click around a bit.
Here is a detailed description of tube amp circuit analysis.
Here is some spice modeling information.
Concluding Remarks
This is a very crude model of a tube amp, and intentionally so.
I wanted to start with something, anything that worked really, and this is it.
Although there are many critiques to the model, the overall technique of searching the web for circuits and solving them by hand to obtain equations for the model is sound.
I plan to make other, better tube amp models which are more accurate and model the negative side of the waveform, and I'll be sure to post an update when they are ready. .
I hope you enjoyed this article, and good luck with your tube amp modeling!