When dealing with music DSP stuff there's a great chance that one day you'll ponder about a mysterious issue: *Do audio samples represent the voltages in electronic circuits or do they represent the currents?* And somehow the most fundamental difference between sample based signals in DSP and that of analogue stuff seems to be just that: One dimension versus two.

It's like one strategy game that has health, strength and pills as commodities while another game has wood, wool, water and rocks, yet the goal of the game is the same, and somehow even the game play seems to follow the same rules and dynamics, but you can't quite put your finger onto it.

### analogue modeling

My understanding of analogue modeling in the most simple terms is this: In analogue modeling we use formulas that deal with voltages and currents. These formulas are furthermore based on the understanding of the electronic components used in a circuit, and how they're wired up.

This opposes models based on abstract concepts (e.g. poles and zeros, spectral processing) or what I call "flowchart models" which emerge from the assumption that samples somehow make their way through successive components which have distinct inputs and outputs.

I basically grew up with the understanding of filter algorithms representing a transistor as a little box with a sample multiplier inside while a capacitor was a little box which accumulates samples. A sample would reach the input of one, before it comes out modified on the other side. Somehow we would convince ourselves that because we had baked a notion of what these components might do, we'd get a result that's very similar to that of the electronic circuit. And fair enough, one can actually build lowpass filters and stuff that sound quite alright.

However, these models are solely based on the concepts of algebraic computation (multipliers, accumulators, you name it) and they miss a key feature of electronics: Both ends of a resistor are inputs as well as outputs. In other words, electronics don't work that way. Not everything has dedicated inputs and outputs.

Of course a whole lot of this stuff is interchangeable - and in practice you'd rather use what works than spend your time being dogmatic about it. Some of the abstract models are even mathematically equivalent to actual ones, at least within the intention and circumstances of their use case. But really, one doesn't need a degree in engineering to see that a concrete model is more likely to be "closer to the real deal" than an abstract one. (A bit of tongue-in-cheek: A degree in electric engineering may even be an obstacle to this very insight ;-)

### of voltages and currents

When dealing with voltages and currents, the first big a-ha moment is when you realize that one relates to the other by a very simple and famous formula, which is Ohm's law: I = V/R, or current is voltage divided by resistance. If you have a resistor with 10 Ohms and on one side you have 5 Volts while on the other you have 1 Volt, you can be assured that a current of (5-1)/10 = 0.4 Ampere is in motion from the 1 Volt end towards the 5 Volt one.

Note that we often rather use some g = 1/R as a factor to turn the division into a multiplication. That's then what's called admittance or conductance, such that a resistor with 10 Ohms has a conductance of 0.1 (bearing a unit name).

The next big a-ha moment is a tad more complicated. There are two more fundamental laws, Kirchhoff's Current Law aka KCL and Kirchhoff's Voltage Law aka KVL. Latter says that all voltages within a loop of current flow sum up to zero. Former says all currents that flow in or out of any node in a circuit add up to zero. I.e. nothing gets lost, nothing gets added (if we leave a little heat dissipation aside). I usually get along with KCL and it's also what you'll find in Andy Simper's papers, but I've seen papers where KVL is preferred.

Three more ingredients need to be mentioned, two of which being: Something always needs to provide for voltages and/or currents (a battery, an oscillator) and the realization that when something is connected to ground, it's connected to 0 Volts.

The gist of these ingredients is, they help us make equations. Most of Analogue Modleing is making equations and most of that equation making is really just finding conductances (very simple with resistors) or voltage/current sources that are connected in nodes. As a matter of another a-ha effect, every electronic component we model is going to be broken down to a set of conductances and current sources. All of them.

As a simple example, a capacitor is modeled as both a resistor and a current source. The current that's "resisted" over time gets stored in the capacitor which - by a separate formula - changes the conductance. (Note that "over time" is the verbal cue for the second to next chapter...)

With that in mind we can combine all currents that flow in and out of our nodes in a circuit to zero. Which then leads to equations that give us the voltage in one node from the voltage in another. It's like "what voltage does this node need to have so that the currents in and out become zero?". It's pretty basic, but it's the perspective that matters. It'll become deep soon enough though ;-)

### the example

Let's look at the very inevitable example of an RC lowpass filter:

It's almost the most simple circuit there is. We know Vin as being determined by something like an oscillator. It's our known value. Our unknown value is Vout. We know however that the currents that flow into the node at Vout match the currents that flow out of it. So, let's replace the capacitor with its aforementioned "companion model"and draw some arrows for the currents:

Here we go. At the node marked Vout we have the current through the resistor (iR) going in and the current through the capacitor's virtual resistor (iRC) going out. Lastly, we have the capacitor virtual current source pump some current "iceq" back into our node. Latter is of special interest because it is the mechanism provides a history component over time. We see to that in our time chapter.

Yep, only Ohm's Law and Kirchhoff's Current Law are required to arrive at these equations:

$$iR = gR * (Vin-Vout)$$

$$iRC = gC * (Vout - 0)$$

$$0 = iR - iRC + iceq$$

$$= gR * (Vin-Vout) - gC * Vout + iceq$$

Hence

$$Vout = \frac{Vin*gR+iceq}{gR+gC}$$

Looks familiar? We can set gC = 1 and get the equation I used in my article about numerical integration...

So, the usual way to go about this is roughly like this:

- identify nodes
- mark currents ("Is") that go in and out of those nodes with arrows (KCL)
- add each current source directly
- for each resistive component, apply Ohm's law to relate "Vs" to "Is"
- rearrange to solve for unknown Vs

This - in short - is commonly referred to as Nodal Analysis. With these tools we can determine the voltages and currents of an electronic circuit at a point of time.

### continuous time vs. discrete steps

In terms of music DSP however our interest is pretty much all about how the currents and voltages evolve over time. Thus, yep, our last ingredient to get started is *time!*

*I'll keep this chapter short because I've pretty much written most of it in my previous blog post. And also, it's quite hot outside and I want to jump in the pool.*

Most books and papers about electronic circuits and their components provide models and equations that deal with continuous time. I guess everyone is a very aware that the utterly defining difference between analogue and digital processing is, analogue is continuous and digital is discrete, i.e. sample based.

So, the key to transforming equations for analogue circuits into sample based processing lies within numerical integration. The time that passes between each "snapshot" of circuit analysis is "bridged" with any of the standard integration methods. This is what we need the current source equivalents of the capacitors for, which we think of as energy storage components.

If you haven't read it yet, please go to my previous blog entry called "Numerical Integration". It has basically been a spoiler to the RC filter example in this article, while this article focusses on the concept and methodology to harvest the equations.

Note that - speaking of time that passes - with all of this, "zero delay feedback" comes for free. It's an inherent property of an analogue modeled filter/compressor/whatsoever. Because analogue circuits have no unit delays, and neither should analogue models.

### outlook

This has been a basic glimpse of my take on analogue modeling. I hope the above has caused a little revelation here or there, and I'm sure that - equipped with this - the papers of Vadim Zavalishin and Andy Simper will be more approachable. Vadim's book contains a lot more theory and is designed to be a more open approach to filter design beyond analogue modeling, while Andy's papers are insightful hands on code with a (currently) strong emphasize on linear, flexible filter models.

I think for my next article I'll go one step further, which is a non-linear model of a one pole filter, with which I hope to slowly approach what motivates me: A practical stance and considerations on implementation details of non-linear analogue models. We'll see :-)

runs u-he