I am a C programmer working on an embedded application and I am looking into finding a less processor intensive algorithm for calculating the Total Harmonic Distortion than using an FFT. In my search, however, almost every calculation involves looking at each of the harmonics. Is there any way to subtract out the fundamental RMS value and get the THD from there? I have the RMS value of the fundamental already and was just wondering if I could use that in someway to get the THD. Thanks for any input even if it is just, "tough luck."
THD without using an FFT
Started by ●July 11, 2010
Reply by ●July 11, 20102010-07-11
holychicken wrote:> I am a C programmer working on an embedded application and I am looking > into finding a less processor intensive algorithm for calculating the Total > Harmonic Distortion than using an FFT. > > In my search, however, almost every calculation involves looking at each of > the harmonics. Is there any way to subtract out the fundamental RMS value > and get the THD from there? I have the RMS value of the fundamental > already and was just wondering if I could use that in someway to get the > THD. > > Thanks for any input even if it is just, "tough luck."If you subtract fundamental frequency from the signal, you will get a mix of (THD + noise + non-harmonic components + nonstationarity + numeric artifacts). The result may or may not be acceptable depending on your application. What THD numbers are you after? Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●July 11, 20102010-07-11
On 7/11/2010 5:30 PM, holychicken wrote:> I am a C programmer working on an embedded application and I am looking > into finding a less processor intensive algorithm for calculating the Total > Harmonic Distortion than using an FFT. > > In my search, however, almost every calculation involves looking at each of > the harmonics. Is there any way to subtract out the fundamental RMS value > and get the THD from there? I have the RMS value of the fundamental > already and was just wondering if I could use that in someway to get the > THD. > > Thanks for any input even if it is just, "tough luck."THD of what? My first distortion analyzer was a Heathkit that, if I remember correctly, generated quite pure sine waves at a few frequencies (Wien bridge) and provided notch filters at those frequencies (twin T). The filters were adjusted for null with a distortion-free system (a.k.a wire) in place, then readings were taken with an actual system. It gave useful results that correlated well with my other distortion analyzer (also Heathkit) that measured IM at two frequency pairs. Subtracting out the fundamental instead of using a notch filter isn't necessarily simple in practice. You need to account for very small variations of gain during the test. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●July 12, 20102010-07-12
Thanks for the responses. The application is to give our customers a heads up to make sure that their customers are meeting the IEEE 519 spec. It is just meant to give them a warning of where they should go off and take a more accurate reading. I will definitely look into the suggestions you two gave and thanks again.
Reply by ●July 12, 20102010-07-12
On 07/11/2010 02:59 PM, Jerry Avins wrote:> On 7/11/2010 5:30 PM, holychicken wrote: >> I am a C programmer working on an embedded application and I am looking >> into finding a less processor intensive algorithm for calculating the >> Total >> Harmonic Distortion than using an FFT. >> >> In my search, however, almost every calculation involves looking at >> each of >> the harmonics. Is there any way to subtract out the fundamental RMS value >> and get the THD from there? I have the RMS value of the fundamental >> already and was just wondering if I could use that in someway to get the >> THD. >> >> Thanks for any input even if it is just, "tough luck." > > THD of what? My first distortion analyzer was a Heathkit that, if I > remember correctly, generated quite pure sine waves at a few frequencies > (Wien bridge) and provided notch filters at those frequencies (twin T). > The filters were adjusted for null with a distortion-free system (a.k.a > wire) in place, then readings were taken with an actual system. It gave > useful results that correlated well with my other distortion analyzer > (also Heathkit) that measured IM at two frequency pairs. > > Subtracting out the fundamental instead of using a notch filter isn't > necessarily simple in practice. You need to account for very small > variations of gain during the test.And possibly whopping big phase variations, too. By the time you make an amplifier that'll track the gain and phase change of the fundamental, you've done a lot more work than making a notch filter. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●July 12, 20102010-07-12
On 07/11/2010 02:51 PM, Vladimir Vassilevsky wrote:> > > holychicken wrote: > >> I am a C programmer working on an embedded application and I am looking >> into finding a less processor intensive algorithm for calculating the >> Total >> Harmonic Distortion than using an FFT. >> >> In my search, however, almost every calculation involves looking at >> each of >> the harmonics. Is there any way to subtract out the fundamental RMS value >> and get the THD from there? I have the RMS value of the fundamental >> already and was just wondering if I could use that in someway to get the >> THD. >> >> Thanks for any input even if it is just, "tough luck." > > If you subtract fundamental frequency from the signal, you will get a > mix of (THD + noise + non-harmonic components + nonstationarity + > numeric artifacts). The result may or may not be acceptable depending on > your application. What THD numbers are you after?Assuming that you're doing a "run a sine through the system & look at the results" sort of test, you could average one cycle of the output over a number of repetitions -- that would pound down both noise and non-harmonic components, although it wouldn't do anything with noise. Then you could subtract out the best-fit fundamental sine for an "answer". -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●July 12, 20102010-07-12
On 7/12/2010 11:10 AM, Tim Wescott wrote:> On 07/11/2010 02:51 PM, Vladimir Vassilevsky wrote: >> >> >> holychicken wrote: >> >>> I am a C programmer working on an embedded application and I am looking >>> into finding a less processor intensive algorithm for calculating the >>> Total >>> Harmonic Distortion than using an FFT. >>> >>> In my search, however, almost every calculation involves looking at >>> each of >>> the harmonics. Is there any way to subtract out the fundamental RMS >>> value >>> and get the THD from there? I have the RMS value of the fundamental >>> already and was just wondering if I could use that in someway to get the >>> THD. >>> >>> Thanks for any input even if it is just, "tough luck." >> >> If you subtract fundamental frequency from the signal, you will get a >> mix of (THD + noise + non-harmonic components + nonstationarity + >> numeric artifacts). The result may or may not be acceptable depending on >> your application. What THD numbers are you after? > > Assuming that you're doing a "run a sine through the system & look at > the results" sort of test, you could average one cycle of the output > over a number of repetitions -- that would pound down both noise and > non-harmonic components, although it wouldn't do anything with noise. > Then you could subtract out the best-fit fundamental sine for an "answer".It boils down to "What do you really want to know" and "What information will you settle for instead." Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●July 12, 20102010-07-12
On 07/12/2010 08:27 AM, Jerry Avins wrote:> On 7/12/2010 11:10 AM, Tim Wescott wrote: >> On 07/11/2010 02:51 PM, Vladimir Vassilevsky wrote: >>> >>> >>> holychicken wrote: >>> >>>> I am a C programmer working on an embedded application and I am looking >>>> into finding a less processor intensive algorithm for calculating the >>>> Total >>>> Harmonic Distortion than using an FFT. >>>> >>>> In my search, however, almost every calculation involves looking at >>>> each of >>>> the harmonics. Is there any way to subtract out the fundamental RMS >>>> value >>>> and get the THD from there? I have the RMS value of the fundamental >>>> already and was just wondering if I could use that in someway to get >>>> the >>>> THD. >>>> >>>> Thanks for any input even if it is just, "tough luck." >>> >>> If you subtract fundamental frequency from the signal, you will get a >>> mix of (THD + noise + non-harmonic components + nonstationarity + >>> numeric artifacts). The result may or may not be acceptable depending on >>> your application. What THD numbers are you after? >> >> Assuming that you're doing a "run a sine through the system & look at >> the results" sort of test, you could average one cycle of the output >> over a number of repetitions -- that would pound down both noise and >> non-harmonic components, although it wouldn't do anything with noise. >> Then you could subtract out the best-fit fundamental sine for an >> "answer". > > It boils down to "What do you really want to know" and "What information > will you settle for instead."It does indeed, and so often and for so many different fields of endeavor. I _really_ like that wording. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●July 12, 20102010-07-12
On 7/12/2010 11:50 AM, Tim Wescott wrote:> On 07/12/2010 08:27 AM, Jerry Avins wrote:...>> It boils down to "What do you really want to know" and "What information >> will you settle for instead." > > It does indeed, and so often and for so many different fields of > endeavor. I _really_ like that wording.A close cousin is "What do you really want to do and what action will you settle for instead." Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●July 12, 20102010-07-12
Well, what I want is an exact measurement of the THD of both voltage and current wave forms that takes absolutely no time, no memory, no extra code and no time to develop. ;) What I will settle for is a time efficient algorithm (that doesn't require a ridiculous amount of RAM) that gives a rough estimate of the THD (+/- 10%) of a given waveform. I currently store the raw waves and calculate a number of things, the only really relevant I believe is the RMS, including the I and Q, value of the fundamental of the waves. If the FFT is the best way to do this, I will go ahead with it, but I am no DSP expert and it just seems to me that there would be a simpler, faster way to get a rough estimate, so I was hunting around hoping to find something. Again, thanks for all the input, definitely giving me things to think about.






