DSPRelated.com
Forums
Online · Live + on demand
February 9-11, 2027
Price goes up Nov 1: register now to lock in today's rate
Register Now →

Accurate Harmonic Analysis

Started by evilzucchini ●March 1, 2010
On 1 Mar, 23:17, "evilzucchini" <cbar...@digitalgridinc.com> wrote:
> Thanks for the responses. > > I don't think aliasing is a problem because our anti-aliasing filter's > cutoff is less than 2 times our sampling rate.
Eh... less than *two* times the sampling rate? Not less than *half* the sampling rate...? Rune
Rune Allnor wrote:
> On 1 Mar, 23:17, "evilzucchini" <cbar...@digitalgridinc.com> wrote: >> Thanks for the responses. >> >> I don't think aliasing is a problem because our anti-aliasing filter's >> cutoff is less than 2 times our sampling rate. > > Eh... less than *two* times the sampling rate? > Not less than *half* the sampling rate...?
That passed right over me! Jerry -- "I view the progress of science as ... the slow erosion of the tendency to dichotomize." --Barbara Smuts, U. Mich. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
>I am fairly new (or, more accurately, still very wet behind the ears) to >DSP. I have very little formal training and got thrust into the duties
of
>handling the embedded DSP programming for our project. So please forgive >me if I ask something that is very basic. . .and I believe it is kind of >basic. > >At first my duties were pretty simple: sampling some sine waves, >correlating them to determine magnitudes/angles/etc. I handle this fine >and well within the specs given to us by our customers. > >However, now our customers want more (big surprise). One of the requests >was to do a Total Harmonic Distortion analysis of the currents (we are >working in the power industry). I have no problem finding and >understanding the mathematics for determining the total harmonic >distortion, however, whenever I do it I get numbers that I believe to be >very high. I am seeing 11-20% THD on "perfectly" smooth sine waves that
I
>am generating. Perfect in the sense that I am adding in no harmonics and >they look very clean on an oscilloscope. I am using Exocortex 2D FFT >algorithm to generate the power of each harmonic on our sine wave. > >I suspect the problem is that I am not sampling perfectly in sync with
the
>60 Hz sine wave due to imperfections in the clock (like the rate I am >sampling at would not be exactly 128 samples per cycle, but more like >128.5) and that this is making it look like there is more distortion than >there is. I believe that if you are expecting to see 1 cycle in 128 >samples, but you are really only seeing .9 cycles per 128 samples, it may >appear that you have a lot of power in harmonics other than the
fundamental
>when, in the real world, it is actually a sine wave with very low >distortion. > >Would a slightly incorrect sampling rate give significantly incorrect >harmonic data? If so, how do you correct this? Is there a good
algorithm
>for "locking" onto a signal so that your sampling rate becomes more >perfect? Or am I just totally wrong and it is probably some other >problem? > >I did do a search trying to find the solution to this problem or at least >some guidance, but I am not exactly sure what it is called so I have been >unsuccessful trying to find a solution or even if I am barking up the
right
>tree. > >For reference, I am coding in C for a 16 bit Freescale 56f8367 Digital >Signal Controller and doing the FFT calculations in C# for .Net (after >downloading the raw sampled data from the ADC in our unit). > >Thank you, >Charlie
Why take a roundabout approach to finding the THD (finding all the harmonics with an FFT and summing them), rather than go straight for your goal? What about: - Phase lock a synthesised pure sine wave to your signal. - Tune the amplitude of your sine wave, so that original.pure == pure.pure Now, sqrt(original.original) is your harmonic polluted RMS value, and sqrt(pure.pure) is the fundamental RMS value. The difference is the harmonic content. Calculate those dot products in a leaky manner, and you can perform a continuous measurement, tuning the phase lock and amplitude as you go. Steve
steveu wrote:
>> I am fairly new (or, more accurately, still very wet behind the ears) to >> DSP. I have very little formal training and got thrust into the duties > of >> handling the embedded DSP programming for our project. So please forgive >> me if I ask something that is very basic. . .and I believe it is kind of >> basic. >> >> At first my duties were pretty simple: sampling some sine waves, >> correlating them to determine magnitudes/angles/etc. I handle this fine >> and well within the specs given to us by our customers. >> >> However, now our customers want more (big surprise). One of the requests >> was to do a Total Harmonic Distortion analysis of the currents (we are >> working in the power industry). I have no problem finding and >> understanding the mathematics for determining the total harmonic >> distortion, however, whenever I do it I get numbers that I believe to be >> very high. I am seeing 11-20% THD on "perfectly" smooth sine waves that > I >> am generating. Perfect in the sense that I am adding in no harmonics and >> they look very clean on an oscilloscope. I am using Exocortex 2D FFT >> algorithm to generate the power of each harmonic on our sine wave. >> >> I suspect the problem is that I am not sampling perfectly in sync with > the >> 60 Hz sine wave due to imperfections in the clock (like the rate I am >> sampling at would not be exactly 128 samples per cycle, but more like >> 128.5) and that this is making it look like there is more distortion than >> there is. I believe that if you are expecting to see 1 cycle in 128 >> samples, but you are really only seeing .9 cycles per 128 samples, it may >> appear that you have a lot of power in harmonics other than the > fundamental >> when, in the real world, it is actually a sine wave with very low >> distortion. >> >> Would a slightly incorrect sampling rate give significantly incorrect >> harmonic data? If so, how do you correct this? Is there a good > algorithm >> for "locking" onto a signal so that your sampling rate becomes more >> perfect? Or am I just totally wrong and it is probably some other >> problem? >> >> I did do a search trying to find the solution to this problem or at least >> some guidance, but I am not exactly sure what it is called so I have been >> unsuccessful trying to find a solution or even if I am barking up the > right >> tree. >> >> For reference, I am coding in C for a 16 bit Freescale 56f8367 Digital >> Signal Controller and doing the FFT calculations in C# for .Net (after >> downloading the raw sampled data from the ADC in our unit). >> >> Thank you, >> Charlie > > Why take a roundabout approach to finding the THD (finding all the > harmonics with an FFT and summing them), rather than go straight for your > goal? What about: > > - Phase lock a synthesised pure sine wave to your signal. > - Tune the amplitude of your sine wave, so that > original.pure == pure.pure > > Now, sqrt(original.original) is your harmonic polluted RMS value, and > sqrt(pure.pure) is the fundamental RMS value. The difference is the > harmonic content.
Is subtracting two possibly nearly-equal numbers a robust approach?
> Calculate those dot products in a leaky manner, and you can perform a > continuous measurement, tuning the phase lock and amplitude as you go.
Jerry -- "I view the progress of science as ... the slow erosion of the tendency to dichotomize." --Barbara Smuts, U. Mich. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;

steveu wrote:

> Why take a roundabout approach to finding the THD (finding all the > harmonics with an FFT and summing them), rather than go straight for your > goal? What about: > > - Phase lock a synthesised pure sine wave to your signal. > - Tune the amplitude of your sine wave, so that > original.pure == pure.pure
I wouldn't recommend this for beginners.
> Now, sqrt(original.original) is your harmonic polluted RMS value, and > sqrt(pure.pure) is the fundamental RMS value. The difference is the > harmonic content.
Not quite. The difference is THD + N + numeric artifacts.
> Calculate those dot products in a leaky manner, and you can perform a > continuous measurement, tuning the phase lock and amplitude as you go.
I've heard that some digital scopes adjust their sample rate so the period of fundamental falls exactly in the FFT bin. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com

Jerry Avins wrote:

> Vladimir Vassilevsky wrote:
>> BTW, just recently I had to measure ~0.0001% of THD. That's seismic >> data acqusition specmanship. HiFi nuts, you said ? :-) > > Can you discuss some of the subtleties involved? What kind of ADC is > linear enough to do that?
Interestingly, ADC is not the biggest part of a problem. There are ADCs with that kind of linearity. Also, filtering the fundamental out is the classic way for doing such measurements. The difficult part is generation of super clean sine. I had to use good DAC with analog post filtering. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
>On 1 Mar, 23:17, "evilzucchini" <cbar...@digitalgridinc.com> wrote: >> Thanks for the responses. >> >> I don't think aliasing is a problem because our anti-aliasing filter's >> cutoff is less than 2 times our sampling rate. > >Eh... less than *two* times the sampling rate? >Not less than *half* the sampling rate...? > >Rune
D'oh! Sorry, I meant half.
> > >steveu wrote: > >> Why take a roundabout approach to finding the THD (finding all the >> harmonics with an FFT and summing them), rather than go straight for
your
>> goal? What about: >> >> - Phase lock a synthesised pure sine wave to your signal. >> - Tune the amplitude of your sine wave, so that >> original.pure == pure.pure > >I wouldn't recommend this for beginners.
Because Matlab doesn't pre-package this strategy? :-)
>> Now, sqrt(original.original) is your harmonic polluted RMS value, and >> sqrt(pure.pure) is the fundamental RMS value. The difference is the >> harmonic content. > >Not quite. The difference is THD + N + numeric artifacts.
The numeric artefacts are fairly easy to keep under control. Noise can be an issue if you want this to work over a wide dynamic range. Picking out the exact harmonic frequencies, and ignoring all the noise in between, could be cleaner with small signals.
>> Calculate those dot products in a leaky manner, and you can perform a >> continuous measurement, tuning the phase lock and amplitude as you go. > >I've heard that some digital scopes adjust their sample rate so the >period of fundamental falls exactly in the FFT bin.
I don't know what scopes do, but if you want to do accurate mains power harmonic measurements by FFT you'd better be prepared to tune to the precise fundamental, and sit all the bins bang on the harmonics. I've done power analysis by having a table of Goertzel coeffs for the exact harmonic frequencies, for reasonably fine increments of fundamental between 47.5Hz and 52.5Hz. After doing a fundamental estimate I used the appropriate table entries to estimate the harmonics as individual elements, rather than an amorphous FFT bank. Its capable of very accurate and stable results, without too much computation. Something like the 20th to 40th harmonic is usually as far as people want to go, so you don't need to run more than 40 Goertzels. That suits an application looking for an accurate breakdown of the individual harmonics. Steve

steveu wrote:

>> >>steveu wrote: >> >>
>>> What about: >>>- Phase lock a synthesised pure sine wave to your signal. >>>- Tune the amplitude of your sine wave, so that >>> original.pure == pure.pure >> >>I wouldn't recommend this for beginners. > > Because Matlab doesn't pre-package this strategy? :-)
MatLab: dumb methods for dumb people (TM)
>>>Now, sqrt(original.original) is your harmonic polluted RMS value, and >>>sqrt(pure.pure) is the fundamental RMS value. The difference is the >>>harmonic content. >> >>Not quite. The difference is THD + N + numeric artifacts. > > > The numeric artefacts are fairly easy to keep under control.
When subtracting two square roots? You are looking for trouble.
> Noise can be > an issue if you want this to work over a wide dynamic range. Picking out > the exact harmonic frequencies, and ignoring all the noise in between, > could be cleaner with small signals.
But this is a totally different story. :-)
>>>Calculate those dot products in a leaky manner, and you can perform a >>>continuous measurement, tuning the phase lock and amplitude as you go. >> >>I've heard that some digital scopes adjust their sample rate so the >>period of fundamental falls exactly in the FFT bin. > > > I don't know what scopes do, but if you want to do accurate mains power > harmonic measurements by FFT you'd better be prepared to tune to the > precise fundamental, and sit all the bins bang on the harmonics. > > I've done power analysis by having a table of Goertzel coeffs for the exact > harmonic frequencies, for reasonably fine increments of fundamental between > 47.5Hz and 52.5Hz.
Why is that? That's very narrow for mobile generator and too wide for power grid.
> After doing a fundamental estimate I used the > appropriate table entries to estimate the harmonics as individual elements, > rather than an amorphous FFT bank. Its capable of very accurate and stable > results, without too much computation. Something like the 20th to 40th > harmonic is usually as far as people want to go, so you don't need to run > more than 40 Goertzels. That suits an application looking for an accurate > breakdown of the individual harmonics.
The 8-bit thinking is very touching; however it seems to be getting less and less popular with all that internets and matlabi :-) Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
> > >steveu wrote: > >>> >>>steveu wrote: >>> >>> > >>>> What about: >>>>- Phase lock a synthesised pure sine wave to your signal. >>>>- Tune the amplitude of your sine wave, so that >>>> original.pure == pure.pure >>> >>>I wouldn't recommend this for beginners. >> >> Because Matlab doesn't pre-package this strategy? :-) > >MatLab: dumb methods for dumb people (TM) > >>>>Now, sqrt(original.original) is your harmonic polluted RMS value, and >>>>sqrt(pure.pure) is the fundamental RMS value. The difference is the >>>>harmonic content. >>> >>>Not quite. The difference is THD + N + numeric artifacts. >> >> >> The numeric artefacts are fairly easy to keep under control. > >When subtracting two square roots? You are looking for trouble. > >> Noise can be >> an issue if you want this to work over a wide dynamic range. Picking
out
>> the exact harmonic frequencies, and ignoring all the noise in between, >> could be cleaner with small signals. > >But this is a totally different story. :-) > >>>>Calculate those dot products in a leaky manner, and you can perform a >>>>continuous measurement, tuning the phase lock and amplitude as you go. >>> >>>I've heard that some digital scopes adjust their sample rate so the >>>period of fundamental falls exactly in the FFT bin. >> >> >> I don't know what scopes do, but if you want to do accurate mains power >> harmonic measurements by FFT you'd better be prepared to tune to the >> precise fundamental, and sit all the bins bang on the harmonics. >> >> I've done power analysis by having a table of Goertzel coeffs for the
exact
>> harmonic frequencies, for reasonably fine increments of fundamental
between
>> 47.5Hz and 52.5Hz. > >Why is that? That's very narrow for mobile generator and too wide for >power grid.
Its wider than the power grid gets in even the worse run grids, but its the usual spec you are required to work to.
>> After doing a fundamental estimate I used the >> appropriate table entries to estimate the harmonics as individual
elements,
>> rather than an amorphous FFT bank. Its capable of very accurate and
stable
>> results, without too much computation. Something like the 20th to 40th >> harmonic is usually as far as people want to go, so you don't need to
run
>> more than 40 Goertzels. That suits an application looking for an
accurate
>> breakdown of the individual harmonics. > >The 8-bit thinking is very touching; however it seems to be getting less >and less popular with all that internets and matlabi :-)
It still tends to be efficient solutions that get the volume sales. Many utilities are interested in charging based on fundamental power energy consumption, rather than the active energy consumption they use today. They'll put really detailed harmonic analysis into every consumer electricity meter if its cheap enough. You'd better make the cost delta over a simply electricity meter close to zero, though, if you don't want to be confined to a niche. Steve