Noob Questions regarding Circuit Simulation

DSP, Plug-in and Host development discussion.
pdoogs
KVRer
4 posts since 8 Aug, 2017 from US

Post Tue Mar 13, 2018 6:48 am

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
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 (https://www.swarthmore.edu/NatSci/echeeve1/Ref/mna/MNA6.html) or a system of equations using Sauce (http://www.electronicsauce.com/p/welcome.html).

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?

mystran
KVRAF
5032 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Noob Questions regarding Circuit Simulation

Post Tue Mar 13, 2018 3:14 pm

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.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

pdoogs
KVRer
4 posts since 8 Aug, 2017 from US

Re: Noob Questions regarding Circuit Simulation

Post Wed Mar 14, 2018 1:04 pm

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.

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Wed Mar 14, 2018 1:12 pm

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~

mystran
KVRAF
5032 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Noob Questions regarding Circuit Simulation

Post Wed Mar 14, 2018 4:14 pm

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
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Wed Mar 14, 2018 7:59 pm

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

Chaotikmind
KVRist
65 posts since 26 Sep, 2005 from France

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 2:17 am

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)

Z1202
KVRian
978 posts since 12 Apr, 2002

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 2:28 am

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

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 3:44 am

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~

mystran
KVRAF
5032 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 8:59 am

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.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 9:59 am

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~

Chaotikmind
KVRist
65 posts since 26 Sep, 2005 from France

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 10:16 am

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 ...

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 10:23 am

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~

Chaotikmind
KVRist
65 posts since 26 Sep, 2005 from France

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 10:30 am

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.

stratum
KVRAF
2114 posts since 29 May, 2012

Re: Noob Questions regarding Circuit Simulation

Post Thu Mar 15, 2018 10:35 am

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~

Return to “DSP and Plug-in Development”