#include <stdio.h>
#include <math.h>
#define FFT_ORDER 8
#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, fftl2;
double theta;
double *real;
#ifdef CALCULATE_DISTORTION
double rx, ix, dist;
double *real2;
#endif
fprintf(stderr, "Can't open FFT plugin: %s\n", plugin_name);
} else {
fprintf(stderr, "FFT plugin: %s\n", plugin_name);
}
}
fftl2 = fftl / 2;
for (k = 0; k < fftl; k++) {
theta = 2.0 * PI * SIN_NCYCLE * (double)k / (double)(fftl - 1);
real[k] = sin(theta);
}
#ifdef CALCULATE_DISTORTION
memcpy(real2, real, fftl * sizeof(double));
#endif
printf("%f %f\n", real[0], 0.0);
for (k = 1; k < fftl2; k++) {
printf("%f %f\n", real[2 * k], real[2 * k + 1]);
}
printf("%f %f\n", real[1], 0.0);
#ifdef CALCULATE_DISTORTION
dist = 0.0;
rx = real[0] - real2[0];
dist += SQUARE(rx);
for (k = 1; k < fftl2; k++) {
rx = real[2 * k] - real2[2 * k];
ix = real[2 * k] - real2[2 * k];
dist += 2.0 * (SQUARE(rx) + SQUARE(ix));
}
rx = real[1] - real2[1];
dist += SQUARE(rx);
dist = sqrt(dist / (double)fftl);
printf("dist = %f\n", dist);
#endif
return 0;
}
spBool spExecRealFFT(spFFTRec fftrec, double *data, int inv)
long spGetFFTLength(spFFTRec fftrec)
spFFTRec spInitFFTByPlugin(spPlugin *plugin, long order, spFFTPrecision precision)
spBool spFreeFFT(spFFTRec fftrec)
int sprfft(double *data, long fftl, int inv)
#define SP_FFT_DEFAULT_PRECISION
Definition fft.h:38
spPlugin * spLoadFFTPlugin(const char *name)
#define spStrNone(string)
#define xspAlloc(n, type)