fft_complex

 

Description

Performs nFFT-point discrete Fourier transform or inverse Fourier transform. vSig will be padded with zeros if it has less than nFFT points and truncated if it has more.

Syntax

int fft_complex( int nFFT, vector<complex> & vSig, FFT_SIGN iSign = FFT_FORWARD )

Parameters

nFFT
[input] number of points to do Fourier transform.
vSig
[Modify] the original signal to be transformed, and the result of the transform.
iSign
[input] the transformation to carry out
= FFT_FORWARD: FFT (by default)
= FFT_BACKWARD: IFFT.

Return

Returns OE_NOERROR for success or error codes for failure.

Examples

Prior to compilation, load fft_utils.c to the workspace by executing the following LabTalk command:

Run.LoadOC("Originlab\fft_utils.c", 16);

To retain fft_utils.c in the workspace for successive sessions, drag and drop the file from the Temporary folder to the System folder.

EX1

// This example assumes a worksheet is active with seven columns, where
// column 2 has the signal. Column 3, 4 will be filled with real/imaginary
// parts of the foward FFT result. Colummns 5, 6 will be filled with 
// real/imaginary parts of the IFFT result. Column 7 will be filled with
// amplitude of IFFT result, which should then be same as column 2

#include <fft_utils.h>
void fft_complex_ex1()
{
    Worksheet wks = Project.ActiveLayer();
    Dataset dsData(wks, 1);
    Dataset dsFFTRe(wks, 2);
    Dataset dsFFTIm(wks, 3);
    Dataset dsIFFTRe(wks, 4);
    Dataset dsIFFTIm(wks, 5);
    Dataset dsIFFTAmpl(wks, 6);
    // If all datasets are valid, then proceed
    if( dsData && dsFFTRe && dsFFTIm && dsIFFTRe && dsIFFTIm && dsIFFTAmpl)
    {
        vector<complex> vec;
        vec = dsData;
        int nSize = vec.GetSize();
        // Perform forward FFT with exact size of signal
        int iRet = fft_complex(nSize, vec);
        if(0 != iRet )
        {
            printf("Forward FFT returned error: %d\n", iRet );
            return;
        }
        // Store forward FFT result
        vector vecTemp;
        vec.GetReal(vecTemp);
        dsFFTRe = vecTemp;
        vec.GetImaginary(vecTemp);
        dsFFTIm = vecTemp;
        // Perform backward FFT from the forward FFT result
        iRet = fft_complex(nSize, vec, FFT_BACKWARD);
        if(0 != iRet )
        {
            printf("Backward FFT returned error: %d\n", iRet );
            return;
        }
        // Store the backward FFT result
        vec.GetReal(vecTemp);
        dsIFFTRe = vecTemp;
        vec.GetImaginary(vecTemp);
        dsIFFTIm = vecTemp;
        vec.GetAmplitude(vecTemp);
        dsIFFTAmpl = vecTemp;
    }
}

Remark

See Also

fft_real

header to Include

fft_utils.h

Reference