Noob Questions regarding Circuit Simulation

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Say I've modeled a circuit in LTSPICE, SPICE, etc, and now have a netlist.

I can then generate the system of equations in matrix form using something like SCAM or a system of equations using Sauce.

Assuming solving the matrix equation Ax = b isn't horrifically expensive, would I then solve this system for every sample coming in to my VST? That is, substituting Vin with an input float ranging from -1 to 1?

Is this how people model circuits for their VST's, or are there other methods / optimizations to be had?

Post

pdoogs wrote: Assuming solving the matrix equation Ax = b isn't horrifically expensive, would I then solve this system for every sample coming in to my VST? That is, substituting Vin with an input float ranging from -1 to 1?
That's the basic idea. The expensive part usually is when you want to iterate Newton until convergence on per-sample basis. You probably want to build your MNA matrix yourself so you can optimize the component models and stamps and you might even want to build the matrix for an "equivalent circuit" that has already been simplified on the circuit level to discard anything that isn't important for the actual model.

In terms of lower level optimizations, you can order the matrix in such a way that you can prefactor (and even discard if you're not interested in the actual values of the corresponding nodes) most of the static parts of the matrix in advance, which can speed things up a lot. Similarly if you optimize the actual component models to minimize the number of nodes they need to solve you can keep the run-time part of the matrix smaller.

Ultimately though, I'd guess anyone doing analog modeling has their own bag of tricks and shortcuts and what not. Start with some simple circuits and experiment.

Post

Thanks a lot. I've been messing with a 6x6 MNA matrix and it's using 60% of my CPU to solve for every sample, so you are very right that optimizations must be made. Thanks for letting me know I'm on the right track.

Post

pdoogs wrote:Thanks a lot. I've been messing with a 6x6 MNA matrix and it's using 60% of my CPU to solve for every sample, so you are very right that optimizations must be made. Thanks for letting me know I'm on the right track.
I guess mystran won't be posting this as it would sound like a self AD. http://www.kvraudio.com/forum/viewtopic ... 3&t=498122

So called the 'parent project' of the code mentioned in the thread was referred in an article I have recently seen (The paper "RT-WDF—A MODULAR WAVE DIGITAL FILTER LIBRARY WITH SUPPORT FOR ARBITRARY TOPOLOGIES AND MULTIPLE NONLINEARITIES Maximilian Rest , W. Ross Dunkel , Kurt James Werner , Julius O. Smith" refers to it)
~stratum~

Post

stratum wrote:
pdoogs wrote:Thanks a lot. I've been messing with a 6x6 MNA matrix and it's using 60% of my CPU to solve for every sample, so you are very right that optimizations must be made. Thanks for letting me know I'm on the right track.
I guess mystran won't be posting this as it would sound like a self AD. http://www.kvraudio.com/forum/viewtopic ... 3&t=498122

So called the 'parent project' of the code mentioned in the thread was referred in an article I have recently seen (The paper "RT-WDF—A MODULAR WAVE DIGITAL FILTER LIBRARY WITH SUPPORT FOR ARBITRARY TOPOLOGIES AND MULTIPLE NONLINEARITIES Maximilian Rest , W. Ross Dunkel , Kurt James Werner , Julius O. Smith" refers to it)
OMG! I've been referenced in a scientific paper?!? :D

edit: actually the main reason I didn't link to Halite was simply because I was too lazy to lookup the link to the thread at the time, but also because Halite really doesn't do any of the optimisations I was talking about.. it doesn't reorder the matrix, it doesn't do a pre-factorisation pass (rather it builds the matrix from scratch every iteration) and it most definitely doesn't compile the circuit into native code, so it's really very slow in comparison to a more realistic real-time solver

Post

mystran wrote: OMG! I've been referenced in a scientific paper?!? :D
And without even writing a paper about the subject :lol:
~stratum~

Post

mystran wrote: but also because Halite really doesn't do any of the optimisations I was talking about.. it doesn't reorder the matrix, it doesn't do a pre-factorisation pass (rather it builds the matrix from scratch every iteration) and it most definitely doesn't compile the circuit into native code, so it's really very slow in comparison to a more realistic real-time solver
From the tiny part i understand of the code (i'm quite bad at maths), it seems it would be relatively straightforward to use llvm and compile on the fly, isn't it ?
(each component could have it's processing part provided as llvm IR for example)

I'll give it a try IF i have enough time on my hands (which i'm very short off at the moment)

Post

stratum wrote:
mystran wrote: OMG! I've been referenced in a scientific paper?!? :D
And without even writing a paper about the subject :lol:
:clap: :-D

Post

This subject never stops to amaze me.
While there is some very serious work directed at circuit simulation, on the other hand there is also work that extends simple static waveshapers to dynamic ones, while trying to measure system parameters for a generalized model.

https://www.ntnu.edu/documents/10012011 ... ion_21.pdf
~stratum~

Post

Chaotikmind wrote:
mystran wrote: but also because Halite really doesn't do any of the optimisations I was talking about.. it doesn't reorder the matrix, it doesn't do a pre-factorisation pass (rather it builds the matrix from scratch every iteration) and it most definitely doesn't compile the circuit into native code, so it's really very slow in comparison to a more realistic real-time solver
From the tiny part i understand of the code (i'm quite bad at maths), it seems it would be relatively straightforward to use llvm and compile on the fly, isn't it ?
I don't know. I'm not intelligent enough to figure out how to use LLVM for anything.

Post

One could just install llvm alongside with the plugin. The license seems to allow it http://releases.llvm.org/2.8/LICENSE.TXT
I don't see why on-the-fly code generation should be necessary.
~stratum~

Post

mystran wrote:
Chaotikmind wrote:
mystran wrote: but also because Halite really doesn't do any of the optimisations I was talking about.. it doesn't reorder the matrix, it doesn't do a pre-factorisation pass (rather it builds the matrix from scratch every iteration) and it most definitely doesn't compile the circuit into native code, so it's really very slow in comparison to a more realistic real-time solver
From the tiny part i understand of the code (i'm quite bad at maths), it seems it would be relatively straightforward to use llvm and compile on the fly, isn't it ?
I don't know. I'm not intelligent enough to figure out how to use LLVM for anything.
Damn, you wrote that program, and you say that !!!
For me it seems like the other way around , i could never write that kind of soft without some sort of serious help, but LLVM seems so simple to use :/
i'll try to kick myself in the ass and see if i understand enough of the code to make it happen ...

Post

Chaotikmind wrote: Damn, you wrote that program, and you say that !!!
For me it seems like the other way around , i could never write that kind of soft without some sort of serious help, but LLVM seems so simple to use :/
i'll try to kick myself in the ass and see if i understand enough of the code to make it happen ...
I guess you have misunderstood the reply. He is trying to say that he does not want to waste time trying to understand the LLVM code generation API.
~stratum~

Post

Ok then i misunderstood, but still LLVM is pretty simple to use, it's a no brainer for most simple use.
Really a great/unique progress in the field of compilers.
I was really surprised the first time i tried to implement a simple language with it.

Post

Chaotikmind wrote:Ok then i misunderstood, but still LLVM is pretty simple to use, it's a no brainer for most simple use.
Really a great/unique progress in the field of compilers.
I was really surprised the first time i tried to implement a simple language with it.
I haven't really looked at it, but I imagine a compiler backend interface can get pretty complex.
Code generators with simple APIs exist for the assembly language, but using anything such would require performing code optimization before calling that API.
Anyway, this isn't really an issue, as according to the license apparently one can just ship the whole package together with your product.
~stratum~

Post Reply

Return to “DSP and Plugin Development”