# Total Harmonic Distortion of a square wave

Total Harmonic Distortion (THD) is one metric for indicating the linearity of a system.

THD is defined as the ratio of the RMS voltage of the (noise + distortion) to the RMS voltage of the (signal + noise + distortion).

Though defined in terms of RMS voltages, many Distortion Analysers use rectifier / average responding meters. Though these meters may be calibrated in RMS, that calibration only holds true for waveforms with the same form factor (RMS/Average ratio) as a sine wave.

This article analyses a square wave, and the THD that would be indicated by a RMS responding measurement and an average responding measurement.

To measure the THD, the total signal is measured, and then a measurement is made of the total signal with the fundamental frequency filtered out with a very sharp, very deep notch filter. Figure 1 shows the waveform after the fundamental has been filtered out.

The Fourier series for a square wave is given by $$f(x)= \frac{4}{\pi}\sum_{n}\frac{sin(n-x)}{n}$$ for n=1,3..∞.

A simple form of AC voltmeter circuit is a rectifier, a resistor and a d'Arsonval (moving coil) microammeter. The moving coil meter deflection (or response) is proportional to the average current flowing through the meter coil, so in this case it is proportional to average of the rectified AC signal.

Figure 2 shows some functions that are important to analysing and understanding the response of the instruments. The response can be predicted by considering the time varying  waveforms over the interval of 0 to π/2 radians at the fundamental frequency, due to symmetry of both the rectified and squared waveforms.

The blue line in Figure 2 shows a unit amplitude square wave signal, the "total" signal". Its average and its RMS value are both 1.

The green line in Figure 2 shows the instantaneous voltage of a unit amplitude square wave signal less its fundamental component after rectification. An average responding rectifier AC voltmeter responds proportionately to the area under the green curve.

The red line in Figure 2 shows the square of the instantaneous voltage of a unit amplitude square wave signal less its fundamental component, and is proportional to the instantaneous power of the unit amplitude square wave signal less its fundamental component. The average power is proportional to the area under the red curve, and a RMS responding voltmeter will respond to the square root of the area under the curve. (Note that although the area under the red curve is less than the area under the green curve, the square root of the area under the red curve is greater than the area under the green curve, and so the RMS voltage will be higher than the average rectified voltage.)

Table 1 shows the method of calculation of the response and the response of an ideal instrument of each type to an ideal square wave.

 Measurement method Calculation Indicated THD (%) Indicated THD (dB) Rectifier / average responding meter $$\frac{\int_{0}^{\frac{\pi}{2}} \left | 1-\frac4{\pi} sin(x) \right | dx}{\frac{\pi}{2}}$$ 34.3% -9.29dB True RMS responding meter $$\sqrt {\frac{\int_{0}^{\frac{\pi}{2}} ( 1-\frac4{\pi} sin(x))^2 dx}{\frac{\pi}{2}}}$$ 43.5% -7.23dB

If you measure a good square wave with a properly calibrated broadband distortion analyser or SINAD meter, the result will indicate whether it uses an rectifier / average responding meter, or a true RMS responding meter (which is ideal).

Practical SINAD meters have limited bandwidth, but have a flat response over most of the frequency range of interest. The limited bandwidth may result in SINAD readings on a square wave a couple of dB lower than true broadband response.

Some instruments may have optional psophometric weighting of the response. Fig 3 shows two commonly used psophometric weighting curves, so the use of such a filter will improve the SINAD of a square wave by several decibels over the broadband response.

# Changes

 Version Date Description 1.01 20/10/2005 Initial. 1.02 25/08/2007 Errors in columns 3 and 4 of Table 1 rectified. 1.03 30/08/2008 Added Fig 3. 1.04 11/10/2008 Errors in columns2, 3 and 4 of Table 1 rectified. 1.05 06/03/2021 Mathjax.

18/02/09 13:57:04 -0700