# Is there a way to compute the spectrum effect of a non-linear function?

I'm interested in developing audio software. I've read the books by Will Pirkle and there's something I'm struggling to understand about how non-linear functions affect the frequency spectrum of a signal. Particularly I'm concerned about avoiding aliasing noise.

In his book, Pirkle points out the problem: harmonics are created by non-linear functions (e.g. clipping/rectifiers, etc) and those harmonics, in principle, extend upwards past the Nyquist frequency, causing aliasing. The only solution offered is an oversampling->LPF->decimation pipeline, which is easy to understand. If you oversample by 4x then you should only get aliasing from the harmonics that are past 4x the original Nyquist frequency (which is hopefully very low energy by that point).

What I'm wondering though is: is there any way to calculate the rate at which the harmonics decrease in power for a given function (other than actually evaluating the function on a test signal and doing an FFT)? The idea is if you could compute this, maybe you could set the oversample rate adaptively.

is there any way to calculate the rate at which the harmonics decrease in power for a given function

Yes, but it's complicated and typically not worth the bother. If the non-linearity is static, i.e. can be expressed

$$y[n] = f(x[n])$$

without any delays or feedback you can represent this function as a polynomial (e.g. Taylor expansion). For a sine wave input this will give you an idea of the harmonics of the output.

However, this polynomial expansion can be complicated and it also depends on the amplitude of the input. If you run a sine wave through a clipper, the output spectrum will depend a lot on the pre-clipper gain. Combined that with the fact that the input signal is typically NOT a sine wave and can vary quite a lot makes this very difficult.

The idea is if you could compute this, maybe you could set the oversample rate adaptively.

Same answer: could be done, but it's not all that useful. For starters, in a real time system you need to accommodate the peak CPU load. Having variable CPU load can save you average CPU load, but that's generally not the limiting factor. You don't want to build a processor that runs out of MIPS when the guitar player hits the wrong note.

The other part is that the standard solutions (oversample by 2 or by 4) work quite well. For example a guitar signal has both harmonic and inharmonic content. The really high frequency stuff is generally inharmonic and some amount of aliasing doesn't really harm. Depending on the guitar and pick ups there isn't al lot of harmonic energy above 5k and very little above 10k. So even oversampling by 2 will allow you to remove a big chunk of aliasing.

Stealing$$^\dagger$$ from this answer:

For non-linear functions that admit a series expansion (e.g. Taylor/Maclaurin), you can get a decent intuition for how fast the harmonics decay. The Maclaurin expansion of a function $$f(x)$$ is:

$$f(x)=\sum_{n=0}^\infty \left[ \frac{f^{(n)}(0)}{n!} x^n\right]$$

$$^\dagger\tiny\mbox{ Made this answer Community Wiki, so I don't steal rep.}$$

• It's worth mentioning that Taylor expansion goes pretty much out of the window for many commonly encountered nonlinearities. In particular, the Taylor expansion of an idealised brickwall clipper $y \mapsto \max(1, \min(y, 1))$ around 0 is the same as for a perfectly linear transmission, but it's anything but linear and produces very severe harmonics. Sep 27, 2022 at 22:02
• @leftaroundabout Feel free to edit that in!
– Peter K.
Sep 28, 2022 at 14:54