# Total Harmonic Distortion (THD)

## What do you need to know to understand this topic?

## What is Total Harmonic Distortion (THD)?

Total Harmonic Distortion measures how much of a waveform power is distortion caused by harmonics. If the fundamental frequency of the signal is $f_1$ with power $P_1$, and the harmonics $i$ are at $f_i$ with power $P_i$, the THD is:
$$ THD = \frac{\sum_{i>1} P_i}{P_1} = \frac{P_{total} - P_1}{P_1}$$
where $P_{total}$ is the total power of the waveform (signal + harmonics). In other words, the **Total Harmonic Distortion is the ratio of the power of all the harmonics with the power in the fundamental frequency.**.

The THD measures the nonlinearity of a system, while applying a single sinusoidal to it. The sinusoidal, when applied to a nonlinear system, will produce an output with the same fundamental frequency as of the sinusoidal input, but will also generate harmonics at multiples of the fundamental frequency. To understand why that happens, check the harmonics topic.

Squared RMS voltages are equivalent to power and can replace it in the THD equation:
$$ THD = \frac{\sum_{i>1} V_i^2}{V_1^2} = \frac{V_{total}^2 - V_1^2}{V_1^2}$$
However, **in some situations THD is defined as an amplitude ratio**, instead of a power ratio:
$$ THD_{amp} = \frac{\sqrt{\sum_{i>1} V_i^2}}{V_1} = \frac{\sqrt{V_{total}^2 - V_1^2}}{V_1} = \sqrt{THD} $$
which leads to a value that is the square root of the other definition.

### How to measure the THD?

The THD can be measured in the following way: from a set of samples of the waveform, compute the Fourier transform to get the frequency spectrum. From there, sum the harmonics power and divide by the power in the fundamental frequency.

## What is Total Harmonic Distortion + Noise (THD+N)?

THD+N is just the THD accounting with noise, i.e.:
$$\begin{equation}THD+N = \frac{\sum_{i>1} P_i + P_{noise}}{P_1} = \frac{P_{total} - P_1}{P_1} \label{eq:thdn}\end{equation}$$
where $P_{total}$ now includes the noise power.

### How to measure the THD+N

With a notch filter (band-reject), remove the band where the fundamental frequency lies. The remaining power will be the harmonics and noise. Now subtract the remaining signal from the original signal, leaving only the power in the fundamental frequency (or use a pass-band filter to remove all bands except where the fundamental frequency lies) and from there you get $P_1$.
Another option is to measure the total power $P_{total}$ and use again the pass-band filter to extract $P_1$. Then you can use the second form of $\eqref{eq:thdn}$.