In recent postings I have been sharing my experiences, learning to use the software ‘NG-SPICE’, which uses numerical methods to simulate circuit-diagrams. Well, to simulate ‘Netlists’ anyway, that represent circuits. And the GUI which I have has as drawback, not being as fancy as some commercial GUIs, and only allowing me to perform certain types of simulations, that include DC Sweeps, AC Sweeps, and Pulses. I think that if I was to delve deeper, and edit my Netlists using a text-editor, I might be able to expand the range of possibilities…
But then I do think that a premise of how ‘SPICE’ works in general, is to state the Voltage as a Primary phenomenon, to which Current is Secondary. By that I mean, pure capacitors are simulated as having current, that is the derivative of voltage, while in pure inductors, the current is merely the integral of voltage. ( :2 ) And so, SPICE uses numerical approximations of both derivatives and integrals. ( :1 ) And in the many settings my GUI does offer me, I get to choose which method of integration out of two I prefer: ‘Trap’ or ‘Gear’.
The question could just pop into somebody’s head: ‘Methods of numerical integration were taught to me, which are more accurate than Trap, such as The 3-point Simpson’s Sum. (Actually, I was taught to compute 2/3 times the Midpoint, plus 1/3 times the Trap Sum, not their average.) Why can’t I select that?’ And the answer I would suggest is as follows: I already wrote a posting about the simplest method of numerical differentiation, and about how, if the step-size is too long, it can generate differentials which are too high in amplitude. If this was combined with an unsuitable method of integration, one of two paradoxical results could follow:
- An LC tank circuit, aka a pure inductor connected to a pure capacitor, could end up unstable, gaining amplitude, or
- The same, simulated circuit could lose momentum, apparently to nowhere, and stop ringing.
Either result is counter to what happens in Physics. And so it would seem that the medium-range errors in the Trap method, happen to complement the errors exactly, in the simplest method of differentiation. If the differentiation came into being because consecutive samples were subtracted, then simply to add them again, will reproduce what we started with. And so our pure, lossless resonant circuit, would resonate forever, as it should… The engine has no place for ‘dampened integrals’ here.
The other method available, ‘Gear’, is also known as ‘The Backward Differentiation Formula’, or the ‘BDF’. It’s mainly suited for trying to simulate systems which are ‘stiff’ i.e., where the step-interval is assumed to be too long, and where heavy bodies interact with great force, approximated with coarse time-steps. It’s like The Simpson’s Sum on steroids. I’ve heard bad things about it. One main reason not to use it, is the History by which it will stabilize a simulated circuit, while the same circuit, when actually etched into silicon, became unstable. There might be cases where only the Gear Method can be used, but it should be used as a last resort.
The (simpler) ‘Riemann Sum’ has as a problem, that it must either be conceptualized as being ‘left-handed’ or ‘right-handed’, which means, that each input sample must either represent an abstract rectangle that follows it, or that preceded it. With critically-sampled – i.e., long stepped – signals, doing so would introduce a phase-shift. The Trap Sum alleviates such a phase-shift.
(Updated 06/23/2018, 19h35 … )