/* * Xavier Gourdon : Sept. 99 (xavier.gourdon.free.fr) * * FFT.c : Very basic FFT file. * The FFT encoded in this file is short and very basic. * It is just here as a teaching file to have a first * understanding of the FFT technique. * * A lot of optimizations could be made to save a factor 2 or 4 for time * and space. * - Use a 4-Step (or more) FFT to avoid data cache misses. * - Use an hermitian FFT to take into account the hermitian property of * the FFT of a real array. * - Use a quad FFT (recursion N/4->N instead of N/2->N) to save 10 or * 15% of the time. * * Informations can be found on * http://xavier.gourdon.free.fr/Constants/constants.html */ #include "FFT.h" #include #include #include #define PI 3.1415926535897932384626 typedef struct ComplexTag { Real R,I; } Complex; long FFTLengthMax; Complex * OmegaFFT; Complex * ArrayFFT0, * ArrayFFT1; Complex * ComplexCoef; double FFTSquareWorstError; long AllocatedMemory; void InitializeFFT(long MaxLength) { long i; Real Step; FFTLengthMax = MaxLength; OmegaFFT = (Complex *) malloc(MaxLength/2*sizeof(Complex)); ArrayFFT0 = (Complex *) malloc(MaxLength*sizeof(Complex)); ArrayFFT1 = (Complex *) malloc(MaxLength*sizeof(Complex)); ComplexCoef = (Complex *) malloc(MaxLength*sizeof(Complex)); Step = 2.*PI/(double) MaxLength; for (i=0; 2*iFFTSquareWorstError) FFTSquareWorstError = (tmp-Coef[i])*(tmp-Coef[i]); } } void Convolution(Complex * A, Complex * B, long NFFT, Complex * C) { long i; Real tmpR, tmpI; for (i=0; iFFTLengthMax) { printf("Error, FFT Size is too big in MulWithFFT\n"); return; } FFT(ACoef, ASize, ArrayFFT0, NFFT); FFT(BCoef, BSize, ArrayFFT1, NFFT); Convolution(ArrayFFT0,ArrayFFT1,NFFT,ArrayFFT0); InverseFFT(ArrayFFT0,NFFT,CCoef, ASize+BSize-1); }