### Analog modeling of a diode clipper (4): State-space

Update: It seems I have misunderstood the DK method, so instead I’m using a variation of the Nodal Analysis, so this can be understood as a state-space MNA method.

When analyzing a circuit form scratch, we need to replace all capacitors by an equivalent circuit and solve the equation with this modified circuit. Then, the equivalent currents need to be updated with the proper formula.

# What does the formula mean?

So this is the update formula:

$i_{eq_{n+1}} = 2\frac{C}{\Delta t}V_{n+1} - i_{eq_{n}}$

Let’s write it differently:

$i_{eq_{n+1}} + i_{eq_{n}} = 2C\frac{V_{n+1}}{\Delta t}$

If we consider $V_{n+1}$ as being a difference, then this is a derivative with a trapezoidal approximation. In conjunction to the original equation, this means that we have a system of several equations that are staggered. Actually $V_n$ has not the same time constraints than $i_{eq_n}$, it lags it by half a sample.

On the one hand, there are several reasons why this is good. Staggered systems are easier to write, and also if the conditions are respected, they are more accurate. For instance, for wave equations, using central difference instead of the staggered system leads to HF instabilities.

The issues on the other hand are that we do a linear update. If this is fine for the SD1 circuit, it is not the same for the two clippers here, as the amount of current in the condensator is a function of the diode function (not the case of the SD1 circuit, as only the input voltage impacts it). But, still, it’s a good approximation.

# Usage on the clippers

OK, let’s see how to apply this on the first clipper:
$V_{in} = V_{on} + I_s sinh(\frac{V_{on}}{nV_t})(\frac{h}{C_1} + 2 R_1)) - \frac{hI_{eq_n}}{2C_1}$

The time dependency is kept inside $I_{eq_n}$, and we don’t need the rest like for the trapezoidal rule:

$V_{in+1} - V_{in} - I_s sinh(\frac{V_{on+1}}{nV_t}) (\frac{h}{C_1} + 2 R_1) - I_s sinh(\frac{V_{on}}{nV_t}) (\frac{h}{C_1} - 2 R_1) - V_{on+1} + V_{on} = 0$

Quite obvious it is simpler! But actually the update rule is a little bit more complicated:

$I_{eq_{n+1}} = \frac{4 C_1}{h} (V_{in} - V_{on} - R_1 I_s sinh(\frac{V_{on}}{nV_t})) - I_{eq_n}$

Actually,a s we computed all the intermediate values, this comes at a cost of a few additions and multiplications, so it’s good.

Let’s try the second clipper:

$V_{in} = V_{on} (1 + \frac{2 R_1 C_1}{h}) + R_1 I_s sinh(\frac{V_{on}}{nV_t}) - I_{eq_n} R_1$

Compared to:

$V_{on+1} - V_{on} = h(\frac{V_{in+1}}{R_1 C_1} - \frac{V_{on+1} + V_{on}}{2 R_1 C_1} + \frac{I_s}{C_1}(sinh(\frac{V_{on+1}}{nV_t}) + sinh(\frac{V_{on}}{nV_t})))$

And in this case, the update formula is simple, as the tension on the condensator is the output voltage:

$I_{eq_{n+1}} = \frac{4 C_1}{h} V_{on} - I_{eq_n}$

Once again, the dependency is hidden inside $I_{eq_n}$ which means simpler and also faster optimization.

# Conclusion

Using the equivalent currents transformation is actually really easy to implement and it allows to simplify the function to optimize. It doesn’t change the function itself compared to the trapezoidal rule, because they are actually (in my opinion, I have done the actual math) two sides of the same coin.

I’ve applied this to the SD1 filter. The simplification in the equation also leads to an improvement in the computation time, but for low sampling rates the filter does not converge. But the higher the sampling rate, the better the improvement over the traditional trapezoidal rule.