# DSP function used by musical distortion plugins

In short: what kind of mathematical function was applied to this sine WAVE?

I am trying to implement my own distortion plugins. Amongst other things I have read several chapters of Will Pirkle's book ("Designing audio effect plugins in C++"). In the few examples there are in this book and that I could find on the internet, the distortion functions are always pretty straightforward. Here are few examples:

1. y = 2*1/(1 + e**(-k*x)) - 1
2. y = [(e**x - 1)(e + 1)]/[(e**x + 1)(e - 1)]
3. y = tanh(kx) / tanh(k)y = arctan(kx) / arctan(k)
4. y = sng(x) * [1 - e**(-abs(kx))] / [1 - e**(-k)]

I then decided to apply some distortions from Ableton Live(1) to a sine wave to see if I could replicate the distortion or get something similar to it.

Sound input: Sound output: And none of the examples I found in the literature seem to work. Indeed, if we take equation 3 as an example, if the input is symmetrical at its peak like the sine wave is, then the output should also be symmetrical at its peaks. But that's not the case. To be more specific, for all the distortion examples above, if two samples have the same value, then the output for those two samples will also be the same.

As per my screenshot, we can see that is clearly not the case for that distortion as we can see that the symmetry around the peaks is broken. So my question is simple: what kind of DSP function is applied to the signal? I am speculating that it must have some kind of feedback to create this shape? Is there any examples you guys can refer me to?

To be clear, I'm not trying to replicate this exact distortion, I'm just trying to understand the kind of DSP functions that are used to implement those distortion plugins.

(1) Ableton Live is a DAW (digital audio work station) and is used to make music.

update: thanks all for the help, overwhelmed by how nice this community is :)

• The short answer is that if it's not a simple waveshaper, it's often based on a circuit and/or physical model (e..g. tube amp, guitar pedal, vinyl, etc). David Yeh's thesis is a good place to start. May 18 at 13:34
• @datageist nice! I was about to start writing a comment about how I don't know how this is usually modelled in audio engineering, but a common way in communications engineering would be memory polynomials/Volterra series and finding optimal coefficients for that. But that thesis is actually domain-specific, so much more on point! May 18 at 14:57
• Well, one thing though, from a practical point of view, is that 2009 was before neural networks / deep learning became the big and relatively solid research area that it's now, and in many fields of comms over nonlinear channels, Volterra Series approaches have proven to not be better but orders of magnitude harder to fit and compute in real-time than neural networks applied to the input sample stream. So, one might also look for how other people model e.g. amplifier nonlinearities with neural networks in literature. May 18 at 14:58
• Marcus Müller is right about the neural networks. I am aware of the work of some researchers in Aalto University (Helsinki, Finland) that created amplifier simulations (and I believe they have tried with other audio effects) with neural networks and in their subjective tests showed that it was very difficult to differentiate between the real amp and the neural network simulated. I can't find the articles at the moment but I'll repost if I manage to do so. May 19 at 1:50

A simple and common way to generate distortion digitally is indeed to use a memoryless nonlinearity (such as the ones you mentioned), but just as a first step. The aim here is to perform some more or less soft clipping of the incoming waveform. But this is usually not enough to produce the desired sound. A very important step is the linear filtering after the nonlinearity. Clearly, the nonlinearity adds harmonics to the input signal, and the goal of the filtering is to shape the spectrum such that the harmonics don't sound too harsh. The usual filtering is some kind of lowpass filter with several resonances. In practice you don't want to have a lot of energy above about $$8$$ kHz in your spectrum. Very often you also attenuate low frequencies to avoid muddiness. • This is pretty close, Matt. I would suggest flattening the sine more using a high-order smoothstep function. And then we need an LTI filter that has for its step response something like a critical or over-damped 2nd-order response: $$y(t) = (e^{-t} - e^{-2t}) u(t)$$ It's possible that the OP's algorithm did zero-crossing detection and the output would look the same no matter what periodic waveform went in. May 18 at 18:03