LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with THD+N from HarmonicAnalyzer

Hello,

We need to to perform frequency analysis including parameter THD+N and I believe this functionality is broken.

To show that is broken, I modified NI example THD.C by changing line 109 (in LabWindows/CVI 8.0.0 (273)):

for(i = 0; i < frame_size; i++)

*(distored_signal + i) = *(sine_wave+i) + (*(sine_wave+i) * *(sine_wave+i) * 0.5)

+ *(noise+i);

into

for(i = 0; i < frame_size; i++)

*(distored_signal + i) = *(sine_wave+i)

/*+ (*(sine_wave+i) * *(sine_wave+i) * 0.5)

+ *(noise+i)*/

;

and we should obtain harmonic signal with no distortion and no noise. But we get the result from the picture, where THD+N is obviously wrong. It gets worse with different window types.

Thank you

Message Edited by romanZ on 01-10-2007 10:17 AM

Message Edited by romanZ on 01-10-2007 10:18 AM

0 Kudos
Message 1 of 15
(5,580 Views)

Hi RomanZ,

Thank you for your post.  We are looking into this.

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 2 of 15
(5,540 Views)

Hi RomanZ,

Thanks for bringing this issue to our attention - this is a bug and we are working on it.  For now, using a Hanning or Hamming window produces much better results.

Message Edited by AEDavid on 01-12-2007 03:55 PM

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 3 of 15
(5,524 Views)
Was the porblem with the HarmonicAnalyzer function resolved? Is there any update available for download?
 
Thanks
Eric
0 Kudos
Message 4 of 15
(5,420 Views)

Hi Eric,

Thank you for the feedback.  I apologize for the inconvenience.  I have updated the Corrective Action Request to indicate that you are also needing a fix.  There is currently no update, but R&D is examining this issue.  For now, using a Hanning or Hamming window produces much better results.

Cheers,

David Goldberg
National Instruments
Software R&D
Message 5 of 15
(5,394 Views)

Hello,

I think this problem is caused by spectrum leakage during the calculation of auto power spectrum.

After your change of the code, the input signal is 1000Hz sine wave. When you use default sampling rate and frame size, the discrete signal will be 1024-point signal covering 102.4 periods of the sine wave. Spectrum leakage will occur when you try to calculate the auto power spectrum of the sampled signal.

You can use Hanning window or some other window before auto power spectrum calculation to reduce spectrum leakage.

And for this particular case you can eliminate the spectrum leakage by setting the sampling rate to 10240Hz to get 100 complete periods of sine wave.

0 Kudos
Message 6 of 15
(5,317 Views)

i got the wrong result using "Harmonic Analyzer Using Signal" function. I using a squarewave in 1kHz with 50% duty to test the funtion, but the ratio of THD is only 48%. I use a instrument to measure the same signal, and got THD ratio at 60%.

I am confused.

do you have some suggestion?Thanks

0 Kudos
Message 7 of 15
(4,747 Views)

i got the wrong result using "Harmonic Analyzer Using Signal" function. I using a squarewave in 1kHz with 50% duty to test the funtion, but the ratio of THD is only 48%. I use a instrument to measure the same signal, and got THD ratio at 60%.

I am confused.

do you have some suggestion?Thanks

0 Kudos
Message 8 of 15
(4,746 Views)

Hello,

 

Theoretically the THD of 50% duty squarewave should be 48%.

 

You can refer to the attachment for detailed derivation.

 

Could you please tell me the sampling rate and the number of samples in your use case? The result might be inaccurate if you do not set the sampling rate and the number of samples properly.

 

 

0 Kudos
Message 9 of 15
(4,711 Views)

Thanks

I don't have office2007 on my computer and I can't donwload the file. please, can you save your code in txt file ?

Sampling Rate is 250kHz

the number of samples is 262144

the input signal is squarewave at 1kHz 

0 Kudos
Message 10 of 15
(4,670 Views)