About Newton Raphson

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Audiority wrote:Thanks guys. Let's take a simple diode clipping circuit with a resistor and two diodes in parallel. It goes fine up to 30dB, but once over it blows up. Having gains over 30dB is not so unusual when you want to replicate a clipping stage that features an op-amp. That's clearly something wrong I'm doing, but to figure it out maybe I have to get back to spice first or make some real measurements.
I assume your circuit is something like a signal source (eg. opamp, whatever) feeding into a resistor with output taken from the other side and a pair of parallel diodes shorting the output to ground. Initially when the output is low enough, most of the voltage drop will be over the diodes, but as soon as the diodes start conducting, most of the voltage drop will shift to the resistor (which is now the current limiting element). The conducting diode junction voltage should stay somewhere around 0.7V or so; it'll get slightly higher (depending on the value of the resistor) as you increase the input further, but emphasis here is on "slightly" as the resistor will only allow approximately linear current increase, which translates to approximately logarithmic voltage increase over the diodes.

So yeah.. if it blows up you are doing something wrong. :)

Post

I'm not expecting it to work with 700 volts :) I might be wrong, but let's take an average guitar signal of 200mV going through an op-amp that amplifies the signal by ~30/40dB. The outgoing voltage should be around 20V, going into the diode clipping stage which will clamp the signal around 0.7V. Am I right?

Thanks,
Luca

Post

Audiority wrote:I'm not expecting it to work with 700 volts :) I might be wrong, but let's take an average guitar signal of 200mV going through an op-amp that amplifies the signal by ~30/40dB. The outgoing voltage should be around 20V, going into the diode clipping stage which will clamp the signal around 0.7V. Am I right?
Right, but the simple solver above (which is just a test with sinh) converges if the absolute value of the initial guess is less than 710. The output voltage of the opamp should be 20 v and the initial guess for the diode pair voltage may be whatever it was in the previous iteration.
p.s. if the diodes are across the opamp negative feedback loop as in a tubescreamer overdrive pedal then the opamp output voltage cannot be 20v. If that's the case then it's necessary to write an equation for an opamp with a pair of diodes across it, as it's no longer an independent opamp.
~stratum~

Post

stratum wrote:It's not very likely that you'll find an opamp that operates at a voltage that can blow up the solver. No opamp circuit can output 700volts. If you see that voltage at the output then something else is wrong with the model.
The funny thing is, it doesn't even really matter if you had an opamp that can output 700V, because as long as there is some sort of series resistance the exponential junction voltage only increases logarithmically past a certain point. In practice real-life diodes have some series resistance too, so this is really a non-issue. Just adding something like 1 to 10 ohms of series resistance to your diode model will let you simulate a diode from your 700V opamp to ground just fine and this won't really make any meaningful difference when the circuit is operating in more realistic ranges (ie. with the larger value series resistor that you want to add to your clipper circuit in order to actually read the clipped "output" signal).

Obviously a real-world opamp would also have some output resistance; even if one could supply 700v it probably won't do it when shorted straight to ground. ;)

Post

mystran wrote:
stratum wrote:It's not very likely that you'll find an opamp that operates at a voltage that can blow up the solver. No opamp circuit can output 700volts. If you see that voltage at the output then something else is wrong with the model.
The funny thing is, it doesn't even really matter if you had an opamp that can output 700V, because as long as there is some sort of series resistance the exponential junction voltage only increases logarithmically past a certain point. In practice real-life diodes have some series resistance too, so this is really a non-issue. Just adding something like 1 to 10 ohms of series resistance to your diode model will let you simulate a diode from your 700V opamp to ground just fine and this won't really make any meaningful difference when the circuit is operating in more realistic ranges (ie. with the larger value series resistor that you want to add to your clipper circuit in order to actually read the clipped "output" signal).

Obviously a real-world opamp would also have some output resistance; even if one could supply 700v it probably won't do it when shorted straight to ground. ;)
That also makes the "opamp with a pair of diodes across the negative feedback loop" equation trivial, not that my math skills are adequate to derive it by hand, though. Even starting from that point my 'equation solving lazyness' prefers an automated nodal analysis.
~stratum~

Post

Hello Luca !

You're running into a classic issue of Newton-Raphson's algorithm in the context of audio processing. This happens because of any of these reasons :
  • you use the result you got at the previous sample as an initial value
  • the equation you are trying to solve with NR might have a very short range of potential initial values which won't lead to divergence
  • when your algorithm uses a signal with a large amplitude as an input, as a consequence you increase the potential distance between the wanted consecutive results / outputs
  • something that can happen also is that you have a nonlinear model for one of your electronic components which is too much simple, and the function you are trying to solve is not monotonic which is one of the conditions for NR to work properly
The solutions are the following :
  • Damped Newton-Raphson, use of the gmin, homotopy and other methods like that might help, but in general they will just increase a bit the stable range of convergent input values
  • Other methods than NR not using the derivative might be a lot slower but at least they will be stable
  • Find a way to get a more interesting initial value, such as interpolation, use of linearization, approximations, study of the equation itself in a way or another. I know Urs use tricks like this and run several possibilities in parallel to find the most efficient / stable one for a given sample to compute (see the DAFX 15 article and Urs Heckmann's blog about this topic)
  • Find a way to limit your delta, this way you'll prevent the scheme from being divergent. In my tests, that was one of the most efficient ways to solve that problem, but you need to think about it well enough (see the DAFX 15 article about this specific topic)
  • Solve NR in a lookup table once and for all before processing, with little input values steps and a large table, this way your calculus there will always converge, and you'll speedup a lot the processing itself
Bibliography :

https://urs.silvrback.com/one-pole-monster
https://bholmesqub.github.io/DAFx15/

Have fun !

Post

Thank you all, guys!

@mystran + @stratum: Yes, I guess one of my errors is the wrong approach to the op-amp in a negative feedback. In this case I can't rely on the gain being calculated by 1 + (R2/R1), but I have to dig deeper than that and solve for the entire system.

@Ivan: thank for the hints!

Post

https://www.ntnu.edu/documents/10012011 ... ion_18.pdf

This paper specifically investigate the stability of NR for exp-like functions.

Post Reply

Return to “DSP and Plugin Development”