C++ Code Simulating Circuit Components?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

stratum wrote:
My understanding is that CPU power is the limiting factor.
Limiting factor seems to be numerical stability.
You mean stuff like convergence problems with iterative solutions? I think Meffy was referring to some other issues: coders get fainthearted when they see all those exp's in ladder VCF equations. And then, if you use Gummel-Poon model instead of basic BJT equations you go up by order of magnitude or two in evil transcendental functions. And then again, FET stuff, J or MOS, is even more evil: transistor geometry becomes very important factor and you can throw out the window any textbook equations if you want accurate models. So, for description of single transistor you quickly pile up big and ugly equations with bucketloads of transcendental functions*. And that is taxing on CPU cycles.
Stability of numerical solvers is another set of problems on top of that.

* - off course, you don't need all that stuff all the time for audio modeling. But then again, you might need some stuff that is not well defined even with very complex models. For instance, by very nature of ladder and OTA filters you some time (when you turn cutoff down) operate them in low current region, below lets say 50uA. All bunch of weird stuff start to happen at low collector currents: beta drops through the floor, leakage currents become important, log conformity starts to vanish, stuff like that. And I doubt that any digital model cares for Early effect let alone esoteric stuff.

Post

I think Meffy was referring to some other issues
Probably. But actual analog circuits are rather complex for circuit-level simulations to be done in VST plugins. There are a lot of interactions between components (one cannot separate one part of the circuit from another and call the result "still accurate"), and even in the simplest cases discrete nature of time in transient analysis causes accuracy and stability problems (usual problems of numerical integration). And making the simulation run realtime is yet another challenge which can involve interpolation and look up tables (who wants to solve a large set of equations 250K times per second?), which is yet another source of unstability. I recently see things like "Virtual analog filters" discussed in this forum. When you look at it it's obvious that these are not circuit simulations but rather attempts to address the discrete nature of time and its unwanted side effects.
~stratum~

Post

Z1202 wrote:
mystran wrote:Don't get too excited. I'm just trying to make the whole topology-preserving thing more painless, and grab a few low-hanging fruits in the process. :P
I could only guess what exactly you're up to :), but maybe this could give you some ideas
http://images-l3.native-instruments.com ... logyRC.pdf
(this describes kind-of guideline conventions to do TPT stuff in Reaktor Core).
Although I wonder, if your ideas are similar anyway :)
Thanks for the link, I'll need to digest it.

But, I won't go into too many details at this point. I'm close enough to having something useable that I don't feel like announcing vaporware. I think I've already said too much anyway. ;)

Post

stratum wrote:I recently see things like "Virtual analog filters" discussed in this forum. When you look at it it's obvious that these are not circuit simulations but rather attempts to address the discrete nature of time and its unwanted side effects.
I can't resist on commenting this though: every circuit simulator needs to do this. It's one piece of the puzzle. Modelling components to various levels of accuracy is another thing, but whether you use fixed or varying time-steps in your simulation, you're going to have to do it in discrete-time and deal with the unwanted side-effects.

Post

mystran wrote:
stratum wrote:I recently see things like "Virtual analog filters" discussed in this forum. When you look at it it's obvious that these are not circuit simulations but rather attempts to address the discrete nature of time and its unwanted side effects.
I can't resist on commenting this though: every circuit simulator needs to do this. It's one piece of the puzzle. Modelling components to various levels of accuracy is another thing, but whether you use fixed or varying time-steps in your simulation, you're going to have to do it in discrete-time and deal with the unwanted side-effects.
I would put it another way. VA filters (and other VA components) are circuit simulations, which have been simplified to an extent. The simplification involves purely mathematical simplifications and dropping the "unimportant" aspects. Of course the judgement of the "importance" is subjective and this is why we are getting lots of different quality models. But I believe that modeling each and every component is a waste of CPU. It more a matter of proper judgement in selecting the "important" aspects for the modelling. E.g. Stilson&Smith's Moog VCF model takes care only of linear aspects, whereas Antti's model uses the Ebers-Moll transistor model for the ladder transistors (with some further assumptions). Of course you can always model "everything", but I don't personally think it's a reasonable approach, considering today's CPU power.

Regards,
{Z}

Post


I would put it another way. VA filters (and other VA components) are circuit simulations, which have been simplified to an extent. The simplification involves purely mathematical simplifications and dropping the "unimportant" aspects. Of course the judgement of the "importance" is subjective and this is why we are getting lots of different quality models.
A simulation with a simplification is more properly be called "a model", and "unimportant aspects" could be unimportant or important depending on the purpose, but.. the topic is new to me and I won't make further comments about a topic I dont know.


EDIT:
Of course you can always model "everything", but I don't personally think it's a reasonable approach, considering today's CPU power.
That's what circuit simulators like spice do. So what someone mentions a circuit simulator that's the first thing that comes to mind. I guess you are right about the fact that there can be simulators with different levels of realism and all can be called "circuit simulators".
Last edited by stratum on Fri Jun 08, 2012 2:19 pm, edited 1 time in total.
~stratum~

Post

I would further add, that in the "simulate every component" approach, a simulation of a single block, like a filter, is probably not even truely possible, since there may be leakages from the other blocks of the synth. So, you have to simulate the entire synth circuit, with oscillators, filters, envelopes etc., as a single whole. If you don't do it, you are already performing simplifications, which has only a quantitative but not anymore the qualitative difference to the existing digital models.

Furthermore, the simulation will be using the component models, which are approximations of how the components behave in reality. No matter what you do, it's still a model. It's just the question of how deep you go. Since you have to pay with CPU power for the depth of simulation, this depth better be really justified by the improvements in sound. But then, if one can do a proper judgement of the "importance" of the simplifications, one can do with a probably much less CPU-expensive model with a practically identical sound.

Post

When I consider things like this I often do not think about synths. Circuits for which simplifications like simulating one part of circuit separately from another could make real differences are often considered to be valve guitar amps. There are serious papers(*) that argue against such simplifications, but all about guitar amps, yet I'm not aware of any actual amp modeller that simulates an entire circuit, so I guess such modellers are only on papers. If there is any, I'm not sure that that info would pass the marketing departments's buzzword creation process without getting distorted, though.

(*) for example here is one: ieeexplore.ieee.org/Xplore/login.jsp?url=http%3A%2F%2Fieeexplore.ieee.org%2Fiel5%2F10376%2F4358086%2F05272282.pdf%3Farnumber%3D5272282&authDecision=-203

That's the abstract:
Enhanced Wave Digital Triode Model for Real-Time Tube Amplifier Emulation

Pakarinen, J.
Dept. of Signal Process. & Acoust., Helsinki Univ. of Technol., Helsinki, Finland

Electric circuits containing vacuum tubes form an integral part of various audio equipment, such as guitar amplifiers, certain equalizers, microphone preamplifiers, and dynamic range compressors. Although most audio signal processing operations are straightforward to implement with modern computers, real-time digital simulation of vacuum tubes poses a significant challenge due to the dynamic nonlinearities of the tube circuits. Most of the current vacuum-tube emulators model the unidirectional signal path of the circuit using linear filters and nonlinear waveshapers, possibly with signal-dependent parameters. This paper introduces a physical model of a tube stage circuit using wave digital filters. In contrast to previous unidirectional signal models, the wave digital model implements bidirectional signal propagation. This allows realistic simulation of interesting dynamical nonlinearities, such as the bias variation under reactive load. The new model is an extension of the wave digital tube presented in ??Wave digital simulation of a vacuum-tube amplifier?? (M. Karjalainen and J. Pakarinen Proc. Int. Conf. Acoustics, Speech, Signal Processing, 2006, vol. V, pp. 153-156). In particular, the enhanced model for the tube grid-to-cathode connection enables the simulation of interstage coupling and blocking distortion.
~stratum~

Post

stratum wrote:yet I'm not aware of any actual amp modeller that simulates an entire circuit
But I guess, that's the entire point. Without really looking at the paper you mention, I'd guess that someone found out that there is a need to model the behavior of a triode to a deeper extent, therefore coming up with a more elaborate one. So, it's not about "let's model everything", it's about "we seem to have missed an important aspect, let's add it to our model". I'd guess this is also where SPICE would have failed, due to using a simpler triode model, despite the "simulate every component" approach.

Similarly, the VA filter models do use the models of single components, but don't do it for all of them. Only for the ones which are considered "sufficiently important". This is where the quality of the model is determined :) E.g. Antti's model of the Moog VCF (this is essentially the "advanced nonlinear model" described in "The Art of VA Filter Design") is explicitly modelling the transistors and the capacitors in the ladder, but not the other components.
Last edited by Z1202 on Fri Jun 08, 2012 2:48 pm, edited 1 time in total.

Post

But I guess, that's the entire point. Without really looking at the paper you mention, I'd guess that someone found out that there is a need to model the behavior of a triode to a deeper extent, therefore coming up with a more elaborate one. So, it's not about "let's model everything", it's about "we seem to have missed an important aspect, let's add it to our model".
Yes that's exactly it. It's about the fact that the next gain stage on the signal path could "load" the previous gain stage's output (due to grid current), and the fact that there is a coupling capacitor in between which needs to be simulated because grid current passes through it, so a simple single pole highpass filter is inaccurate. So that's not as complete as a spice simulator, obviously. It's a judgement based simplification extended to include another aspect of the circuit, as you say.
~stratum~

Post

stratum wrote:So that's not as complete as a spice simulator, obviously.
Please read my latest edit to my post. My guess regarding the spice simulator in this context would be exactly the opposite. I might be missing the correct point in this specific case, but generally SPICE can fail in exactly the same way, due to the fact that the existing component models fail to emulate the aspects which are necessary in this particular case.

So in the end, it's not about simulating everything. You never can simulate "everything". Even SPICE doesn't. Therefore you have to find out, what is really important to simulate.

Post

Code: Select all

So in the end, it's not about simulating everything. You never can simulate "everything". Even SPICE doesn't. Therefore you have to find out, what is really important to simulate.
Yes it can fail because:

1) Inaccurate component model: In this case there are quite a few tube models around that doesn't take the grid current into account

2) Numerical problems: Numerical analysis is inaccurate and sometimes unstable (i.e. errors accumulate)

3) Aliasing: Transient analysis is done with a discrete (sometimes varying) time, causing aliasing with nonlinear components.

In the end I guess you are right, we can call a model that includes all relevant aspects "a simulator".
~stratum~

Post

Well, my position in this matter is similar to Z1202 in the sense that the question of circuit simulation itself is somewhat orthogonal to the question of how accurate the components models (which you will need to use anyway) are.

As far as I'm concerned, being able to simulate circuits is pretty much a prerequisite for building "accurate" (for whatever definition of "accurate") component models, because most of the time you want to describe the model in terms of an equivalent circuit.

Obviously if you want to use component models as accurate as possible (or even take PCB layout issues into account) then you're probably not going do it real-time in the near-future. But if you argue that it's necessary to always use the most accurate possible models (to call it "circuit simulation" or whatever) then you should never use resistors in Spice without specifying what type of resistor and packaging you want, even if at audio rates it's really just another resistor (maybe with some noise, but you might not actually want that anyway).

Post

mystran wrote: Obviously if you want to use component models as accurate as possible (or even take PCB layout issues into account) then you're probably not going do it real-time in the near-future.
Thing is, SPICE is brute force approach. It takes into account everything, even if some stuff is not relevant for particular situation. If you know what you are doing you can simplify model considerably without loosing accuracy.
You don't care about PCB layout per se for audiorate stuff(treating lines as waveguides, solving full blown 3D model based on Maxwell eq's and stuff like that). Important (no, really important) issue is crosstalk via PSU and ground, and that can be modeled (modeling effect of finite impedance grounding is easy, PSU is a bit trickier but even linear model should do it).
/* "stiffness" of PSU is key explanation I can think of for mysterious (if it is not imaginary) situation that old and new synth with apparently same circuit sound different */


mystran wrote: (maybe with some noise, but you might not actually want that anyway).
IMveryHO, for synth stuff (and in some situations) you do want that.

Post

If you wanted a thermal noise component, that would be rather easy, but to give it a temperature in time would require more modeling as well.

As others have said, numerical precision is the biggest problem. You could use a BCD datatype, but the overhead would be huge. It's all possible given enough time, but then you have to wonder if you wanna sit around and wait for your guitar to "process".

Post Reply

Return to “DSP and Plugin Development”