Testing Audio with THD

When you turn your radio up realy loud, why does it sound so bad? Because you are clipping the signal, causing harmonics. Below are two signals viewed in two different ways. In this first picture you can see a nice clean sine wave.


This is a pure sine tone with no harmonics or noise.


The next picture shows a signal of exactly the same frequency, but the waveform has been clipped (in RED). You can clearly see that the top and bottom of the waveform has been removed, which is exactly what happens when you turn a radio up too loud. The plot also shows the original, non-clipped wave in GREEN for comparison so you can easily see the clipping. 


You can clearly hear the difference. The second tone appears louder, but that is because it is full of nasty harmonics that would ruin the sound if this were music. The problem is that you cannot hire people to sit around and listen to tones all day long to accept or reject good or bad audio chips. They used to do that in the old days, but people have differing ideas about quality and it's way too expensive which raises the cost of audio components making the final product too expensive. The secret to increasing the quality and reducing the cost of consumer goods is to find ways to manufacture and test them as fast as possible without using humans in the process.

The other way to test audio quality is to measure Total Harmonic Distortion, otherwise known as THD. To do this we would create a tone and send it into the chip and then look at the output to see what the chip did to it. Did it amplify it (increase the volume) or did it clip it? Whenever a sine wave signal clips, harmonics are created. Clipping just one side creates both odd and even harmonics, if both the top and the bottom are clipped you get only odd harmonics, so we can't just look at one harmonic or another, we have to look for many harmonics to ascertain signal quality. If only we could analyze the signal and add up all the harmonic energy we could tell if this is a good signal or a bad signal, which would tell us if the audio chip is a good chip or if it should be thrown away. But how do we find the harmonics?

We use a Fast Fourier Transform, or FFT to convert the signal into a spectrum, the same way a prism creates a rainbow out of white light. The FFT will split the signal into its individual frequencies just like a prism splits white light into its individual colors and then we will be able to see all the signal's harmonics. On this next picture, you can see the spectrum of the first, unclipped signal. Notice that you can see the signal (the big, tall spike on the left) and the rest of the spectrum is very clean. There are just a couple of harmonics but they are very small, all below 100 dB. 



If we add up all the harmonics and calculate the average (actually we use a formula called Quadratic Mean) and then compare it against the amplitude of the signal at 330 Hz we will see that the this waveform has very good Total Harmonic Distortion (THD), so it sounds really good. On the right side of the picture you can see the THD of the clean signal (circled in RED) at -99.74 dB. Because this signal has very low harmonic energy, its THD is much lower which indicates a very high quality signal, hence a good part. So now we can put it into a consumer product and the consumer will like it, write good reviews about it, pay a higher price for it, etc.

Now for the spectrum of the clipped signal. Look at all those nasty harmonics! They really screw up the signal, and notice the THD number over on the right side of the plot, THD now reads -28.53 dB, really horrible, which is the way it sounds. The energy of all the harmonics is very large compared to the pure tone at 330 Hz. If you put a chip like this into a consumer part, almost no one would buy it. Anyone who tried it would write up a nasty review and throw it away, you wouldn't make any money on it because people expect CD quality out of everything now, and -28 dB THD is more like AM radio quality which is pretty much not used for music anymore because music sounds pretty bad at this level of THD. 



This is why stereo systems use THD as a measurement of quality, few harmonics, low THD equals a good chip, many harmonics, high THD equals bad chip, so toss it. THD tells us how good the audio system is and we now have a simple way to find out how good or how bad the quality is. 


THD has three problems:

  1. THD relies on a non-linear waveform, a sine wave, to test linearity.
  2. Sine waves don't cover every code in a device's transfer function.
  3. It is assumed that harmonics roll off from lower to higher harmonics.

Problem number 1 is huge, non-linearities near the top or bottom of the transfer function have greater weighting due to the nature of a sine wave.

Problem number 2 is even worse, if you test a 16 bit DAC or ADC with a 64K point sine wave, less than 20,000 points are actually hit, leaving a lot of non-linearities undiscovered and unknown.

And problem number 3 (as seen below) is pretty serious. Depending on where in the transfer function the non-linearity is, the harmonics may not roll off as every engineer has been told. If you look at just the first few harmonics, you may miss a serious non-linearity and ship products that suck!




We recommend the book from Dan P. Bullard   Distortion: The Cause Of Harmonics And The Lie Of THD available at Amazon.