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.mystran wrote:it should probably get you started
C++ Code Simulating Circuit Components?
-
- KVRist
- Topic Starter
- 48 posts since 5 Jul, 2011
-
- KVRAF
- 2256 posts since 29 May, 2012
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
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~
-
- KVRist
- Topic Starter
- 48 posts since 5 Jul, 2011
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.
-
- KVRAF
- 2256 posts since 29 May, 2012
Depending on your purpose, yes. The info in the links above are for writing something like spice, not for using it.I appreciate it. Should go ahead and download spice I suppose.
~stratum~
- KVRAF
- 1871 posts since 16 Jul, 2004 from Deepest Yorkshire
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.
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.
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
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).
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).
-
- KVRist
- 439 posts since 4 Oct, 2002
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).djomni wrote:How is this a flawed concept?mystran wrote:I think "code for individual components" is a fundamentally flawed concept
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.
- KVRAF
- 9590 posts since 17 Sep, 2002 from Gothenburg Sweden
Damn,you're on fire nowadays!mystran wrote:CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.Meffy wrote:My understanding is that CPU power is the limiting factor.
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
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.jupiter8 wrote:Damn,you're on fire nowadays!mystran wrote:CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.Meffy wrote:My understanding is that CPU power is the limiting factor.
- KVRAF
- 9590 posts since 17 Sep, 2002 from Gothenburg Sweden
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.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.jupiter8 wrote:Damn,you're on fire nowadays!mystran wrote:CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.Meffy wrote:My understanding is that CPU power is the limiting factor.
- KVRAF
- 2569 posts since 4 Sep, 2006 from 127.0.0.1
the force will be with you!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.
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
-
- KVRAF
- 1607 posts since 12 Apr, 2002
I could only guess what exactly you're up tomystran 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.
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}
-
- Skunk Mod
- 21249 posts since 10 Jun, 2004 from Pony Pasture
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.mystran wrote:CPU power isn't a limiting factor for circuit simulation. Unless something terrible happens, I'll be able to prove it soon enough.Meffy wrote:My understanding is that CPU power is the limiting factor.
-
- KVRAF
- 2256 posts since 29 May, 2012
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.My understanding is that CPU power is the limiting factor.
~stratum~
