LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FFT

Solved!
Go to solution

Hi all ,

 

I have some problem with the FFT Function in the analysis library

 

I'm using a 128 points array with a sin wave generated in my unit.

 

But when using the FFT function and after with the ToPolar1D and some other math stuff,  to get my Amplitude and the Freq I don't get the values I expected to see .

 

The example given in the cvi isn't helping very much , maybe some one have something else ?

 

Or you have some good guide for that ?

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 1 of 5
(3,862 Views)
Solution
Accepted by Kobi_K

Hi Kobi ,

 

 I have also used the FFT function in finding out the phase difference and amplitudes of two sine waves

 and it works absolutely fine. Each array consists of 128 samples .See the code below.

 

void phasedifference(void)

{                         
    double ph0=0,ph1=0,r1=0,r2=0,im1=0,im2=0,mag1 = 0, mag2 = 0;
   double outarray2[128], outarray4[128],outarrayim2[128],outarrayim4[128];
 
 FFT(outarray2,outarrayim2,128);    // 1 cycle = 128 samples
 
 r1= outarray2[1];
 im1= outarrayim2[1];
 
    mag1  = sqrt((pow(r1,2.0)+pow(im1,2.0)));
 
 mag1 = (mag1*2)/128;
 

 SetCtrlVal(panelHandle,PANEL_pk1,mag1);


 ph0 = RadToDeg(atan2(im1,r1));
 
  
 FFT(outarray4,outarrayim4,128);  // 1 cycle = 128 samples
 
 r2= outarray4[1];
 im2= outarrayim4[1];
 
 mag2  = sqrt((pow(r2,2.0)+pow(im2,2.0)));
 
 mag2 = (mag2*2)/128 ;
 
 
 SetCtrlVal(panelHandle,PANEL_pk2,mag2);
 
 ph1 = RadToDeg(atan2(im2,r2));    
 
  
 phase_diff = ph0 - ph1;

 

SetCtrlVal(panelHandle,PANEL_phase_diff_0,phase_diff);

 

}

 

Hope this helps.
 

0 Kudos
Message 2 of 5
(3,855 Views)

Hi.

I am new user of cvi and  i have tsk i need to do an FFT of sine wave .

So itried to do it .

1)I generated 128 arry of sinewave then i used REFFT and also FFT on the sine generator but the plot i got when i draw the result was not as i  expected .

i thought that i will get the same picture as  in lab when i connect sine generatot to spectrum...

This is my code any help?

 

This is my varibales

 

static double sine[512];
static double IM[512];
static double wave[1024];
static double phase=0;
#define NB_PTS 512
#define AMPLITUDE 2.282
#define FREQ 10.0/NB_PTS
static double SignalArray[NB_PTS];

 

 

SineWave (512, 1.0, FREQ, &phase, sine);

ReFFT(sine, IM, 512);

PlotWaveform (panel, PANEL_SourceWave, sine, NB_PTS, VAL_DOUBLE, 1.0, 0.0, 0.0, 1,VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);

0 Kudos
Message 3 of 5
(3,725 Views)

Hello iliya24,

 

Also, it is recommended that you start a new thread when you have a new question. This helps others navigate the forums more easily in order to solve their questions. It looks like you did this (http://forums.ni.com/t5/LabWindows-CVI/fft/m-p/2277960), so the discussion of your issue would best be handled there.

 

Regards,

 

Jason D

Applications Engineer

National Instruments

0 Kudos
Message 4 of 5
(3,695 Views)

thx

0 Kudos
Message 5 of 5
(3,691 Views)