06-12-2008 12:05 PM
Hi again,
I created a VI in LAbVIEW and it works fine. THD and THD+N looks good. On my Scopemeter the wave looks simetric.
But in LabWindows there are the same bad results.
I'm even trying to generate a sinewave to loop my signal back to me and check THD, but my AO task doesn't work too :s
It's either LabWindows or me to blame 😛
I'm still working on this.
Hope to get thru this.
Thanks for all the help. Do you have any more sugestions?
Daniel Coelho
06-13-2008 04:50 AM
Daniel,
I think the problem you have is due to the fact that PowerFrequencyEstimate function that you use to determine the fundamental frequency, will return 0 for the frequency peak, in case you have on your signal, a DC component bigger than signal amplitude.
I seen in few times, that when HarmonicAnalyzer is fed with 0 as fundamental frequency, it will calculate strange values for thd and thd+noise. And it will not return an error ...
One thing to try is to apply a highpass (or bandpass) filter to your input signal, that will remove DC component. But depending on the application, this might not be possible.
Then another thing to try would be to force PowerFrequencyEstimate to search for peak frequency starting from a higher frequency than 0. Save first 10 values - you might want to tweak this value to suit your application - of the spectrum array, then set first 10 elements of the spectrum array to 0.0, then run PowerFrequencyEstimate, and finally restore these 10 value to the original values.
Try this changes to your code:
double spectrum_array_buffer[10];
//.....
ScaledWindow (data, samples, 0, &WinConst);
auto_power_spectrum = (double *)malloc((samples/2)*sizeof(double));
AutoPowerSpectrum (data, samples/2, 1.0/(sampFreq),auto_power_spectrum, &df);
// ********************FundFreq
Copy1D (auto_power_spectrum, 10, spectrum_array_buffer); //- Save first 10 auto_power_spectrum components
Clear1D (auto_power_spectrum, 10); //- Set to 0.0 first 10 auto_power_spectrum components
PowerFrequencyEstimate (auto_power_spectrum, samples/2, -1, WinConst, df, 7, &Freq_Peak, &Power_Peak);
Copy1D (spectrum_array_buffer, 10, auto_power_spectrum); //- Restore auto_power_spectrum components
Converted_Spec = calloc (samples/2, sizeof(double));
SpectrumUnitConversion (auto_power_spectrum, samples/2, 0, 0, 0, df, WinConst, Converted_Spec, Unit);
number_of_harmonics = sampFreq/(2 * Freq_Peak);
if ( number_of_harmonics == 0)
number_of_harmonics = 5;
harmonic_amplitudes = (double *)malloc(number_of_harmonics * sizeof(double));
harmonic_frequencies = (double *)malloc(number_of_harmonics * sizeof(double));
// ********************THD e THD+N
HarmonicAnalyzer(auto_power_spectrum, samples/2, samples, number_of_harmonics,
2 , sampFreq, Freq_Peak, harmonic_amplitudes,
harmonic_frequencies, &thd1, &thdnoise1);
//...
Regards
ps. I also observed that Labview thd calculation is not so much affected by this issues.
06-15-2008 10:58 PM
06-16-2008 11:34 AM
06-16-2008 11:51 AM
06-23-2008 06:10 AM
Viva Luís,
usei o HarmonicAnalyserUsingSignal() e funcionou. Também alterei outra coisa, retirei a parte do SpectrumUnitConversion().
Agora parece bater certo com os resultados que eu obtinha com o LabVIEW.
Espero ter resolvido o assunto. Agora só quando voltar a dar mal é que vou saber 😛
Obrigado pela ajuda.
Cumprimentos.
Hi all,
I solved the problem with HarmonicAnalyserUsingSignal() and I deleted the SpectrumUnitConversion() function too.
Now it seems to work properly.
Thanks for all the help.
My best regards.
Daniel Coelho