00:38 +0000, Scott Ronald wrote:
Hi
I was wondering if anyone knows of an efficient way to calculate the
THD of a 60Hz sine wave using a basic microcontroller. I was hoping
there is a way to do this without using a full FFT. Is this
possible?
Scott
Yes, it is.
Calculate the total energy in the signal.
Then find the best-fit 60Hz sine wave in the signal (take John Larkin's
suggestion and do a DFT, or use the overly-hyped Goertzel algorithm).
Find its energy.
Subtract the two -- that's your harmonic energy + noise.
--
Tim Wescott
Control systems and communications
consultinghttp://
www.wescottdesign.com
Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes,
http://www.wescottdesign.com/actfes/actfes.html
I see what you are doing, and it sounds simpler than my suggestion, but
if the THD isn't really crappy, this kind of subtraction could mix
rounding noise due to the finite bitsize, i.e. add quantization noise
that really is not part of the THD.
What I was thinking about was to unwrap the signal with an arcsin, which
produces a straight line. [Essentially phase accumulation.] Then LMS
that data. The intercept and slope should allow an optimal sine wave to
be created for the subtraction purpose.
However, the more I think about this, some sort of sampling scheme phase
locked to the 60Hz signal could be more productive. Once the sampling is
synchronous, you can notch the fundamental.
_I_ suspect that anything either of us could cook up would be subject to
quantization noise, so a designer would want to carefully check for that,
and cope with it.
--
Tim Wescott
Control systems and communications consultinghttp://
www.wescottdesign.com
Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes,
http://www.wescottdesign.com/actfes/actfes.html