Why the Simpson’s Sum Does Not Get Used In Circuit Simulations

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:

  1. An LC tank circuit, aka a pure inductor connected to a pure capacitor, could end up unstable, gaining amplitude, or
  2. 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 … )

(As of 06/20/2018 : )

1: )

I suppose that one way in which many complexities in circuit-theory could be avoided, without actually solving exact, instantaneous state-equations, is in the notion that each node actually possesses the smallest-possible amount of capacitance that the simulation could support, so that for one iteration of a time-domain simulation, more current, or less current could actually flow onto that node, than flows off it. Then, one iteration later, the voltage of that node would adapt. This would be useful in determining how a circuit responds to a ‘Pulse’.

But with NG-SPICE, I see that the ‘DC Sweeps’ are actually computed differently, from the (frequency-domain) ‘AC Sweeps’. It seems that for each of these sweep-types, the system stimulates the circuit as the user defined, and waits for some equilibrium-state to be reached, before generating the outputs with the associated input-value. But somehow, for AC Sweeps, the system seems to ignore the constraints that would be imposed on it, by the DC Equilibrium. It was as if a DC Equilibrium needed to be computed first, and that based on its resulting values, the AC Properties of each component were being computed, as though a special version of Ohm’s Law was being applied. Such a version of Ohm’s Law is factually possible, because for every one frequency, impedance is capable of being a complex number (usually labeled ‘Z’) , with which a complex-numbered voltage and current can be associated.

Special components need to be predefined, that can also amplify an AC signal – i.e., that can generate output-voltages as a function of known input-voltages. And in this regard, The AC behavior of certain ‘constant-current circuits’, whose outputs also act as inputs, may not be simulated properly by NG-SPICE.

(Updated 06/21/2018, 18h45 : )

For example, If a MOSFET has a feedback-resistor connected to it Source, and a constant Gate voltage, then the feedback resistor is also likely to force the MOSFET to produce constant current at its Drain, since any current flowing through its Drain also flows through its Source, where changes in current would also produce changes in the voltage, across the feedback resistor, but modulating the Gate-Source voltage oppositely to the direction of current-change proposed at the Drain of that transistor. It’s uncommon to connect the MOSFET in this way, and what NG-SPICE might predict in AC Mode, is the correct bias-current at the Drain, with apparent output-impedance defined internally by the transistor, and by its bias quantities. In order to take such circuit-blocks into account, a time-domain simulation would in fact be needed.

But, If I tell NG-SPICE to stimulate a prospective ‘operational amplifier circuit’ in the frequency-domain with a 1VAC input-signal, at each frequency, then at some frequencies, gain exceeds supply voltage ! +46db ~= 200x amplitude .


 

BTW, I do not agree that the polar form is more convenient, when impedances need to be in parallel, multiplied or divided, because the definition of parallel resistances is already straightforward, as long as the reciprocals of each can be computed and then, the reciprocal of the sum. And, multiplication as well as division of complex numbers is well-defined.



 

(Updated 06/21/2018, 15h10 … )

2: )

I think that a rudimentary time-domain circuit simulation would already have a chance to succeed, if as a minimum, the following was done:

The circuit could be initialized, in that the current flowing through capacitors and inductors could be set to zero, and the total amount of capacitance connected to each node was computed for that node, based on addition. ( :3 ) Then, the following loop should already give results:

(Solution removed 06/22/2018, 6h30, because incorrect. )

 

A possible type of computation to perform on a node could be, to derive its ‘combined resistivity’, based on all the components connected to it. And then hypothetically, a capacitance could also be computed, which, together with the combined resistivity, yields a cutoff-frequency, corresponding to the step-frequency (h) :



 

 

(Updated 06/22/2018, 16h35 : )

3: )

I have found my own idea, of requiring and setting minimum capacitance for each node, to be incorrect. Instead, a hypothetical, alternative approach might work, as follows:

The circuit could be initialized, in that the current flowing through capacitors and inductors could be set to zero, and ‘the combined conductivity’ connected to each node could be computed for that node, based on the addition of the reciprocals, of connected resistor values, of inductor values times (h), and the addition of capacitor values times (h). Then, the following loop should give results:

  1. Update the current flowing through all the components, excluding the capacitors, based on the voltage-differences between nodes. For inductors, this means integrating over time.
  2. Integrate the total amount of current flowing onto each node, from all the explicit components excluding capacitors, dividing by the node’s ‘combined conductivity without capacitors‘.
  3. Update the current flowing through all the capacitors, computing the voltage between nodes minus their earlier saved charge, times capacitance, divided by time.
  4. Integrate the total amount of current flowing onto each node, from the capacitors, dividing by the node’s ‘combined conductivity with capacitors‘.
  5. Nevertheless, integrate the computed current flowing through the capacitors, divided by their capacitance, over time, into the saved charge. This should be done, to prevent any inaccuracies in the ‘combined conductivities’ from detuning the frequencies, at which circuits will resonate, due to the exact capacitance.

 

(Update 06/23/2018, 19h35 : )

There are some details in the hypothetical procedure above, which I felt I should specify explicitly, because my words may not seem intuitive to some readers. I feel that even though such procedures may not be what finally gets used by application programmers, I nevertheless need to develop them, in order to be able to say, that ‘I understand how a program works, more or less.’

I used the word ‘Integrate’ rather loosely. In steps (2) and (4), I’m referring to a Summation which is to take place, once per component connected to any node, which should just happen to result in a voltage, and which should just happen to be carried forward, from one iteration of the simulation to the next. It would make no sense, to use the ‘Trapezoidal Sum’ here.

But in steps (1) and (5), I’m suggesting Integration Over Time, where a Trap Sum could be used. Step (5) would actually correspond to a 1st-order Integral, where step (4) would form a secondary Summation. It seemed important that inaccuracies in step (4) not affect the time-constant of steps (3) and (5), where step (5) really just reverses what step (3) calculated.

If what gets used in step (5) was the Trap Integration Method, then it might not be made to match the differentiation which is to take place in step (3), so that even step (5) might better just be omitted, and the ‘saved charge’ of a capacitor updated when the delta is converted into current, within step (3).

Dirk

 

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.