Bullard plot of a peak clipped cosine wave

It Gets Even Better

Published on August 21, 2019

Copyright © Dan P. Bullard

I've been astonished at what I have discovered in the realm of harmonic distortion. Some discoveries take months, some take days, and some are done alone and some need the help of a friend. My latest epiphany came when I was trying reconcile what my friend David Reynolds (daver@metrocast.net) was telling me about my latest law of harmonics. He was right, I was just looking at things the wrong way, and he helped me make Law #5 even simpler!

Daver as I call him is the name he told me years ago when we were introduced. He used it because that was his email moniker, DaveR@somesuchdomain.com, a company acquired by Credence that we both worked at back in the 1990s. Daver is smart, I mean, really smart! I once talked him into taking an IQ test and he scored 10 points above me at 145. That gives him 30 IQ points on the average college graduate and it shows. He has written some amazing code, solved some incredibly difficult problems and helped me in my endeavors mostly be being a good person to bounce ideas off. So when I told him about my newest law of harmonics, he was skeptical, and so he looked into it.

While I said that:

The harmonics of a distorted wave will always start at 0, 90, 180 or 270 degrees relative to the fundamental, no exceptions.

Daver disagreed. He tried several waves that didn't obey the law. He got all kinds of angles from the harmonics depending on what he did. As I show in this article, if you botch the distortion and don't implement it as a real transfer function anomaly, you can get any phase you want, and that is what I assumed Daver was doing. Stupid of me to assume that Daver screwed up though, because he never screws up. He was making the point to me that the kind of wave you start with is the most important thing. Law #5 is valid, but only if you add a single word to it.

The harmonics of a distorted sine wave will always start at 0, 90, 180 or 270 degrees relative to the fundamental, no exceptions.

Law #5 only applies to sine waves, nothing else. But Daver discovered something even more useful: I guess we should call it Daver's Law:

The harmonics of a distorted cosine wave will always start at 0 or 180 degrees relative to the fundamental, no exceptions.

Take a look at the wave I showed you above:

A cosine wave with the peak clipped off. I have shown you this wave before, but as a sine wave. Look at the phases of all the harmonics. The lower harmonics all start at the negative peak, meaning that they have a 180 degree phase shift relative to the fundamental, the blue cosine wave at the top of the plot. However, some of the higher harmonics (lower in the diagram) start with a phase shift of zero relative to the fundamental. Those are the only two phases you will find here, 0 and 180 relative to a cosine. See what Daver was saying? Shift this whole wave 90 degrees to the right and it obeys Bullard Laws of Harmonics #5, and then you have to deal with four harmonic phases. Shift it back 90 degrees to the left and you only have to deal with two harmonics phases, 0 and 180. Let's look at another distortion, a zero crossing.

Notice how well this plot shows the harmonics lining up to help push the distortions into the otherwise pristine cosine wave. Now, look to the left, what are the phases? Yep, they either start at the positive peak or the negative peak, nothing else. 0 degrees or 180 relative to a cosine wave. Shift the whole wave 90 degrees to the right and it will obey Bullard Laws of Harmonics #5, but now you have to deal with four phases instead of just two. And shift it either way by 45 degrees, now you have to deal with 8 phases, yikes! Who wants that? Shift it some random amount and there is no telling what you are going to have to deal with. This is what happens when you capture a wave willy-nilly from the real world with no phase alignment, like what happens with most oscilloscopes and other waveform capturing devices. So is this useful piece of information just a waste of limited brain space? Not at all, because as Daver and I have shown in the past, you don't have to be satisfied with the waveform you capture from the world, you can modify it to suit your needs. In this video, I show you a trick that Daver and I (and Matt Mahoney) devised to reorder a wave from multiple cycles to a single cycle. Who's to say you can't do something like that to any other waveform, transforming a randomly captured wave into a cosine wave so you can do a THD or SNR test like I suggested in a previous article.

I did this in Excel to show that it still had the same validity. I do an FFT on the wave in question with a random phase. Then I look only at the phase of the fundamental, nothing else. Then I set up a wave shifting algorithm to change the wave into a cosine wave. In Excel I used the Index() function, but in C you would probably use a couple of arrays. (Ask Daver, he could help you do it.) The advantage of looking at the phase of the fundamental is that while the captured signal is distorted and noisy, the fundamental is pure; remember, all the distortion is in the harmonics, and the noise is scattered across the spectrum that your FFT created, there is no noise in the individual bins (well, there is, but it's just seen as a small change in amplitude) so extracting the phase from the fundamental is the best way to know what the phase of the wave overall is, and remember once again, both of these laws say the phases of the harmonics are relative to the fundamental, not the overall distorted wave.

Now that the wave is shifted one way or another to be a cosine wave, do an FFT on it, extract the phases of all the bins of the spectrum, and look for anything that has a phase of 0, or 180, or -180. Because we are dealing with complex math, you sometimes get negative phases, Daver could probably tell you why, but what is -180 degrees? It's a 180 degree phase shift! So I just take the Abs() of the phase and ignore it. Then give yourself two or three degrees of slop like I said in the previous article, and anything that fits in that window is a harmonic, anything that doesn't is noise. So now we can capture a wave with any phase offset we find in the real world, shift it to be a cosine wave like this:

And then run the adaptive THD and SNR test on it, getting results like this:

In the Traditional THD I added up the 2nd through the 9th harmonics and compared them to the amplitude of the fundamental. In the Traditional SNR test, I added up everything else and just assumed it was all noise, making an ASS out of U and ME as everybody who has ever measured SNR and THD in the past has done. But in the adaptive THD and SNR tests, I took anything that had a phase of 0 degrees or 180 degrees, plus or minus 2 degrees (that 2 you see in the Dan's THD column) and called that a harmonic. Now, I did eliminate anything that was below -100dB from being considered as a harmonic, because the phases get pretty noisy at that level, just from the mathematical noise induced by doing so many multiplies in the FFT, but you can do whatever you want with this technique, it's up to you. Notice the big difference between this approach and the one I advocated in my previous article: Instead of looking for 4 phases with a window of 5 degrees each (the phase in question and then two degrees on either side of it), 20 degrees total, the cosine approach only considers two phases, with a window of 5 degrees each, just 10 degrees total. That increases the odds, 36:1 vs 18:1 that I will not pick up some random noise spike as a harmonic.

See, it gets even better when you listen to Daver! We have a good time chatting about this stuff. He knows the math and I have a knack for playing with it and writing about it. I can only imagine how boring my career would have been without knowing Daver all these years. It's nice to surround yourself with a genius or two, it makes you look like a genius too, as long as you listen to him!