Phase shifted Cosine wave with distortion

# Achieving Perfection

Published on August 31, 2019

In my latest set of articles I told you how you could greatly improve your SNR and THD measurements by avoiding the ASS U ME method, where you make an ass out of U and me by assuming that only the first 4 or 6 or 8 or 9 harmonic candidates are harmonics and the rest are noise. Harmonics carry a very specific signature, they are phase-related to the fundamental, since they are created by the fundamental interacting with a distortion. And like a ball in a gravity field, anything that goes up, must come down, and so the speed of the ball on the way up 10 feet from the peak height will be the same speed at the same point when it comes down. Harmonics obey the law. Absolutely guaranteed. And so the harmonics follow the Bullard Laws of Harmonics #5:

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

And Daver's Law which is an extrapolation of my law:

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

The second law is easier to use in many cases, if, and that seems like a big if, you can coax the wave you capture into being a cosine wave, a PERFECT cosine wave, because this will work pretty well for a while if the wave is not exactly a cosine wave. But then the phases of the harmonics will start to shift as you go up in frequency. For example, if the wave is 1 degree off from a cosine wave, then the 2nd harmonic phases will be off by 2 degrees, the third harmonic will be off by 3 degrees, the fourth harmonic will be off by 4 degrees, and so on. Whatever shall we do?

In those previous articles I told you how you could take the wave you capture, do an FFT on it, extract the phase from the fundamental (which is the biggest, most powerful signal in the wave usually) and use that to shift the wave to the right or left to get it close to being a perfect cosine wave, so you could test to see if a signal is a harmonic (and not noise) by checking the phase. But as my friend and co-mentor David Reynolds, discoverer of Daver's Law said to me, even if you take a lot of samples, you can't capture a perfect cosine wave, you cannot align the capture that closely, no matter how good your capture system is. And he's right, we have both worked on systems in the past with very sophisticated trigger systems for picking the exact right moment to start a capture, but the signal always carries some noise, and even if you take a million samples, you are always at least a half a millionth sample off, no way to fix that except take two million samples, now you are off by a half of a two millionth sample. But you don't have to do that, I found the mathematical key to perfection, and it's so simple it will startle you.

In this snapshot of my Excel code I show how I achieved perfection. I captured the wave at the top of this article with a very large phase offset. I shifted the wave to get as close to a perfect cosine wave as I could. But then I did a mean thing: I shifted the entire wave one sample to the right, one out of 2048, which puts it at 1/2048*360 or -0.17578125 degrees, as you see in the red highlighted cell in column T above. Then I worked on correcting for that offset by devising the formula in column U named Modified Angle. You can see the formula I arrived at and if you look down column T you can see how I arrived at that formula. As the frequency goes up, the harmonics drift further and further away from the 0 and 180 degree phase shift expected for a cosine wave, because the harmonics have shorter periods; 0.17578125 degrees in the fundamental means 0.3515625 degrees for the second harmonic, and means 0.52734375 degrees for the third harmonic and so on. Eventually we are 1, 2, 3, 4 and more degrees away from the values predicted by Daver's Law. But by doing this little bit of math, we can predict, and then correct for it with that simple formula. Now look down column U, Modified Angle. Every value is either 0 or 180 degrees, because this wave has no noise. Now you might say "But Dan, that's because you used the Round function in your formula!" That's true, I round to milli-degrees, because I was getting tired of seeing 1.78543E-13 degrees in that column. The 180 values always display 180, but the zeros come back at some ridiculously small value away from zero in the trillionths of a degree. That is why I round it, not because I don't trust my formula. Another thing that tells you I nailed it, look at the Dan's SNR value in column Y. 200dB. Do you know why it's 200dB? Because I had to hard code it to 200 if every value in column Y is zero to avoid a #DIV/0! error. Why is that? Because this method works so good that I changed my criteria for looking at the phase. If the amplitude of the signal in any given bin is smaller than -150dB, then I set the phase to a non-useful value. But since every bin here is a harmonic (as there is no noise) and there are plenty of harmonics thanks to this distortion, the SNR column ended up filled with zeros. That resulted in a divide by zero error when I calculated SNR, and we can't have that! So this method once again proves Bullard Laws of Harmonics and Daver's Law, as in this wave not one single harmonic, not one out of 1023, ever gave me a value other than 0 or 180 degrees. And I can throw any distorted wave I want at it, it will do the same thing in every case! These two laws are absolute. In fact, a former coworker I was having lunch with was astounded by my statement. "Every single one?" Yep, every single harmonic will be either 0 or 180 degrees from the fundamental if you look at a cosine wave, and 0, 90, 180 or 270 if you look at it as a sine wave. Well, since we can shift any wave to be a cosine wave, why look for four angles when you can look for just two?

Just more proof of the utility of Bullard Laws of Harmonics. Who knows what I could discover with these laws next? Who knows what you could discover, what problem you could solve, what algorithm you could invent based on these laws. The world has gotten bigger, we now know more about the world thanks to my work on harmonics. This could be your ticket, you could do great things, because this knowledge is very limited now, almost nobody knows about these laws. Just because analog seems like an old technology, don't forget that rocket fins vibrate with harmonics, wings vibrate with harmonics, MEMS sensor beams vibrate with harmonics. Do you really want to miss out on the next groundbreaking discovery because you refuse to learn something new?