#include <stdio.h>
#include <math.h>
#define FFT_ORDER 10
#define SIN_NCYCLE 5
#define CALCULATE_DISTORTION
#if 1
#define FFT_PLUGIN_NAME "oourafft"
#elif 0
#define FFT_PLUGIN_NAME "fftw"
#elif 0
#define FFT_PLUGIN_NAME "cufft"
#else
#define FFT_PLUGIN_NAME ""
#endif
static char plugin_name[SP_MAX_PATHNAME] = FFT_PLUGIN_NAME;
int spMain(int argc, char **argv)
{
long k;
long fftl;
double theta;
double *real, *imag;
#ifdef CALCULATE_DISTORTION
double rx, ix, dist;
double *real2, *imag2;
#endif
fprintf(stderr, "Can't open FFT plugin: %s\n", plugin_name);
} else {
fprintf(stderr, "FFT plugin: %s\n", plugin_name);
}
}
for (k = 0; k < fftl; k++) {
theta = 2.0 * PI * SIN_NCYCLE * (double)k / (double)(fftl - 1);
real[k] = sin(theta);
imag[k] = 0.0;
}
#ifdef CALCULATE_DISTORTION
memcpy(real2, real, fftl * sizeof(double));
memcpy(imag2, imag, fftl * sizeof(double));
#endif
for (k = 0; k < fftl; k++) {
printf("%f %f\n", real[k], imag[k]);
}
#ifdef CALCULATE_DISTORTION
spfft(real2, imag2, fftl, 0);
dist = 0.0;
for (k = 0; k < fftl; k++) {
rx = real[k] - real2[k];
ix = imag[k] - imag2[k];
dist += (SQUARE(rx) + SQUARE(ix));
}
dist = sqrt(dist / (double)fftl);
printf("dist = %f\n", dist);
#endif
return 0;
}
A class to handle FFT execution.
int spfft(double *xRe, double *xIm, long fftl, int inv)
spBool spExecFFT(spFFTRec fftrec, double *real, double *imag, int inv)
long spGetFFTLength(spFFTRec fftrec)
spFFTRec spInitFFTByPlugin(spPlugin *plugin, long order, spFFTPrecision precision)
spBool spFreeFFT(spFFTRec fftrec)
#define SP_FFT_DEFAULT_PRECISION
Definition fft.h:38
spPlugin * spLoadFFTPlugin(const char *name)
#define spStrNone(string)
#define xspAlloc(n, type)