Thought it would be nice to have a place share some thoughts and approximations on distortion - sigmoids and waveshapers and the like.
I'll start:
Code: Select all
Tanh - continued fraction:
x2 = x*x;
a = (((x2+378)*x2+17325)*135135)*x;
b = ((28*x2+3150)*x2+62370)*x2+135135;
tanh_out = a/b;
Tanh - Cody & Waite's rational approximation:
x2 = x*x;
p0 = -1613.119023996228053;
p1 = -99.225929672236083313;
p2 = -0.96437492777225469787;
q0 = 4840.357071988688686;
q1 = 2233.7720718962312926;
q2 = 112.74474380534949335;
b = x2*((p2*x2+p1)*x2+p0)/(((x2+q2)*x2+q1)*x2+q0);
tanh_out = x+x*b;
Atan - rational approximation:
x2 = x*x;
x4 = x2*x2;
a = x*(105+55*x2);
b = 105+90*x2+9*x4;
atan_out = a/b;
Other useful functions:
Inverse sqrt:
out = x/sqrt((x*x)+1);
Cubic Soft Clipper: (Julius Smith)
a = clip(x,-1,1);
out = 1.5*a*(1-(a*a)*0.3333333);
My "non-boosting" sigmoid:
out = tanh(sinh(x));
//rewrite as -> out = 1-2/(exp(exp(x)-1/exp(x))+1)
Fast tanh-like 3rd term: (mentioned by C.Budde)
a = abs(x);
b = 6+a*(3+a);
out = (x*b)/(a*b+12);
Langevin Function: (mind your singularities here!)
out = coth(x) - (1/x);
My nasty symmetrical 'non-limiting' distortion: (based on asinh)
a = x*2;
out = (ln(a+sqrt(a*a)+1))*0.5;
My supressor dist:
a = sin(atan(x));
b = cos(tanh(x*x+0.4342944819));
out = atan(a/b);
Some Asym types:
My 'real' inv_sqrt clipper: (nasty)
a = clip(x,-1,1);
b = a+1;
c = a*1.8;
d = inv_sqrt(c);
out = a/(c-0.48);
My Asym nr7:
a = atan2(cosh(x),sinh(x)+1);
out = tanh(x*-a*0.32*-a)*0.56;
Anybody got more to share? Was also wondering about memory effects and what role they play in the analog world. Most technical papers seem to simplify most non-linear functions to a memoryless tanh(x). Was wondering if any more complex/analog examples exist. Have only seen a transistor differential amplifier on musicdsp, was wondering about JFet, OTA or just more static waveshapers in general...
I find distortion to be very interisting
Andrew Ainslie
