Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

There has a error message when I call HarmonicAnalyzer..

 
 
Based on the same SpectrumArray data , in a Windows Dialog, I can get 'thd' successfully.
But in DLL, I will get ' Floating-point division by zero. ' error message. And this is not exception thus this will cause my AP hang on here.
 
I trace step by step and the above  error message is generated by the following function call.
My sample code is as the following:
MathError error =  CNiMath::HarmonicAnalyzer(SpectrumArray
      ,dw_WaveArraynSamplePerSec
      ,dTF,harmonicAmp,harmonicFreq,*thd,thdNoise
      ,iInputBufferNumber ,HarmonicNumber,static_cast<CNiMath::WindowType>(i_WindowType));
 
What is the problem in function HarmonicAnalyzer ? How can I remove the above error message and handle it by exception?
And my NI measurement studio is version 6.
Is that free to uprade to version 7 or 8 if the above is the bug of version 6?
0 Kudos
Message 1 of 23
(5,870 Views)
I forgot to mention that if I set HarmonicNumber to 2 (intead of 5) , the error message will disappear and return the correct the data to me.
 
CNiMath::HarmonicAnalyzer(SpectrumArray
      ,SPS //dw_WaveArraynSamplePerSec
      ,dTF,harmonicAmp,harmonicFreq,*thd,thdNoise
      ,iInputBufferNumber ,HarmonicNumber,static_cast<CNiMath::WindowType>(i_WindowType));
Message 2 of 23
(5,853 Views)

Hey Bird,

Ther is an updater here: Measurement Studio Version 6.0 for Windows--Update for Visual Basic 6.0 and Visual C++ 6.0 (patch) .  Try that and let me know how it turns out.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 3 of 23
(5,840 Views)
Thank you for your feedback.
But updating NI V6 updater seems doesn't work.
 
0 Kudos
Message 4 of 23
(5,830 Views)

Hey Bird,

Is there any way to print out each of the values that you are passing to the HarmonicAnalyzer() function.  I'm just curious to see if maybe I can reproduce it on my end.  Also, let me know what all the values are when it works for you.

 

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 5 of 23
(5,821 Views)
The attachment file 'b.wav' is the one I try to read back and analyze the harmonic.
The b.wav file is property is
nSamplesPerSec : 192000
nChannels : 2
wBitsPerSample : 16
TotalSamples : 4096
 
int iInputBufferNumber =  m_WaveArray.GetSize();  // the channel 1 of  b.wav data is read back and save in m_WaveArray.,                                                                                    // iInputBufferNumber =4096
  if (iInputBufferNumber <0)
    return false;
  CNiReal64Vector WaveArray(m_WaveArray);
  CNiReal64Vector SpectrumArray(iInputBufferNumber);
  double df;
  double dt;
  int    i_WindowType = WindowType;  //WindowType =3
  dt = (double) 1 / dw_WaveArraynSamplePerSec;  //dw_WaveArraynSamplePerSec = 192000
    
  CNiReal64Vector CovertedSpectrumArray(iInputBufferNumber);    
  CNiMath::WindowConstants wc;
  CNiReal64Vector convertedSpectrum(iInputBufferNumber);   
  CString unitsString;
  if ((i_WindowType !=0)&&(i_WindowType !=2)&&(i_WindowType !=5))
  {
    //For ScaledWindow, WindowType cannot be Rectangular(0),Triangular(2),Blackman(5)            
    CNiMath::ScaledWindow(WaveArray, wc, static_cast<CNiMath::WindowType>(i_WindowType));                   
  }
  // calculate the power spectrum
  if (CNiMath::AutoPowerSpectrum(WaveArray, SpectrumArray, df, dt)
    != MathSuccess)
  {
    return false;
  }
  // Find Estimated Peak Power and Frequency values
  if (CNiMath::PowerFrequencyEstimate(SpectrumArray, wc, m_peakFrequency, m_peakPower, -1, 7, df)
      != MathSuccess)
  {
     return false;
  }

  if ((i_WindowType ==1)||(i_WindowType ==2))
  {
    //For THD calculate, WindowType cannot be Rectangular(1),Triangular(2)
    * thd = -1;
     return false;
  }
  //calculate harmonic
  int HarmonicNumber = dw_WaveArraynSamplePerSec / (2 * TargetFrequency) -1;  //TargetFrequency = 1000;
  if (HarmonicNumber>numHarmonics)
    HarmonicNumber = numHarmonics;   //numHarmonics=5, if numHarmonics=2, there is no error message in the HarmonicAnalyzer function
  CNiReal64Vector  harmonicAmp(HarmonicNumber);
  CNiReal64Vector  harmonicFreq(HarmonicNumber);
  double thdNoise;
  try
  {
    double dTF =TargetFrequency;  //TargetFrequency = 1000;
    double SPS = dw_WaveArraynSamplePerSec;  // dw_WaveArraynSamplePerSec = 192000
    MathError error =  CNiMath::HarmonicAnalyzer(SpectrumArray
      ,SPS //dw_WaveArraynSamplePerSec
      ,dTF,harmonicAmp,harmonicFreq,*thd,thdNoise
      ,iInputBufferNumber ,HarmonicNumber,static_cast<CNiMath::WindowType>(i_WindowType));
  } catch (CException* e)
  {
    return false;  //I can not catch that error message by exception
  }
  return true;
0 Kudos
Message 6 of 23
(5,810 Views)

Hi Sam,

In my source code I try to implement the following code in the begin of the above Cal_THD function:

try
  {
    double i=0;
    double j=100/j;
   // int *p=0;
    //*p = 100;

  } catch (...)
  {
    return false; //check if I can catch this exception
  }

And if compile it with Dlg AP, I can not catch that error. 
And if compile the same code with DLL, I can catch the above error.
Do you have any idea?

But the following exception in Dlg AP could be catched.

  // int *p=0;
    //*p = 100;

Bird

0 Kudos
Message 7 of 23
(5,803 Views)
Now I'm a little confused.  Are you saying that if you just try to run a divide by zero (not using measurement studio) that it compile as a Dlg AP but not as a DLL?  I'm just trying to narrow down the issue here. 
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 8 of 23
(5,793 Views)

Hi Sam,

I implement a Audio Class (Call CAudio_Capture ) and this class need to include NI component work to calculate THD / AC/DC.

I could implement a dialog AP to include this class or a DLL file to use this Class, right?

In the dialog AP, there is no exception when I use the above Audio class when I try to divide zero. (I think that is NI component to handle that exception and doesn't throw it out.)

But in DLL, there  will have execption if I try to divide zero. and after exception,the function NI "HarmonicAnalyzer" only return 2 harmonic intead of 5 ones I setted.

So could you have a look of this inside NI component.

0 Kudos
Message 9 of 23
(5,785 Views)

I'm not able to reproduce the error.   Maybe you can post your project and I'll see if I can reproduce it?  Thanks Bird.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 10 of 23
(5,773 Views)