LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to do FFT on 1D array of sine wave

Hi,
 
I am very new to CVI as well as C programming. Pardon me if this post sounds stupid.
 
I am creating a code and part of the code is to generate a sine wave and do a FFT on the generated sine wave to get the amplitude and phase plots. I want to get a graph that is similar to the picture attached below.
 
I do not know how to use the FFT function as it required an array of real values and an array of imaginary values. When I create a sine wave, I think all the values created are amplitude values. Can I just use these created values in FFT function?? Can anyone show me how to achieve what I want as shown in the picture??
 
I am also looking for a function in CVI that will tell me what is the amplitude and frequency of the sine wave. This sine wave is just a simulated signal. I will use my code with real signal which I want to find the amplitude and frequency of the real signal. I tried PowerFrequencyEstimate but it does not give me the right value (which is 10Hz).
 
 
Part of my code is as below.
 
static WindowConst Windowing;
static double samfreq=200;             //sampling frequency is 200Hz
static double reqfreq=10;                 //sine wave frequency is 10Hz
static double freq=1000;                  //frequency at which sine wave function generate
static double sampleno=0;              //number of samples
static double phasedeg=0;              //phase in degree
static double sig[1000];
static double freqpeak, amppeak;   //to store frequency peak value and amplitude peak value
 
Clear1D(sig,1000);
freq=reqfreq/samfreq;
SineWave (sampleno, 1.0, freq, &phasedeg, sig);
ScaledWindowEx (amplitude, sampleno, HANNING, 0, &Windowing);
PowerFrequencyEstimate (sig, sampleno, -1.0, Windowing, delta_f, 7, &freqpeak, &amppeak);
FFT (sig, sig, sampleno);     //gives me nothing on the graph control
 
Hope someone can give me adivse on how I can achieve what I want.
 
Thank you and Regards
Lee
0 Kudos
Message 1 of 2
(6,439 Views)
Hello Lee,
 
I think fort his case we might want to use the ReFFT() function instead of the FFT() function.  ReFFT() does not expect a filled imaginary array but in fact a blank imaginary array of the same size as our real array which it then fills within the function.  Therefore I think we might want use this function instead since we only have a single input array.
 
You can find an example of using both of these functions in the 2dfft.prj example that comes with CVI.  You can open this example via the Example Finder (Help»Find Examples) by browsing to Analysis and Processing Signals»FFT and Frequency Analysis.  This has an example of both FFT functions being used so you might find this helpful as a reference.
John B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(6,375 Views)