### Analog modeling of a diode clipper (3a): Simulation

Now that we have a few methods, let’s try to simulate them. For both circuits, I’ll use the forward Euler, then backward Euler and trapezoidal approximations, then I will show the results of changing the start estimate and then finish by the Newton Raphson optimization. I haven’t checked (yet?) algorithms that don’t use the derivative like the bisection or Brent algorithm.

All graphs are done with a x4 oversampling (although I also tried x8, x16 and x32).

# First diode clipper $V_i - 2 R_1 I_s sinh(V_o/nV_t) - \int \frac{2 I_s}{C_1} sinh(\frac{V_o}{nV_t}) - V_o = 0$

## Forward Euler

Let’s now figure out what to do with the integral by deriving the equation: $\frac{dV_o}{dt} = \frac{\frac{dV_i}{dt} - \frac{2 I_s}{C_1} sinh(\frac{V_o}{nV_t})}{1 + \frac{2 I_s R_1}{nV_t} cosh(\frac{V_o}{nV_t})}$

So now we have the standard form that can used the usual way. For the derivative of the input, I’ll always use the trapezoidal approximation, and then for the output one, I’ll use the forward Euler which leads to the “simple” equation: $V_{on+1} = V_{on} + \frac{V_{in+1} - V_{in} - \frac{4 h I_s}{C_1} sinh(\frac{V_{on}}{nV_t})}{1 + \frac{2 I_s R_1}{nV_t} cosh(\frac{V_{on}}{nV_t})}$

## Backward Euler

For the backward Euler, I’ll start from the integral equation again and remove the time dependency: $V_{in+1} - V_{in} - 2 R_1 I_s (sinh(\frac{V_{on+1}}{nV_t}) - sinh(\frac{V_{on}}{nV_t})) - \int^{t_{n+1}}_{t_n} \frac{2 I_s}{C_1} sinh(\frac{V_o}{nV_t}) - V_{on+1} + V_{on} = 0$

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

I didn’t use this equation for the Backward Euler because I would have had a dependency in the sinh term, so I would still have required the numerical methods to solve the equation.

## Trapezoidal rule

Here, we just need to change the discretization for a trapezoidal one: $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$

## Starting estimates

Starting from the different rules, we need to replace sinh(x):

• for the pivotal by $\frac{x}{x_0} sinh(x_0)$
• for the tangent rule by $\frac{x}{nV_t} cosh(\frac{x_0}{nV_t}) + y_0 - \frac{x_0}{nV_t} cosh(\frac{x_0}{nV_t})$

## Graphs

Let’s see now how all these optimizers compare (with an estimate of the next element being the last optimized value):

Obviously, the Forward Euler method is definitely not good. Although is on average 4 times lower, the accuracy is definitely not good enough. On the other end, the other two methods give similar results (probably because I try to achieve a convergence quite strong, with less that 10e-8 difference between two iterations).

Now, how does the original estimate impact the results? I tried the Backward Euler to start, and the results are identical:

To have a better picture, let’s turn down the number of iterations to 1 for all the estimates:
{"ft_lang_label":"__label__en","ft_lang_prob":0.87572354,"math_prob":0.99911946,"size":2924,"snap":"2021-43-2021-49","text_gpt3_token_len":654,"char_repetition_ratio":0.12534246,"word_repetition_ratio":0.03265306,"special_character_ratio":0.20793433,"punctuation_ratio":0.09856631,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99994695,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-28T02:06:41Z\",\"WARC-Record-ID\":\"<urn:uuid:50a8d7df-10c6-4062-8fba-6cc91676ef39>\",\"Content-Length\":\"95297\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7a47912b-7d23-44c6-b2ca-ccc3ac2fff2e>\",\"WARC-Concurrent-To\":\"<urn:uuid:4b144ebf-dbf3-4633-8c4e-ee28fdc7b7e1>\",\"WARC-IP-Address\":\"155.133.132.2\",\"WARC-Target-URI\":\"https://blog.audio-tk.com/2016/04/12/analog-modeling-of-a-diode-clipper-3a-simulation/\",\"WARC-Payload-Digest\":\"sha1:OMIRPEMTCC7JU6UJCMTINUAXFCXUMJQ6\",\"WARC-Block-Digest\":\"sha1:OIBPYN2AQBQR4V2P6J5J63XCZTWBQQBT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323588246.79_warc_CC-MAIN-20211028003812-20211028033812-00105.warc.gz\"}"}