LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

THD+N measure without knowing the fundamental frequency

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

 

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 11 of 16
(2,338 Views)

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 ... Smiley Mad

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.

0 Kudos
Message 12 of 16
(2,319 Views)
Hi miniMe,

Could you please try another function called HarmonicAnalyzerUsingSignal?
 
It is a new function in LabWindows which can find the amplitude levels and frequency tones of the fundamental and harmonic components and calculate THD and THD+N directly from the input time-domain signal.
 
Best wishes,

 
0 Kudos
Message 13 of 16
(2,281 Views)
Olá Daniel,
 
Não sei bem ao certo que versão do CVI é que estás a usar. No entanto, a função HarmonicAnalyzerUsingSignal foi introduzida na versão 8.5, precisamente para resolver umas diferenças no algoritmo usado pelo CVI e o do LabVIEW.
 
Luís
Message 14 of 16
(2,266 Views)
Viva Luis,
eu estou a usar o LabWindows/CVI 8.5. Ja me deparei com o HarmonicAnalyzerUsingSignal mas entretanto remediei a situação com o LabVIEW.
Assim que eu voltar a pegar nisto vou tentar o HarmonicAnalyzerUsingSignal porque a minha solução tem que passar pelo LabWindows.
Estou a fazer uns testes com os equipamentos que geram sinal e com o código para ter a certeza que os valores "errados" que estou a obter não são derivados ao próprio equipamento.
Obrigado pela resposta e espero ter resultados em breve.
Cumprimentos.
 
Hi all,
at the moment I'm trying another aproach to solve this problem using LabVIEW. But I'll get back to this using CVI.
I hope to write soon telling what I managed to achieve.
Thanks for the help.
See u soon.
 
Daniel Coelho
 
Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 15 of 16
(2,262 Views)

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

 

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 16 of 16
(2,213 Views)