Before the steady state

One step, computed twice

A step response from the poles is exact. The same step walked forward in time is not, and the difference between them is the trapezoidal rule's own error rather than anything about the circuit. It falls by a factor of four every time the step is halved, which is a claim about a method and can be watched.

Every response in the previous field assumed a settled circuit. This one is about what happens before that: a source that was zero and is now one volt, and a network finding its way to the answer the frequency plots take for granted.

There are two ways to compute it, they are genuinely independent, and the gap between them is not a defect to be hidden. It is a measurement of the method — and since almost everything numerical in this subject is done by the second method, knowing its size is worth a figure.

One step response, computed twice: from the poles, and by walking the network forwardA damping ratio of 0.22, so the overshoot is 49.2%. The two curves are drawn on top of each other; the panel below is the difference between them, which is the trapezoidal rule's error at 500 steps and reaches 1.70e-3 V.00.50011.50024output (volts), for a 1 V step inthe final valuesolid: from the poles · dashed: stepped forwardtime (milliseconds) above · the same span as a fraction, belowgap between the two routes (volts)1e-71e-61e-51e-41.0m10m1.0e+2m1solved, then checked — residues against 500 trapezoidal stepsthe numerical route is out by 1.7e-3 V
Fig. 1 One step response drawn twice. The solid curve is exact, computed from the network’s own poles by a residue expansion. The dashed curve is the same network walked forward in time by the trapezoidal rule, which is what a circuit simulator does. The panel underneath is the difference. The slider is the number of time steps, and the gap falls by a factor of four for every doubling.

The exact route

A linear network’s response to a step is a sum of exponentials, one for each of its natural frequencies, plus the final value. That is not an approximation: it is what the inverse Laplace transform of a rational function with distinct poles is, written out.

Getting it requires the poles, and the poles come from the matrix rather than from a formula. The nodal matrix is affine in the complex frequency, so its determinant is a polynomial; sampling that determinant around a circle in the complex plane and transforming recovers the polynomial exactly; its roots are the poles. The weight attached to each exponential — its residue — follows from evaluating the numerator and the derivative of the denominator at that pole.

For the circuit in the figure, a series RLC with a damping ratio of 0.22, the answer is a decaying cosine: two complex-conjugate poles, two conjugate residues, and a final value of one volt. The curve is that expression sampled at as many instants as the plot has pixels, and it is correct at every one of them independently. There is no accumulation and no step size.

The other route, which is what actually gets used

Almost nothing outside a textbook is computed that way, because almost nothing outside a textbook has poles that can be found. Add one nonlinear element — a diode, a transistor, an amplifier that saturates — and the transfer function ceases to exist.

What is used instead is a method that never needs one. Replace each capacitor and inductor by a resistor and a source whose value depends on the previous instant, solve the resulting resistive network, advance, repeat. Each step is one linear solve of exactly the kind the first essay in this collection describes, and the reactive elements’ memory is carried in the source values.

The particular rule used here is the trapezoidal one: it assumes the current through a capacitor varies linearly across each step and integrates accordingly. It is the default in every circuit simulator worth using, for two reasons that are worth naming. It is second-order accurate, so halving the step quarters the error. And it is A-stable, meaning a stable circuit stays stable in the simulation no matter how long the step — which sounds like a technicality and is the difference between a slightly inaccurate answer and an exponentially growing one.

The gap, measured

The lower panel of the figure is the difference between the two curves, on a logarithmic scale, and the slider makes the convergence visible directly. The worst disagreement anywhere in the response, at each setting:

Time steps Worst gap
60 1.15 × 10⁻¹ V
125 2.70 × 10⁻² V
250 6.79 × 10⁻³ V
500 1.70 × 10⁻³ V
1000 4.25 × 10⁻⁴ V
2000 1.06 × 10⁻⁴ V
4000 2.65 × 10⁻⁵ V

Each row is almost exactly a quarter of the one above it. That is second-order convergence measured rather than asserted, and it is the kind of claim that is easy to state and rarely checked: the ratio is 4.26, 3.98, 3.99, 4.00, 4.01, 4.00 down the column, which is as close to four as a floating-point measurement of a fourth-order-accurate quantity gets.

The absolute numbers are worth having as well. At sixty steps the answer is wrong by more than a tenth of a volt on a one-volt step — visibly wrong, and wrong in a specific direction: the trapezoidal rule under-resolves the ringing and slightly damps it, so the simulated circuit looks better behaved than the real one. At four thousand steps the error is below thirty microvolts, which is far under any measurement anybody would make.

Why this belongs in a collection about models

The site’s rule is that no model appears without the point at which it stops being true, and it would be inconsistent to apply that to circuits and not to the arithmetic used on them.

A numerical integration is a model of a differential equation exactly as an ideal amplifier is a model of a device. It is excellent inside a range and wrong outside it; the range is set by a parameter under the user’s control; and the error can be computed rather than guessed. The difference is that a numerical error carries no physical intuition to catch it with — a response that has been quietly damped by too coarse a step looks like a response, and there is nothing in the picture that says otherwise.

That is why the figure plots the gap rather than describing it. A method’s error is a measurement like any other, and a figure that does not show it is asserting that it is small.

The step size that is not chosen

There is a practical wrinkle worth stating, because it is where the reasoning above meets what a simulator actually does.

Nobody sets a fixed step. Real simulators vary it, taking small steps where the solution is changing quickly and long ones where it is not, with the step chosen by estimating the local error and keeping it below a tolerance. That is much better than a fixed step and it introduces a subtlety of its own: the local error per step is what is controlled, and the global error — the thing in the figure — is an accumulation of local errors that the controller never sees.

The two are related but not the same, and the relationship depends on the circuit. In a stable network the errors decay along with everything else and the global error stays close to the local one. In a network with a pole near the imaginary axis — a high-quality resonator — they do not decay, and the global error accumulates over the whole run. A simulation of a sharp filter’s ringdown is therefore much less accurate than its tolerance setting suggests, and by an amount that grows with the quality factor.

What the step response contains

Before the two routes, one observation about why a step is the input worth choosing.

A step contains every frequency, with an amplitude falling as 1/f. So a step response is, in a precise sense, the whole frequency response measured at once — and the derivative of a step response is the impulse response, whose Fourier transform is exactly the transfer function. Nothing is lost by looking at one rather than the other.

What differs is where the information is concentrated. A step response shows the low-frequency behaviour as its final value and the high-frequency behaviour as its initial rise, so a fast feature occupies a tiny fraction of the trace and a slow one dominates it. A frequency response spreads them evenly across a logarithmic axis. That is why a step is the natural test for something that has to settle and a sweep is the natural test for something that has to pass a band, and why both figures appear throughout this collection.

There is also a practical reason a step is used to test a real circuit: it is the easiest signal to generate accurately. A square wave from a good generator has an edge faster than most circuits respond to, requires no calibration of amplitude against frequency, and reveals overshoot, ringing and settling time in one picture on any oscilloscope.

Why the trapezoidal rule and not something simpler

Two other integration rules are worth naming, because the reasons for not using them are the reasons this one is standard.

Backward Euler assumes the current through a capacitor is constant across a step and equal to its value at the end. It is first-order accurate, so halving the step only halves the error rather than quartering it, and it is heavily damping: a lossless resonant circuit simulated with backward Euler loses amplitude every cycle, which is a fictitious loss the circuit does not have. A ringing waveform computed that way decays visibly faster than the real one, and nothing in the picture says so.

Forward Euler uses the value at the start of the step instead. It is also first-order, and worse: it is not stable at all for a step longer than a limit set by the fastest pole, so a network with one fast element requires tiny steps everywhere, and taking a step slightly too long produces a solution that grows exponentially rather than one that is merely inaccurate.

The trapezoidal rule averages the two, which is what makes it second-order and what makes it neither damping nor amplifying — it preserves the amplitude of a lossless oscillation exactly, at the cost of slightly mis-stating its frequency. That last property has a name, and its consequence is visible in the figure: the two curves separate mostly in phase rather than in amplitude, which is why the gap plotted underneath grows and shrinks in step with the ringing rather than decaying smoothly.

The one place the trapezoidal rule misbehaves

Honesty requires the other side, since this essay has spent several paragraphs recommending it.

Applied to a circuit with a very fast pole and a long step, the trapezoidal rule does not blow up — it is stable — but it produces an oscillation at the step frequency that has nothing to do with the circuit. A step change applied to a network with a small time constant relative to the step gives an answer that alternates above and below the true value, decaying slowly, and it looks exactly like ringing.

Every real simulator has a remedy, usually a second-order rule that damps such artefacts, applied either always or only after a discontinuity. The detail is beyond this collection’s scope; what is worth carrying away is that the artefact exists, that it looks like a physical effect, and that a ringing waveform from a simulation should always be checked by shortening the step. If the ringing changes when the step changes, it belongs to the method.

That test is exactly what the slider on the figure at the top of this essay performs, which is the second reason the figure has one.

What the exact route cannot do

Symmetry demands the other side of the ledger, since the residue expansion has been described as exact.

It requires distinct poles. Two coincident poles make the expansion divide by zero, and a critically damped circuit is exactly that case. The generator behind the figure refuses it rather than perturbing the circuit slightly to make the arithmetic work, which would produce a correct- looking curve for a circuit nobody asked about. That refusal is why the damping slider in the next essay stops at 0.95 rather than passing through 1.

It requires linearity, absolutely and everywhere. The whole idea of a transfer function is that the response to a sum is the sum of the responses; a single nonlinear element destroys that, and the poles are then not merely inaccurate but meaningless.

And it requires the poles to be findable, which for a large network means rooting a high-degree polynomial. The recovery used here is well conditioned for the response but marginal for the residues once poles start to cluster, because a residue divides by the product of the distances to every other pole. The filter essays elsewhere in this collection take the design poles rather than the recovered ones for exactly that reason, and say so.

Between them, those three restrictions are why time-stepping is the general method and the exact one is the special case — the reverse of the order they are usually taught in.

A second-order step at ζ = 0.3Overshoot measured off the curve is 37.2%, and it settles inside 2% after 1.12 ms. Inverting the standard relation on that overshoot returns a damping ratio of 0.300 against the 0.3 the components were built for.00.50011.5001234time (milliseconds)output (volts), for a 1 V step inthe final value37.2% oversolved, then checked — overshoot read off the curvesettles inside 2% after 1.12 ms
Fig. 2 The same exact route applied across a family. Each of these is a residue expansion at a different damping ratio, and the overshoot marked on the curve is read off the computed points rather than taken from the standard formula — which is then required to return the damping ratio the components were built with.
The same step through all three, at order 5Overshoot measured off each curve: Butterworth 12.8%, Chebyshev 12.4%, Bessel 0.8%. The family with the flat delay barely overshoots; the other two, whose delay varies by tens of per cent, overshoot by more than ten and are hard to tell apart — magnitude flatness does not decide it.00.500101234time (milliseconds)output, for a 1 V step inButterworth 12.8%Chebyshev 12.4%Bessel 0.8%solved, then checked — residues, checked by integrationovershoot follows the delay, not the magnitude
Fig. 3 The same exact route applied to three fifth-order networks at once. Each of these is a residue expansion over five poles, and each was checked against the same network walked forward in time — which is the pairing this essay is about, used as a working tool rather than as a demonstration.

Two routes as a working habit

This figure is the clearest instance in the collection of a discipline that runs through all of it, so it is worth stating in general terms.

A single computation confirms only that it is self-consistent. It cannot detect a mistake in its own premises, and in this subject a mistake in the premises produces output that looks entirely reasonable. The remedy is to compute the same quantity a second time by a route that shares no arithmetic with the first, and to accept the answer only when they agree to a stated tolerance.

The pairs used elsewhere in this collection are all of that shape. A transfer function from the matrix against the same one from its recovered poles. A ladder solved by nodal analysis against a chain-matrix product. A phase margin from the loop gain against an overshoot from the step response. The impedance of a real capacitor from the network against the closed form for the same three elements. In each case the two routes are chosen for their independence rather than their convenience, and in each case the tolerance is stated.

What makes this particular pair the best illustration is that the two routes do not agree to machine precision, and are not supposed to. The disagreement is the trapezoidal rule’s error, it has a known form, and measuring it confirms both routes at once: the exact one because the numerical one converges to it, and the numerical one because it converges at the rate its theory predicts. Two routes that agree exactly prove less than two routes that disagree by precisely the amount they should.

Two poles at ζ = 0.3, recovered from the matrixThe poles are at -477.4 ± j1518 hertz. Their distance from the origin is the natural frequency to six digits; the cosine of their angle from the negative real axis is the damping ratio. The step response beside them follows.the step this produces00.50011.5001234σζ = 0.3000ω₀ = 1592 Hzsolved, then checked — poles by rooting the determinantnatural frequency recovered to 6 digits
Fig. 4 Where the exact route gets its numbers. The two poles recovered from the network’s own matrix, with the circle of constant natural frequency and the ray of constant damping drawn through them rather than under them. The step response beside is the same expansion the figure at the top of this essay uses.