My Profile Photo

Deviant Syndrome


coding, multimedia, gamedev, engineering


Kkampf RMod Tech notes

As a part of me trying to get into DSP (and attract ladies), I made a simple VCV Rack module that does ring modulation. The implementation of this effect in digital domain is devilishly simple. You just multiply two signals sample by sample to get the output. I still wanted my module to comply VCV Rack’s audio audio signal “virtual voltage” standards, so I decided to apply some simple soft clipping to the multiplication product, because multiplication operation can easily give us results in higher orders of magnitude, than the arguments. In theory, a hyperbolic tangent function should applied, because it has those nice smooth leads to the asymptotic (-1, 1). The problem here that it is kinda complex function to evaluate. So, we’d better use some approximation. Let’s see, what is available.

Polynomial interpolation

$$ tanh(x) \approx a_{0}x + a_{1}x^2 + a_{2}x^3 + \cdots + a_{n}x^n $$

Hyperbolic tangent Polynomial Interpolation

So, we took some of the points of the original curse and interpolated over them. Coefficients are not very important here (or I was too lazy to retype them in \(L_{A}TE^{X}\). Does not look very well to me, it has up to 10th degree argument which implied a lot of multiplications. Also, as you can see from the graph, it goes wild after about, 5. I also tried to experiment to reduce the high-degree arguments as non-significant, but that approach failed miserably. Ok, moving on.

Continued fraction representations

$$ tanh(z) = \frac{z}{1 + \frac{z^2}{3 + \frac{z^2}{5 +\frac{z^2}{7 + \frac{z^2}{9 + \frac{z^2}{11 + \ldots}}}}}} $$

And here we can have a recursive process of getting fractions to achieve a certain degree of approximation. Looks nice, but still quite some work to do, especially in C++ which I’m terrible at. Interesting, can we have a super crude approximation, just giving up on subsequent recursive divisions.

$$ tanh(x) \approx \frac{x}{1 + \vert{x}\vert} $$

Hyperbolic tangent Polynomial Interpolation

This looks alright, in fact quite suitable for my need of simple output clipping. In case you’re curios, this is how it sounds like: