C++ Code Simulating Circuit Components?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

mystran wrote:it should probably get you started
Damn Right. It's all the equations I forgot from when I took circuits forever ago. I'll just go ahead and build s-function blocks in m. If anyone's interested in getting the library when I'm done (might take a while, as this is a hobby), let me know. To the best of my knowledge it should work in Octave just fine for those without Matlab.

Post

Google for "nodal analysis", "transient analysis", "linear algebra".

For example:
http://www.ecircuitcenter.com/spicetopi ... alysis.htm

http://www.ecircuitcenter.com/SpiceTopi ... alysis.htm

You'll need to write equations in terms of conductances and node voltages, for all components. For some components this will only yield a numerical approximation which will be subject to stability concerns, as described in the second link.

Matrices are required for the general case, for specific circuits you can find simpler solutions, for example http://www.simulanalog.org/statevariable.pdf
Last edited by stratum on Fri Jun 08, 2012 6:56 am, edited 1 time in total.
~stratum~

Post

stratum wrote:Google for "nodal analysis", "transient analysis", "linear algebra".

For example:
http://www.ecircuitcenter.com/spicetopi ... alysis.htm

http://www.ecircuitcenter.com/SpiceTopi ... alysis.htm

You'll need to write equations in terms of conductances and node voltages, for all components. For some components this will only yield a numerical approximation which will be subject to stability concerns, as described in the second link.

For a more specific example, see http://www.simulanalog.org/statevariable.pdf

I appreciate it. Should go ahead and download spice I suppose.

Post

I appreciate it. Should go ahead and download spice I suppose.
Depending on your purpose, yes. The info in the links above are for writing something like spice, not for using it.
~stratum~

Post

You will need at least a basic understanding of electronic components and the equations that define their behavior. I started out with a book called Mastering Electronics. It assumes you know the mathematics and so give you the basics in a quick and practical way.

For Transistors etc, I used Transistor Circuit Techniques in college and combined with a little study in Chaos Theory (i.e. the time evolution of non-linear, simultaneous differential equations) helped my simulation skills a lot.

Once you've got the basics down, I would start with implementing ideal component equations. Each can be implemented as a class, but remember there is no input/output but rather set the values for each external connection of the component, as well as the characteristics and time deltas. This gives you the basics for Nodal Analysis, but you don't need to use Voltage and Conductance, as long as you can derive them from whatever you use (Current, Resistance etc.). I usually have them all defined, and calculated for all when one is changed.

Once you've done this you can then implement per component modifiers for tolerance and noise. Simple (usually uniform) models can be used initially and more research done as, and when, you want to go for more accuracy. Numerical Analysis (Runge Kutta) is you're friend with this.

As you combine components, to make circuits, it will quickly become apparent that you're eating CPU for no reason. You can then start combining classes into basic circuit blocks (LRC etc.) so that you can have more efficient code.

Hope it helps.
Last edited by khanyz on Fri Jun 08, 2012 7:23 am, edited 2 times in total.
I miss MindPrint. My TRIO needs a big brother.

Post

Oh btw, if you're interested in working with S-parameters then I believe you might also want to look at Wave Digital Filters. Those are essentially just BLT transformed linear circuits in terms of waves. For linear circuits they are certainly the most straight-forward method.

The problem with using WDFs (and wave scattering formulations in general) for circuit simulation of audio circuits is that normally one would want to describe non-linear elements in terms of Kirchhoff voltages and/or currents, and with WDFs this only really works at the root-node. This is not an issue if your circuit only has a single non-linear element (since you can choose the root-node).

Post

Forgot to mention the OpAmp book I use. I'll try to remember it.
I miss MindPrint. My TRIO needs a big brother.

Post

djomni wrote:
mystran wrote:I think "code for individual components" is a fundamentally flawed concept
How is this a flawed concept?
because you "think in simulink" which is not the best paradigm here. Simulink is about signal flow through independent blocks. That approach is usable for circuit simulation if you have models of macro level blocks (for instance, for guitar amp you have models for preamp, power amp and load/speaker).

For component level simulation of electronic circuit best route is to go down the classical system analysis road: find independent state variables (usually node voltages) and system of equations that describe their dependance (which will hopefully be system of PDEs). That's more or less SPICE approach.

Post

mystran wrote:
Meffy wrote:My understanding is that CPU power is the limiting factor.
CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.
Damn,you're on fire nowadays!

Post

jupiter8 wrote:
mystran wrote:
Meffy wrote:My understanding is that CPU power is the limiting factor.
CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.
Damn,you're on fire nowadays!
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

Post

mystran wrote:
jupiter8 wrote:
mystran wrote:
Meffy wrote:My understanding is that CPU power is the limiting factor.
CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.
Damn,you're on fire nowadays!
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
Don't focus on the negative. I have faith in you and i want to encourage you and i strive be a little more like you every day. Knowledgeable, productive and sharing.

Post

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
the force will be with you!
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

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 :)

Regards,
{Z}

Post

mystran wrote:
Meffy wrote:My understanding is that CPU power is the limiting factor.
CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.
Needless to say, I'd be pleased to be proven wrong (more accurately, have it shown that my understanding has been passed by technology) on this.

Post

My understanding is that CPU power is the limiting factor.
Limiting factor seems to be numerical stability. So instead of directly simulating a circuit I guess the synth guys would prefer to redesign the thing from scratch and call it an analog modelling synth. Guitar amp and other effect modellers would probably do the same unless they are looking for some adventure for adventure's own sake.
~stratum~

Post Reply

Return to “DSP and Plugin Development”