What would be the reason to use a non-BLT transfer function???Ichad.c wrote:Hey Mystran, I have a couple of () questions:
1: Can a non-BLT transfer function be used with your method?
Cheap non-linear zero-delay filters
-
- KVRAF
- 1607 posts since 12 Apr, 2002
- KVRAF
- Topic Starter
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
Well, anything with at most single zero per integrator should "work" but the point of BLT is to get something predictable.Ichad.c wrote:Hey Mystran, I have a couple of () questions:
1: Can a non-BLT transfer function be used with your method?
It depends on the intergrator (both structure and transfer function). The way you calculate new states is quite irrelevant, as long as you get the correct results. The correct results depend on what you are trying to do.2: Say - if Maxima can solve y0,y1,y3 etc, is there a general rule as to - how to update the states?
Urgh. I actually thought of complaining that he should post proper differential equations instead, but thought it'd be futile. In any case, you're best bet is to infer the analog model, and then discretize it properly.The reason I ask is - I've been trying to convert aciddose's Sallen-Key topology to zero-delay; Maxima's solution seems correct:
Also, I'm sorry to say but I'm not going to debug anyone's solution code. I don't even debug my own solution code. I've come to the conclusion that the easiest way is to debug the model and redo the solutions (using whatever form of automation; copy-paste from Maxima works, but a spice-like netlist to C++ would be quite nice actually), then test them as-is until it works (at which point one can simplify the solve for CPU purposes). If the model needs a change, just redo the solution unless it's something trivial; chances of getting this right is much better once the models get more complex.
- KVRian
- 1091 posts since 8 Feb, 2012 from South - Africa
Thanks for the advice mystran. Guess I'll have to go Analog->BLT->Zero-Delay.mystran wrote: In any case, you're best bet is to infer the analog model, and then discretize it properly.
Maxima can't do BLT, so I'll google, thanks.
Andrew
- KVRAF
- Topic Starter
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
First of all: Maxima CAN do BLT in the sense that you can map transfer functions. All you need to do is substitute s=1/tan(w/2)*(z-1)/(z+1) and use radcan() to simplify. It works, I use it all the time.Ichad.c wrote:Thanks for the advice mystran. Guess I'll have to go Analog->BLT->Zero-Delay.mystran wrote: In any case, you're best bet is to infer the analog model, and then discretize it properly.
Maxima can't do BLT, so I'll google, thanks.
However, that's NOT what you want here. Look at my example around page 2 or so: we want to simply replace every analog integrator (most commonly capacitor, though inductors are possible as well) with a digital equivalent. You then get a set of equations which depend on each other, and you solve the system. If you have trouble understanding the idea of differential equations, then the differentials (eg dV/dt) simply describe the (continuous) rate of change of the variables (ie what we want to integrate).
The BLT is built into the integrator we use for the TPT (topology-preserving transform; Vadim's term for the process). Every integration (of the differentials) becomes one discrete BLT integrator and we get the BLT of the filter as a by-product of the conversion using BLT integrators. You certainly don't need to do it explicitly.
- KVRAF
- 12615 posts since 7 Dec, 2004
it isn't "my" version of a sallen-key. it's the simplest (least expensive) configuration that works similarly to sallen-key. as i mentioned it's actually not correct.
to do it correctly is actually more expensive than other options.
for example, what i posted is to a sallen-key as this is to a "ladder":
a += x(input - feedback*d - a)
b += x(a - b)
c += x(b - c)
d += x(c - d)
obviously this implementation doesn't actually work. it does give you an idea of the structure though.
to do it correctly is actually more expensive than other options.
for example, what i posted is to a sallen-key as this is to a "ladder":
a += x(input - feedback*d - a)
b += x(a - b)
c += x(b - c)
d += x(c - d)
obviously this implementation doesn't actually work. it does give you an idea of the structure though.
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.
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.
- KVRian
- 1091 posts since 8 Feb, 2012 from South - Africa
Now I'm even more confused. Think that I'm way too much of a noob (c++, math and otherwise), so I think I'll gracefully stay out of this thread from now on.
Thank you Mystran and Aciddose for all the help, code snippets and explenations.
Regards
Andrew
Thank you Mystran and Aciddose for all the help, code snippets and explenations.
Regards
Andrew
- KVRAF
- 12615 posts since 7 Dec, 2004
here is a version of the 4-pole that doesn't alias like mad:
since the coefficients are all related directly to cutoff, they can actually all be placed into a look-up table of vectors. i'm not sure what the most efficient method would be.
the really interesting thing about this though is that it's still more expensive than the filter i've used for ten years which outputs similar results. (equally tunable, stable, sounds identical...)
the tanh shaping just makes it sound so muddy... what would be interesting is a much stronger saturation applied only to the feedback not in the signal path. that would start to sound like an IR3109 if adjusted correctly.
http://soundcloud.com/aciddose/boring-saturation-blah
here is an attempt at that. mp3 compression insisted on adding aliasing-like tones but these are not present in the raw output. not much tweaking, just a quick test to see if the same methods i normally use apply well here. apparently, they do.
it's possible to apply the shaping directly without modifying the calculation for s[3]'s state (and therefore all other states.) atanh works best to create the desired effect but approximations are both faster and can be tweaked to be scaled to match whatever you're modelling more accurately without scaling factors. (factors can be built into the approximation.)
still super expensive, though using this as a basic building block i believe it is possible to find good results.
Code: Select all
float f = tan(3.1415926535897932384626433832795f * cutoff);
float fd2 = 2.0f * f;
float r = 4.0f * resonance;
float g = 1.0f / (1.0f + f);
float f3 = f*g * g;
float f2 = f*g * f*g * g;
float f1 = f*g * f*g * f*g * g;
float f0 = f*g * f*g * f*g * f*g;
s[0] = limit(s[0], -1.0f, 1.0f);
float y3 = (g*s[3] + f3*s[2] + f2*s[1] + f1*s[0] + f0*in) / (1.0 + r*f0);
float xx = (in - r*y3);
float y0 = g*(s[0] + f*xx);
float y1 = g*(s[1] + f*y0);
float y2 = g*(s[2] + f*y1);
s[0] += fd2 * (xx - y0);
s[1] += fd2 * (y0 - y1);
s[2] += fd2 * (y1 - y2);
s[3] += fd2 * (y2 - y3);
return y3 * (1.0f + r);
the really interesting thing about this though is that it's still more expensive than the filter i've used for ten years which outputs similar results. (equally tunable, stable, sounds identical...)
the tanh shaping just makes it sound so muddy... what would be interesting is a much stronger saturation applied only to the feedback not in the signal path. that would start to sound like an IR3109 if adjusted correctly.
http://soundcloud.com/aciddose/boring-saturation-blah
here is an attempt at that. mp3 compression insisted on adding aliasing-like tones but these are not present in the raw output. not much tweaking, just a quick test to see if the same methods i normally use apply well here. apparently, they do.
it's possible to apply the shaping directly without modifying the calculation for s[3]'s state (and therefore all other states.) atanh works best to create the desired effect but approximations are both faster and can be tweaked to be scaled to match whatever you're modelling more accurately without scaling factors. (factors can be built into the approximation.)
still super expensive, though using this as a basic building block i believe it is possible to find good results.
Last edited by aciddose on Wed May 23, 2012 9:55 am, edited 1 time in total.
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.
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.
- KVRAF
- 12615 posts since 7 Dec, 2004
seems to get things more in-phase with the tanh saturation. in the version i posted it has a lot less effect.
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.
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.
- KVRAF
- 2569 posts since 4 Sep, 2006 from 127.0.0.1
aciddose: i so far only tryied one such "TPT" resonant filter (the diode ladder from karrikuh) and he initially used something similar to tanh() iirc
the thing was so nasty
when i replaced it with my old hard clipper (x = (x < -1 ? -1 : (x > 1 ? 1 : x))
it was so much better.. the tuning was perfect and there was no detuning when abusing the feedback level
tho there was something else which i also have in my old ladder filter (which is not TPT) - the more feedback you put the tuning starts to become like stair-like.. if you know what i mean.. that's due to precision being lost, even tho i use double everywhere
anyway, just wanted to note that a hardclipper works most of the times quite good, unless you want authentic saturation (which IMO only makes tuning worse)
the thing was so nasty
when i replaced it with my old hard clipper (x = (x < -1 ? -1 : (x > 1 ? 1 : x))
it was so much better.. the tuning was perfect and there was no detuning when abusing the feedback level
tho there was something else which i also have in my old ladder filter (which is not TPT) - the more feedback you put the tuning starts to become like stair-like.. if you know what i mean.. that's due to precision being lost, even tho i use double everywhere
anyway, just wanted to note that a hardclipper works most of the times quite good, unless you want authentic saturation (which IMO only makes tuning worse)
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
- KVRAF
- 12615 posts since 7 Dec, 2004
the hard-clip (limit() in my example) is required to eliminate aliasing.
feedback is never allowed over 100%. otherwise aliasing would be introduced.
feedback is never allowed over 100%. otherwise aliasing would be introduced.
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.
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.
-
- KVRist
- 346 posts since 4 Sep, 2006
Thanks AD, that's what had confused me. I was trying to work out how it fitted into the TPT structure but it is more to get the non-linearity to play nicelyaciddose wrote:seems to get things more in-phase with the tanh saturation. in the version i posted it has a lot less effect.
-
Richard_Synapse Richard_Synapse https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=245936
- KVRian
- 1187 posts since 20 Dec, 2010
If you pull out most of the nonlinearities then it spews CPU, true, because you could use a much cheaper filter. But this isn't the point here, ihmo.aciddose wrote:the really interesting thing about this though is that it's still more expensive than the filter i've used for ten years which outputs similar results. (equally tunable, stable, sounds identical...)
Richard
Synapse Audio Software - www.synapse-audio.com
- KVRAF
- 12615 posts since 7 Dec, 2004
well it is for me. the tanh result sounds horribly muddy. there are many other ways to apply the saturation characteristic to this filter (or any other) and for me the two most important factors are expense and aliasing. aliasing being way more important than expense.
also the tanh result sounds nothing like a transistor ladder anyway. the minimoog filter does not sound muddy like that.
by the way for anyone interested: if you lerp(1.0, saturation(x), depth) you get variable depth. it's also possible to modify the function to create far more shaping than a naive tanh function - the tanh function itself isn't strong enough to match some cases and it certainly isn't even near accurate to a real filter implementation except by coincidence. for example you could raise the result to a power, saturation(x) ^ depth which would give you the same variability but would also allow you to go far beyond 100%.
there are also other solutions. for example saturation(x) = 1 - y * abs(x). y = 1/4 gives similar results to the tanh approximation (although x^2 is closer, it's less stable) and remains stable. high values of y become unstable. y acts as a "depth".
also the tanh result sounds nothing like a transistor ladder anyway. the minimoog filter does not sound muddy like that.
by the way for anyone interested: if you lerp(1.0, saturation(x), depth) you get variable depth. it's also possible to modify the function to create far more shaping than a naive tanh function - the tanh function itself isn't strong enough to match some cases and it certainly isn't even near accurate to a real filter implementation except by coincidence. for example you could raise the result to a power, saturation(x) ^ depth which would give you the same variability but would also allow you to go far beyond 100%.
there are also other solutions. for example saturation(x) = 1 - y * abs(x). y = 1/4 gives similar results to the tanh approximation (although x^2 is closer, it's less stable) and remains stable. high values of y become unstable. y acts as a "depth".
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.
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.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
Yeah. The only non-linearity in Poly-Ana's filter is clipping in the feedback path to keep the level sane. This makes for a very Roland-y sounding filter.aciddose wrote:well it is for me. the tanh result sounds horribly muddy. there are many other ways to apply the saturation characteristic to this filter (or any other) and for me the two most important factors are expense and aliasing. aliasing being way more important than expense.
also the tanh result sounds nothing like a transistor ladder anyway. the minimoog filter does not sound muddy like that.
Here, I'll even tell you the "secret". Clip point is at 200%, not 100%. There you go, that, plus oversampling, is the secret to Poly-Ana's famous filter, which is otherwise a naive ladder implementation. (So naive that I independently invented it before discovering that it was a well known implementation.)
I've intended to experiment with adding a choice of saturation in the feedback path, rather than just the hard clip. But with resonance at zero the filter has a perfectly linear response and doesn't have any clip point. It'll filter whatever scale of signal you put into it. And to my ears, this sounds like classic synth filter behavior. And you can avoid or embrace the resonance clipping by controlling the input levels to the filters (and compensating for lost gain downstream in the Amp section(s)).
I do hope I can understand mystran's code enough to remove the saturators but keep the positive effects. Haven't tried yet... might get to it tonight.

