Published on August 17, 2019
Copyright © Dan P. Bullard
In a previous article, I posited an interesting option for the standard THD test, which suffers severely from underestimating some kinds of distortion by assuming (making an ass out of U and ME) that all harmonics drop off in amplitude after the first five, or nine, or whatever. As I mentioned, this assumption destroyed one tester line because the apps engineer believed the SNR/THD function which reported back that what he was seeing was noise, when in fact it was harmonic distortion caused by a serious timing error in the digital subsystem. If only the SNR/THD function could adapt to the situation and call a spade a spade, that is, be able to differentiate between harmonics and noise. It could really help us out, and here's how.
Above you can see the spectrum of a very nasty glitch in a sine wave, and because it was a real distortion of the transfer function, it replicates on the way up and the way down like this:
And because it replicates, the glitch is symmetrical around 90 degrees which guarantees that it will obey Bullard Laws of Harmonics #5. And because it only impacts the positive side, it's considered asymmetrical, which means that it will have plenty of Even harmonics, in addition to the ever present Odd harmonics. This glitch is not that dissimilar to the kind of distortion that I mentioned before that destroyed a whole tester line. The problem was that we were using a function that assumes that the first 9 harmonics, the fundamental and 8 harmonics after that are worthy of being considered as part of the Total Harmonic Distortion number, everything else is to be considered noise. Let's see how my new method of doing a THD test compares to the standard, inflexible way of measuring THD:
If we assume that the first 9 harmonics are truly distortion related harmonics, we underestimate the harmonic distortion by 6dB. But also, everything after that is considered noise, which goes into the SNR number which reports back an SNR of 19.158dB which is really, really bad. If we assume 51 harmonics (the fundamental plus everything from the 2nd to the 51st, 25 Odd and 25 Even harmonics), we get a slightly more accurate value, -18.4dB, but if we use the adaptive method, we are only going to gain another 0.5dB. In fact, in this case, nearly everything in the spectrum is a harmonic, and I ignore anything below -100dB, so these numbers are being kind to the Device Under Test (DUT). You may have noticed the "1" in the top of the Dan's THD column, that is the spread in degrees that I give myself. So I factor in every amplitude above -100dB that has a phase angle of 0 +/-1 degree, 90 +/-1 degree, 180 +/-1 degree and 270 +/-1 degree. Anything that doesn't meet those criteria is considered noise and is added up for the SNR value, and since this test has no noise, that's pretty good. Some harmonics do get incorporated into the SNR just because they are too small to be of interest to us for THD purposes, that is, below -100dB.
Now, what happens if I add -66dB of noise to the signal, as you might expect in a real world environment? It doesn't change the look of the wave much, as you can see:
And it doesn't change the spectrum much either in a perceptible way.
But it really changes the numbers for my technique;
Notice that the my THD number hardly changed, from -17.889dB to -17.895dB, and the SNR using the traditional method didn't change much either, from 19.1657849B to 19.1578519dB. But my SNR number changed quite a bit, from 96.49dB to 44.225dB. Why is that? Well, I added quite a bit of noise, again -66dB, and that changed the phases of quite a few of the lower level harmonics, dragging their phases off the expected 0, 90, 180 and 270 degree value. Because of that, quite a few harmonics are now considered noise. Remember that I can arbitrarily change the spread of the window for what I consider harmonics? Let's do that, this time I will give the algorithm a spread of 2 degrees instead of 1 degree.
By altering the window of the phases of harmonics, my THD numbers hardly changed, -17.8864dB vs -17.8947dB, but the SNR changed about 7.5dB, closer to the real value, so it probably is not a bad idea to make the window for harmonics a little wider, but for now I will keep it at 1 degree on either side of the expected phase angles for harmonics of (need I say it again?) 0, 90, 180 or 270 degrees.
Now, why do we have this idiotic idea that harmonics always drop off so that only the first 5, or 9, or whatever harmonics are valuable to THD? Because for the most part, scientists studied the easiest type of distortion to create, peak clipping. Here is an example where I clip the top off a sine wave and use my new technique to measure the THD and SNR.
Again, this has the same amount of noise as the last wave, and you really can't see it in Time Domain, nor in Frequency Domain.
But you can get an idea why they decided that harmonics just harmlessly roll off as frequency goes up. Now, how does my new algorithm handle this kind of distortion?
Notice that no matter whether you look at the first 9 harmonics, or the first 51 harmonics, or the harmonics that exhibit a 0, 90, 180 or 270 degree phase, you get pretty much the same answer. So using 9 harmonics is a good bet, if your only distortion is peak clipping, but if it's anything else, you are seriously underestimating THD and your SNR number is seriously compromised. Notice that my SNR number is only 9dB away from the real answer of 66dB, and that is because some of the lower amplitude harmonics are being mistaken for noise because they pulled the phase number away from the expected values of 0, 90, 180 or 270 degrees. Opening up the phase variance should show us better numbers for SNR but not change the THD numbers much if any.
So I gained almost 3dB in the SNR value, getting it closer to the expected value of 66dB, but hardly impacting the THD number, taking it from -32.1dB to -32.095dB. So really, a 2 degree window is probably the best way to go in the real world. It only slightly underestimates the THD, but seriously improves the SNR value, and even in this case makes the SNR much closer to the real value than the old way of assuming that everything after the 9th harmonic is noise.
I hate to tell you that I told you so, as in my previous article I proposed giving the phase 2 degrees of slop, and as it turns out after a little bit of research, that's really the best way to go! This technique will never have you searching for a noise problem when you really have just a harmonics problem, meaning that you had better be looking for something that is causing distortion, not bleeding noise in from some mysterious source.