# Harmonics

## What is intermodulation?

In the Harmonics topic, we have seen how nonlinearities in a system can produce harmonics when a perfect sine wave is applied as input. But what happens if more than one sine wave is the input? The result is not just the harmonics of each sine wave, but also components at the sums and differences of the harmonics and the fundamental frequencies. If you have a signal composed of two sine waves with fundamental frequencies $f_1$ and $f_2$ (with $f_1 > f_2$), besides the harmonics of each sine wave ($2f_1$, $2f_2$, $3f_1$, $3f_2$, ...), the components $f_1 \pm f_2$, $2f_1 \pm f_2$, $2f_2 \pm f_1$, $2f_1 \pm 2f_2$, $3f_1 \pm 2f_2$, $3f_2 \pm 2f_1$, ... will show up at the output of a nonlinear system.

Let's say that we apply a signal composed of two perfect sinusoides $x(t) = \sin(\omega_1 t) + \sin(\omega_2 t)$ to a certain system ($\omega_x=2\pi f_x$). If the system is linear, the output will have the same perfect sinusoides at its output: $$y(t) = b x(t) + a = b(\sin(\omega_1 t) + \sin(\omega_2 t)) + a$$ where $a$ and $b$ are the parameters of the linear system, $x(t)$ is its input and $y(t)$ is the output.

Now let's assume that the system is nonlinear and, like any nonlinear system, can be approximated by a polynomial function $y(t) = a + b x(t) + c x(t)^2 + d x(t)^3 + ...$. How deep we go into the terms of the polynomial function depends on how accurate we want to approximate the system. We apply the same signal and look at the output: $$\begin{equation}y(t) = a + b (\sin(\omega_1 t) + \sin(\omega_2 t)) + c (\sin(\omega_1 t) + \sin(\omega_2 t))^2 + d (\sin(\omega_1 t) + \sin(\omega_2 t))^3 + ...\label{eq:nonlinear}\end{equation}$$ Since this expression can become quite long, let's look at each term of the polynomial individually.

For the $x^2$, we have $$\begin{equation}(\sin(\omega_1 t) + \sin(\omega_2 t))^2 = \sin(\omega_1 t)^2 + 2\sin(\omega_1 t)\sin(\omega_2 t) + \sin(\omega_2 t)^2\label{eq:x2}\end{equation}$$ We make use of the trigonometric properties (you can find them on wikipedia): $$\sin(\theta)^2 = \frac{1-\cos(2\theta)}{2}$$ $$\sin(\theta_1)\sin(\theta_2) = \frac{1}{2} \left( \cos(\theta_1 - \theta_2) - \cos(\theta_1 + \theta_2)\right)$$ Going back to equation $\eqref{eq:x2}$, we get: $$(\sin(\omega_1 t) + \sin(\omega_2 t))^2 = \frac{1-\cos(2\omega_1 t)}{2} + \cos((\omega_1 + \omega_2) t) - \cos((\omega_1 - \omega_2) t) + \frac{1-\cos(2\omega_2 t)}{2}.$$ From the quadratic term we get components at $2f_1$, $2f_2$ (the harmonics) and $f_1 \pm f_2$ (the intermodulation).

Now let's see the term $x^3$ in $\eqref{eq:nonlinear}$: $$(\sin(\omega_1 t) + \sin(\omega_2 t))^3 = (\sin(\omega_1 t) + \sin(\omega_2 t))^2(\sin(\omega_1 t) + \sin(\omega_2 t))$$ $$=(\sin(\omega_1 t)^2 + 2\sin(\omega_1 t)\sin(\omega_2 t) + \sin(\omega_2 t)^2)(\sin(\omega_1 t) + \sin(\omega_2 t))$$ $$\begin{equation}=\sin(\omega_1 t)^3 + 3\sin(\omega_1 t)^2\sin(\omega_2 t) + 3\sin(\omega_1 t)\sin(\omega_2 t)^2 + \sin(\omega_2 t)^3\label{eq:x3}\end{equation}$$ We make use of the trigonometric identities: $$\sin(\theta)^3 = \frac{3\sin(\theta) - \sin(3\theta)}{4}$$ $$\sin(\theta_1)\cos(\theta_2) = \frac{1}{2}\left(\sin(\theta_1 + \theta_2) + \sin(\theta_1 - \theta_2)\right)$$ Replacing them in each term of $\eqref{eq:x3}$:

First and last term $$\sin(\omega_x t)^3 = \frac{3}{4}\sin(\omega_x t) - \frac{1}{4}\sin(3\omega_x t)$$

Second and third term $$3\sin(\omega_x t)^2 \sin(\omega_y t) = \frac{3}{4} (1 - \cos(2\omega_x t)) \sin(\omega_y t)$$ $$= \frac{3}{4}\left[\sin(\omega_y t) - \frac{1}{2}\left( \sin((\omega_y + 2\omega_x) t) + \sin((\omega_y - 2\omega_x) t) \right) \right]$$

From the cubic term we get components at $3f_1$, $3f_2$ (the harmonics) and $2f_1 \pm f_2$, $f_1 \pm 2f_2$ (the intermodulation).

This process can be repeated to higher-order terms to find the intermodulation products. Later in this topic, you can see a table with more intermodulation products. In pratice, the harmonics and the intermodulation products show as distortion in the output signal. In audio systems, distortion is a big topic and ideally we would want no components except in the fundamental frequencies.

 A1 A2

The sliders below control each coefficient of the polynomial function. The sliders on the right control the amplitudes of a sine wave at 5Hz (A1) and another at 6 Hz (A2). In the above plot you can see the original sine wave ($x(t)$) and the output $y(t)$ of the system. As you increase c and d (the nonlinear components), the output signal becomes more distorted.

 b = c = d =

The sliders above control each coefficient of the polynomial function. In the plot above you can see the input and output signals in the frequency domain. As you increase c and d (the nonlinear components), the harmonics and the intermodulation components start to show up.

## Intermodulation in differential signals

Often, a signal is transmitted in a differential way, i.e., the difference between two opposed signals represent the analog signal. For example, a signal $x(t)$ can be represented as $x(t) = x^+(t) - x^-(t)$, where $x^+(t) = \sin(\omega_1 t) + \sin(\omega_2 t)$ and $x^-(t) = -(\sin(\omega_1 t) + \sin(\omega_2 t))$. In that case, and assuming both signals pass through the same system, we can easily realize that $x^+(t)^2 = x^-(t)^2$ and the quadratic terms of each signal cancel. In fact, that is true for any power of an even number, such as $x(t)^4, x(t)^6, ...$. In sum, the intermodulation products generated from even-order terms cancel out in a differential signal. Only the ones from the odd-order terms remain. However, it must be pointed out that the intermodulation products closer to the fundamental frequencies are generated by odd-order terms.

## Table of intermodulation products

This table extends the terms found in the first section to higher-order terms:

OrderIntermodulation productsHarmonicsExample frequencies
1st$f_1, f_2$5,6
2nd$f_1 \pm f_2$$2f_1, 2f_21,11; 10, 12 3rd2f_1 \pm f_2, f_1 \pm 2f_2$$3f_1, 3f_2$4, 7, 16, 17; 15, 18
4th$2f_1 \pm 2f_2$$4f_1, 4f_22, 22; 20, 24 5th3f_1 \pm 2f_2, 2f_1 \pm 3f_2$$5f_1, 5f_2$3, 8, 27, 28; 25, 30
6th$3f_1 \pm 3f_2$$6f_1, 6f_23, 33; 30, 36 7th4f_1 \pm 3f_2, 3f_1 \pm 4f_2$$7f_1, 7f_2$2, 9, 38, 39; 35, 42
...and you get the point