Cheap non-linear zero-delay filters

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

karrikuh wrote:I would be very interested if there are developers of guitar amp sims/distortion circuit emulations reading this thread who could try out if mystran's method can improve accuracy/efficiency of their code and share their experience.
Haven't tried but I'd expect it to blow up in some cases. E.g. a diode clipper circuit as found in stomp boxes has a sinh(x) nonlinearity as opposed to tanh(x):

https://ccrma.stanford.edu/~dtyeh/paper ... lipode.pdf

Anyhow there's solutions for such problems that are efficient and stable, especially if circuit elements are constant- then you could use a state-space representation, for example.

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

Post

mystran,

that optimization of yours is genius.

Am I misleading when I summarize it as "use linear zero delay feedback filter technology but add delayed nonlinearities"?

Cheers,
- Clemens

Post

aciddose wrote:
karrikuh wrote:
aciddose wrote:could you replace the averaging "half sample delay" with lerp() so it's clear to anyone reading the code what is happening?

have you tried more advanced interpolations?
I would say don't waste your time on this (well, you already did ... :) ). I found one can safely omit the 1/2 sample delay in practice without any impact on tuning/sound. The filter code for which I posted sound samples above (with 2x oversampling) doesn't have it.
it should definitely make a difference. not a very big difference, but it should be audible in certain configurations. mystran already noted that aliasing may be reduced due to the filtering of the input.
Sure, the lowpass effect of crude linear interpolation for realizing the 1/2 sample delay will slightly reduce aliasing, but that's more of an artifact with positive side effects and not the original idea behind introducing the delay. If you replace the linear interpolation by an ideal bandlimited sinc-interpolator, then the lowpass effect is gone...

But really, just try it out yourself, mystran provided a nice piece of code you can mess with.

Post

cheppner wrote:mystran,

that optimization of yours is genius.

Am I misleading when I summarize it as "use linear zero delay feedback filter technology but add delayed nonlinearities"?
Yeah, pretty much. Delay the non-linearities by half a sample, which happens to be just enough to make them only depend on what we already know.

Then replace them with resistors when calculating the linear solution. It was this second step where I started getting good results.

Post

Richard_Synapse wrote:
karrikuh wrote:I would be very interested if there are developers of guitar amp sims/distortion circuit emulations reading this thread who could try out if mystran's method can improve accuracy/efficiency of their code and share their experience.
Haven't tried but I'd expect it to blow up in some cases. E.g. a diode clipper circuit as found in stomp boxes has a sinh(x) nonlinearity as opposed to tanh(x):

https://ccrma.stanford.edu/~dtyeh/paper ... lipode.pdf

Anyhow there's solutions for such problems that are efficient and stable, especially if circuit elements are constant- then you could use a state-space representation, for example.
Why would this blow up?

It's not like this method is limited to tanh() non-linearities. I first used the idea for the diode-limit of an SVF, and when I realized the error was well-defined, I generalized it to other things.

In the circuit above, the non-linearity isn't unbounded in the sense that would cause any problems here. At low inputs (and capacitor voltages) the diodes are open circuit, and it's a low-pass. At high inputs and/or capacitor voltages, the diodes become a "wire" and bypass the capacitor, at which point current is limited by the resistor (which is a stable circuit too).

The paper gives an approximation for the equivalent "resistance" for the diodes. That's what you want to use. Once you have a resistance value, you can calculate a linear solution using the method here. The problem is that diode current depends on resistor current which depends on diode current, which needs to be solved first. This is not something this method addresses.

The thing is, in circuits where there would truly be problems with run-away non-linearities, the practical analog prototype will typically do one of the following: (1) hit supply rails, which puts a bound on currents or (2) release magic smoke. Only in the case where a circuit depends critically on a non-linearity acting on high-frequency signals accurately would there be a problem, and while there probably exists some such circuit, it's rather questionable design in analog as well because you should plan for component tolerances (no practical diode is instant for example, even if at audio rates we can treat something like 1N4148 pretty much as such).

Post

Richard_Synapse wrote: Haven't tried but I'd expect it to blow up in some cases. E.g. a diode clipper circuit as found in stomp boxes has a sinh(x) nonlinearity as opposed to tanh(x):

https://ccrma.stanford.edu/~dtyeh/paper ... lipode.pdf

Richard
Hey Richard, the non-linearity does NOT have a sinh(x) shape. Read more carefully.
Last edited by Ichad.c on Mon May 21, 2012 8:52 pm, edited 1 time in total.

Post

mystran wrote:
Since you probably want to combine common sub-expressions as much as possible, this tends to be the part where you need to do some manual work, and it's also the most error prone part.
You should have written "manual work" in CAPITAL letters. Dang killing me :ud:

One thing that has bothered me since the thread started - how much difference does the non-linearities make to the sound 1x Distortion in forward-path and 1 in Feedback Path vs full non-linearities?

Should I try and take mystran's filter, and try and fudge a couple of "personalities" out of it? As a test to see - how much the non-linearities play a subjective role?

Andrew

Post

mystran wrote:The paper gives an approximation for the equivalent "resistance" for the diodes. That's what you want to use. Once you have a resistance value, you can calculate a linear solution using the method here. The problem is that diode current depends on resistor current which depends on diode current, which needs to be solved first. This is not something this method addresses.
I don't really follow. Equation (2) from the paper looks like it can be directly realized using your approach.

Post

Ichad.c wrote:
Richard_Synapse wrote: Haven't tried but I'd expect it to blow up in some cases. E.g. a diode clipper circuit as found in stomp boxes has a sinh(x) nonlinearity as opposed to tanh(x):

https://ccrma.stanford.edu/~dtyeh/paper ... lipode.pdf

Richard
Hey Richard, the non-linearity does have a sinh(x) shape. Read more carefully.
This is what I wrote above yes. Read more carefully?

Richard
Last edited by Richard_Synapse on Mon May 21, 2012 8:55 pm, edited 1 time in total.
Synapse Audio Software - www.synapse-audio.com

Post

mystran wrote:The paper gives an approximation for the equivalent "resistance" for the diodes. That's what you want to use. Once you have a resistance value, you can calculate a linear solution using the method here. The problem is that diode current depends on resistor current which depends on diode current, which needs to be solved first. This is not something this method addresses.
Thanks, I see what you mean now- read your first post again and got it. Really brilliant stuff! :)

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

Post

Richard_Synapse wrote:
This is what I wrote above yes. Read more carefully.

Richard
Sorry Richard, I should actually proof-read what I write more carefully! I edited my post.
Also did not imply any disrespect! The actual signal does not have a sinh(x) characteristic, the sinh(x) part has to do with the current. The signal shape would be simplified to tanh(x) - if I understand it correctly.

Regards
Andrew

Post

Ichad.c wrote:Sorry Richard, I should actually proof-read what I write more carefully! I edited my post.
Also did not imply any disrespect! The actual signal does not have a sinh(x) characteristic, the sinh(x) part has to do with the current. The signal shape would be simplified to tanh(x) - if I understand it correctly.
Yes, tanh is one possible static approximation. There's some more given in his papers, I think atan(x) was slightly closer to his reference curve.

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

Post

aciddose wrote:sallen-key is similar to this:

Code: Select all

f_c = not sure, i'd have to check
fb_c = fb + fb / (1.0 - f_c);
a += (in - a + (a - saturate(b)) * fb_c) * f_c
b += (a - b) * f_c
Thanks for the clarification aciddose, just wanted to know for educational purposes.

Regards
Andrew

Post

the difference you need to be aware of is that: (a - saturate(b)) * fb_c) is actually not correct. b is scaled first, then saturated, then differentiated by a. doing it this way is just an optimization.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Hey Mystran, I have a couple of ( :idiot: ) questions:

1: Can a non-BLT transfer function be used with your method?

2: Say - if Maxima can solve y0,y1,y3 etc, is there a general rule as to - how to update the states?

The reason I ask is - I've been trying to convert aciddose's Sallen-Key topology to zero-delay; Maxima's solution seems correct:

Code: Select all

// Sallen-Key Filter by aciddose
    Omega = cutoff / samplerate;
    fcut = Pade_Sin(6.2831853071795864769f * Omega);
    r = res + res / (1.0 - fcut);
    fcut2 = fcut*fcut;


    //solve y1
y1 = -fcut * buf2 + (fcut2 * r - fcut2 + fcut) * buf1 + fcut2 * input / (1.0 + fcut2 * r);

    //solve y0
y0 = fcut2 * r * y1 + (fcut * r - fcut + 1.0) * buf1 + fcut * input / (1.0 + fcut2 * r);


But I can't seem to get a LP response of of it - all I get is a low-level bandpass. Think I'm updating the states incorrectly.

Andrew

Post Reply

Return to “DSP and Plugin Development”