Diode clipper simulation instability

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I am trying to simulate attached diode limiter circuit.

Still learning electronics, fortunately found ODE for this model:

dVo/dt = (Vi-Vo) /RC - 2 Is/C * sinh(Vo/Vt)

- Found typical values for reverse current and thermal voltage
- Integrated using trapezoidal integrator and Newton-Rhapson

It works and clips nicely (avg 4 iterations) until ...
certain input level get exceeded, then it explodes. In particular it depends on input level / RC ratio .. The bigger input signal is, the lower cutoff freq is needed to make it stable.

I suppose I should limit the voltage somewhere.. as in real circuits.

Could someone help me and explain what is going on here?
You do not have the required permissions to view the files attached to this post.
giq

Post

I don't think I ever had any instabilities issues with this schema. Perhaps can you share some pieces of code you used?
Did you compare what happened to my implementation of it?

Post

Thanks, having ode mentioned above I integrate both sides and have:

y = f*(in-feedback) + s - 0.00016 * sinhf( feedback*40.0);

where
- s is state variable from tpt integrator
- constants are computed from typical values
- f - tan(omega)

feedback - previous y - Newton-Rhapson iterations

btw. Just found your code, seems your method is completely different + so many CPP templates aaaargh ;)
Last edited by itoa on Mon Oct 06, 2014 4:41 pm, edited 1 time in total.
giq

Post

Yes, I love templates. It enables me to have the cost function (the clipping function) and the optimization algorithm in different places, so I can reuse one or the other with no runtime cost.
If there is a divergence, you should see the number of Newton-Raphson iterations increase. The associated cost function does not need a lot of iterations (less than 10 for any input frequency), so you should see right from the start if something is wrong.
Also check by hand that the NR actual converges (i.e. f/f' is computed properly)

Post

I have 4-5 iterations, when I approach the 'limit' it goes rapidly to 128 and inf ;)

What I see if sinh gets too big it starts to 'oscillate'..

As for templates, nothing against them. Personally I like to have simple things expressed in the simplest 'wysiwyg' form, especially when I want to optimise this for SSE. Believe me if you put this in a few lines of code I would see your solution immediately, now I see a big construction of abstractions.
giq

Post

itoa wrote:y += f*(in-feedback) + s - 0.00016 * sinhf( feedback*40.0);
shouldn't that be

y = f*(in-feedback) + s - 0.00016 * sinhf( feedback*40.0); // no +=

for an iterative solver?

Post

And it is (my fault, wrong copy-pasted :). Edited and fixed..

So the iterative solver goes crazy as sinh increases for bigger signals, just can't drive it stronger than half clipping.. besides of that it works good 4-5 iterations..

Theoretically I could compute effective filter f and limit sinh .. to workaround this problem.. but I'm curious what is wrong here and how the real circuit (with limited voltages) works.
giq

Post

Strange. I don't have any issues with sinh at all :/
I think you are solving the ODE differently than I am, so that may explain why I can't pinpoint the issue.

Post

itoa wrote:And it is (my fault, wrong copy-pasted :). Edited and fixed..

So the iterative solver goes crazy as sinh increases for bigger signals, just can't drive it stronger than half clipping.. besides of that it works good 4-5 iterations..
Can happen with stiff systems, not necessarily a bug.
itoa wrote:Theoretically I could compute effective filter f and limit sinh .. to workaround this problem.. but I'm curious what is wrong here and how the real circuit (with limited voltages) works.
Precompute everything is ihmo the way to go (if that's what you mean), as you'll get correct and perfectly stable results at essentially no CPU cost - in this particular case anyway, as it's a 1-dimensional ODE.

Richard
Synapse Audio Software - www.synapse-audio.com

Post

Thanks Richard, Miles: I should take a look at your code then

btw. you mean this http://matt.eifelle.com/2010/10/05/elec ... overdrive/
Your approach is different, you don't use sinh, seems you picked up another state variable
giq

Post

Yes and no. I made a newer version here: https://github.com/mbrucher/AudioTK/blo ... Filter.cpp
My state variable is the output voltage directly. I don't compute sinh, because I'm using exp directly (and then the reverse of it). I think it's the same, isn't it?

Post

Miles just tried out your code.. And what is interesting .. our results are so different:

Take a look at attached screenshot: fed with 100Hz ramp down wave

Yours:
Screenshot 2014-10-07 08.19.26.png
Mine:
You do not have the required permissions to view the files attached to this post.
giq

Post

Ok our circuits are different though :)
giq

Post

Oh yes, I remember now... I think the condensator is in serial and not parallel. Sorry for the noise...

Post

I found mine as "low pass diode limiter". Your acts more like HPF, it sounds quite raw, whereas 2nd boosts lower harmonics.
giq

Post Reply

Return to “DSP and Plugin Development”