01-12-2013 09:40 AM
Hello.
I am a new user to cvi and i want to undestand how to do FFT .
I want to generate sinewave and preform FFT on it and than Plot it but i am geting very strange results not as i expected iwas sure i will get same plot as when i am at my lab connecting sine wave to spectrum .
This is my code .
Thx for help.
#include <analysis.h>
#include <cvirte.h>
#include <userint.h>
#include "Furie.h"
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];
static int panelHandle;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "Furie.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK create (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
SineWave (512, 1.0, FREQ, &phase, sine);
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_GREEN);
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);
break;
}
return 0;
}
Solved! Go to Solution.
01-14-2013 07:32 AM
I haven't run your code, but I think you want the 'spectrum' function which provides the power spectrum. You should also set proper horizontal scales if you want your graphs to make sense.
01-14-2013 01:28 PM
Hello iliya24,
Is there a reason why you are using the ReFFT function? According to the help file (http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvirefft/), this function is obsolete. You can use FFTEx (http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvifftex/) or FFT (http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvifft/). In this help, there is some helpful example code that you can use as a test in your program. You also may be able to see the FFT more easily if you do not plot the sine wave.
Regards,
Jason D
Applications Engineer
National Instruments
01-14-2013 01:43 PM
thx