# [sdiy] tanh() and approximations and warping, why is my maths wrong?

Brian Willoughby brianw at audiobanshee.com
Tue Jun 11 06:58:39 CEST 2019

```On Jun 10, 2019, at 1:58 PM, Gordonjcp <gordonjcp at gjcp.net> wrote:
> On Mon, Jun 10, 2019 at 09:11:58PM +0100, Tom Wiltshire wrote:
>> I think what he’s looking for is to know why x/(1+x) gives the right warping to get the correct cutoff frequency.
>>
>> Since I know very little of how digital filter models are derived from their analog counterparts and the approximations inherent in that process, I’m not the person to ask…
>>
>> Tom
>
> That's it exactly.  I'm not great at maths and the kind of algebra that
> goes into this sort of thing is a bit much for me, but x/(1+x) gets the
> filter tracking absolutely bang on.

Matthias hinted at the compete answer. There are series, like the Taylor series or Maclaurin series, where each additional term gets closer to a correct estimation of the actual function value. Since each additional term costs CPU time, the normal practice is to decide the tradeoff between accuracy and time for your range of values needed and processing power. The assumption is that calculating the precise function value is way too expensive, so the approximation is taken as close as is practical.

The Taylor series for tanh(x) = x - (x^3)/3 + 2(x^5)/15 - 17(x^7)/315 + ...

Since digital audio is only valid up to Nyquist, you only need the approximation to be accurate up to 0.5, and it looks like the first three terms are very accurate up to 0.5 Fs, and then it only slowly drifts away until well above 0.75 Fs. Even just the first two terms stay fairly close up to 0.5 Fs, so all you really need is:

y = x - x^3/3

An equation like x/(1 + x) doesn’t seem to fit that very closely. Maybe it’s a different series? Graphing x/(1+x) shows it to be well off tanh(x), so I’m not sure why you’re getting good results. It’s roughly 2/3 of tanh(x), so maybe you have some scaling?

Brian

```