Diode clipper simulation instability
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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?
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
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
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?
Did you compare what happened to my implementation of it?
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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
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
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
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)
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)
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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.
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
- u-he
- 28065 posts since 8 Aug, 2002 from Berlin
shouldn't that beitoa wrote:y += f*(in-feedback) + s - 0.00016 * sinhf( feedback*40.0);
y = f*(in-feedback) + s - 0.00016 * sinhf( feedback*40.0); // no +=
for an iterative solver?
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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.
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
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
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.
I think you are solving the ODE differently than I am, so that may explain why I can't pinpoint the issue.
-
Richard_Synapse Richard_Synapse https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=245936
- KVRian
- 1136 posts since 20 Dec, 2010
Can happen with stiff systems, not necessarily a bug.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..
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.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.
Richard
Synapse Audio Software - www.synapse-audio.com
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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
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
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
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?
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?
-
- KVRian
- Topic Starter
- 513 posts since 3 Sep, 2009 from Poland
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: Mine:
Take a look at attached screenshot: fed with 100Hz ramp down wave
Yours: Mine:
You do not have the required permissions to view the files attached to this post.
giq
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
Oh yes, I remember now... I think the condensator is in serial and not parallel. Sorry for the noise...