[sdiy] Tanh and other distortion functions
Richie Burnett
rburnett at richieburnett.co.uk
Thu Apr 14 01:00:08 CEST 2011
Tanh is accurate for modelling lots of common saturation mechanisms like
those that occur in the long-tailed pair differential amplifier.
However, two challenges presented by Tanh from a DSP viewpoint are that it
results in a broad output spectrum (so needs adequate oversampling to avoid
introducing aliasing,) and the curve rounds off gradually over a wide input
range so you either need a big look-up table with interpolation, or a
high-order polynomial to model it accurately.
My favourite *cheap* saturation function for DSP audio work is: y = 1.5 x -
0.5 x^3
This gives an s-shape saturation curve for input values that lie between -1
and 1. The gradient (dy/dx) also goes to zero at x=-1 and x=1 meaning that
you can clip larger input magnitudes to the range -1<x<1 without incurring a
discontinuity in y or the first differential. The output essentially tends
smoothly to -1 or +1 as the input tends to -1 or +1 and then remains there
for x<-1 or x>1.
This polynomial is easily implemented efficiently on a DSP with MAC
operations by re-arranging into the Horner form: y = ( 1.5 - 0.5 x^2 ) x
It's also easy to implement on a micro that doesn't have hardware-multiply
support because the polynomial coefficients of 1.5 and 0.5 can easily be
realised using a combination of binary right-shift and add.
This function can also be used as a cheap wave-shaping function to convert a
triangle wave into a sinewave. Only odd harmonics exist in the output, the
strongest of which being the 3rd at about -38dB.
-Richie,
More information about the Synth-diy
mailing list