# Why audio clipping produces harmonics?

Today I was talking to my collegue about clipping and he said that clipping produces harmonics in frequency domain as he showed me the clipped signal frequency response.

However when I asked him why does that happen, he couldn't answer. I did some googling and still not able to see why it is so.

This Link does mention about what we observed but didn't explain as to the reason why does it create harmonics? Does anyone know why it is so?

Clipping is a non-linear operation. Consider a system that clips all input whose absolute value is larger than 1: $$y(t) = \begin{cases}x(t)\text{ if }|x(t)|\leq 1 \\ 1 \text{ if } x(t) > 1 \\ -1 \text{ if } x(t) < -1 \end{cases}$$ While this system is linear for small inputs, it becomes non-linear as soon as the input becomes large enough.

Non-linear systems with no memory can be modeled by a power series: \begin{align}y(t) &= \sum_{n=0}^\infty a_n x^n \\ &= a_0 + a_1x(t) + a_2x^2(t) + a_3 x^3(t) + \cdots \end{align} Usually the coefficients $a_n$ become small as $n$ increases. Let's focus on $n=2$. If the input is a sine wave, then the clipped output contains the square of the sine wave, which has a DC term plus a term of twice the frequency of the input. It is the first distortion-causing harmonic.

If you play a bit with the equations you'll see that the terms for $n=3,4,\ldots$ each introduces new harmonics. When the input is more complex, such as a sum of sine waves of different frequencies, the harmonics will be more interesting.

Another, maybe more intuitive way to see it is as follows. A clipped sine wave looks a bit like a square wave -- the more clipping there is, the more similar it is. It is natural, then, that its Fourier series will resemble that of a square wave, which has plenty of harmonics.

If you have access to a spectrum analyzer, you can easily experiment with this by producing clipped sound in your computer, and seeing the output in the spectrum analyzer.

assuming there were no harmonics (frequency components other than the fundamental that are at integer multiples of the fundamental frequency) in the first place, that means the input to the clipping operation is a pure sine wave. a Fourier series analysis of that periodic sinusoid will show non-zero amplitude at only one frequency, the frequency of the sinusoid.

if the output of the clipping operation is something other than a sine wave (like a sine wave with either top or bottom peaks "clipped"), then it's a periodic waveform that is not a sine wave. then the Fourier series analysis will have to have other components than only that which was the original sinusoid.

It can be shown by the Stone-Weierstrass theorem that a power series representation approximates a non-linear system response to any desired precision if N is made sufficiently large. That is, consider a clipped signal $y(t)$ for input signal $x(t)$, then: $y(t) = \sum_{k=0}^{N}a_kx^{k}(t)$.

Thus, if $x(t) = a\sin\omega_0 t$, then $y(t)=\sum_{k=0}^{N}a_k(\sin\omega_0t)^{k}$. This will result in $y(t)$ to have harmonics of $\omega_0$. For instance, $\sin^2\omega_0t=0.5(1-\cos2\omega_0t)$.

For more complicated signal variations, such as speech,: The spectral content varies with time. However, assuming slow temporal variation in spectral content, the above reasoning of harmonic introduction due to clipping will still hold. Further, the harmonic spacing will be time-varying and will be dependent on the short-term signal spectrum. Example see the plot below for a speech signal (normalized to lie between +1 and -1, and corresponding clipped signal at amplitude value of 0.3 and re-normalized to same dynamic range as $x(t)$). Below the time domain signal, the corresponding signal spectrograms are represented. As speech is composed of harmonics in voiced regions (such as vowels), the harmonics strength gets further boosted in the clipped signal in these regions. Also, the lower harmonics have more amplitude strength (more darker in the plot). In the unvoiced regions, the temporal variations are very fast and clipping does not introduce very strong harmonics. In other words, in general, introduction of harmonics is dependent on the spectral content of $x(t)$. The harmonics are introduced for sure if $x(t)$ is a periodic signal. A practical simple way to see the appearance of harmonics is reproduced in the MATLAB code below. A simple sine/cosine wave, x, can be represented by a single harmonic, see X in the figure. If this wave is amplified and clipped, y, more harmonics will be needed to represent the clipped version, see Y.

% MATLAB
N = 32; n = 0:N-1;
x = cos(2*pi*n/N);
y = 2*x;
ind = find(y>1);  y(ind) = 1;
ind = find(y<-1); y(ind) = -1;
subplot(221),stem(n,x); title('x');
subplot(223),stem(n,y); title('y');
X=abs(fft(x));
subplot(222),stem(n,X);
title('X = abs(fft(x))');
Y=abs(fft(y));
subplot(224),stem(n,Y);
title('Y = abs(fft(y))'); 