Re: Square Wave
Usually, THD is the ratio of the noise to the signal. For example, this is somewhat like the THD used for specifying the performance of audio equipment.
So if you want your signal to be a square wave, the THD is zero, because you have a square wave.
But if you are looking for a pure 60Hz sine wave, then THD would be defined as the ratio of the amplitude of all the noise to the amplitude of the 60 Hz sine wave. This is probably what you want. (I will assume we are talking about a voltage signal, and not power).
A perfect square wave is made up of an infinite number of sine waves, all odd multiplies of the fundamental. In your case, the fundamental sine wave is 60Hz, and it has a peak amplitude of 1 volt. The other frequencies are;
180 HZ at 1/3 volt
300 Hz at 1/5 volt
420 Hz at 1/7 volt
540 Hz at 1/9 volt
660 Hz at 1/11 volt
and on and on forever, with each one getting a smaller amplitude. (The nth term is n*60Hz in freq, and 1/n in amplitude.)
The RMS value of the square wave is actually 1. I'll leave the proof to Rattus, but basically you should have divided by 2 before taking the square root. Notice that the RMS value can't be larger than the peak value of the square wave.
So to get THD, we use the RMS value of our 60Hz wave, (which is a sine wave with a peak of 1v) to get .707. Subtract this from the total RMS of 1 to get a noise RMS value of 0.293. So I think the total THD is 0.293/.707 = 0.414 or 41.4% THD.
I'm not 100% sure of that answer. Maybe THD is sometimes defined as the noise over the total signal, which would be 29.3%.
Steve