tanH soft clipping
Posted: Sat Aug 20, 2016 3:45 am
Im wondering if there is a way to get tanh(x) style function in the FV-1? I use it alot in my algorithm designs for warm clean saturation, but I really have no idea how i would replicate these nice non linearities in assembler with the available opcodes. I am guessing it would have something to do with log/exp?
Hyperbolic tangent
The hyperbolic tangent is the solution to the differential equation
f'=1-f^{2} with f(0)=0 and the nonlinear boundary value problem:
1/2fn=f3-f; f(o)=f1(infinity) = 0
I am not a math pro and I really don't know what this means. I am trying to learn as its becoming useful in this DSP design world but damn its like learning a new language from trying to google the definition of each word hah.
Some music DSP info that is somewhat enlightening :
http://www.musicdsp.org/showone.php?id=178
"tanh(x) = sinh(x)/cosh(x)
= (exp(x) - exp(-x))/(exp(x) + exp(-x))
= (exp(2x) - 1)/(exp(2x) + 1)"
he also explains a taylor series for the exp approximation. but the above equation looks like something that could happen in spinASM relatively easily, but how to account for the /16 aspect of the exp opcode?
in the comments of the thread I found these:
tanh (x) = 1 - 2 / (exp (2*x) + 1)
tanh(x/2)~ x/(abs(x)+3/(2+x*x))
tanh(x/2) ~ x/(abs(x)+2/(2.12-1.44*abs(x)+x*x)) Maximum normalized difference 0.0063 from real tanh (x/2) - good enough now.
Here's the Analog Devices "Sharc" DSP translation of the tanh function (inline processing of register f0):
Hyperbolic tangent
The hyperbolic tangent is the solution to the differential equation
f'=1-f^{2} with f(0)=0 and the nonlinear boundary value problem:
1/2fn=f3-f; f(o)=f1(infinity) = 0
I am not a math pro and I really don't know what this means. I am trying to learn as its becoming useful in this DSP design world but damn its like learning a new language from trying to google the definition of each word hah.
Some music DSP info that is somewhat enlightening :
http://www.musicdsp.org/showone.php?id=178
"tanh(x) = sinh(x)/cosh(x)
= (exp(x) - exp(-x))/(exp(x) + exp(-x))
= (exp(2x) - 1)/(exp(2x) + 1)"
he also explains a taylor series for the exp approximation. but the above equation looks like something that could happen in spinASM relatively easily, but how to account for the /16 aspect of the exp opcode?
in the comments of the thread I found these:
tanh (x) = 1 - 2 / (exp (2*x) + 1)
tanh(x/2)~ x/(abs(x)+3/(2+x*x))
tanh(x/2) ~ x/(abs(x)+2/(2.12-1.44*abs(x)+x*x)) Maximum normalized difference 0.0063 from real tanh (x/2) - good enough now.
Here's the Analog Devices "Sharc" DSP translation of the tanh function (inline processing of register f0):
Code: Select all
f11 = 2.;
f0 = f0 * f11;
f11 = abs f0;
f3 = 3.;
f12 = f11+f3;
f12 = f11*f2;
f3 = 6.;
f12 = f12+f3;
f0 = f0*f12;
f12 = f11*f12;
f7 = 12.;
f12 = f12+f3;
f11 = 2.;
f0 = recips f12,
f7=f0;
f12=f0*f12;
f7=f0*f7,
f0=f11-f12;
f12=f0*f12;
f7=f0*f7,
f0=f11-f12;
f12=f0*f12;
rts(db);
f7=f0*f7,
f0=f11-f12;
f0=f0*f7;