/* --------------------------------------------------------------- * Serial - Two-Dimensional Fast Fourier Transform - C Version * FILE: ser_2dfft.c * OTHER FILES: ser_fft.c ser_fft.h * DESCRIPTION: Algorithm: Perform a 1D FFT on each row, transpose, * then perform a 1D FFT on each row again. * * Input is an 512x512 complex matrix. Output is an 512x512 * complex matrix that overwrites the input matrix. The input matrix is * initialized with a point source. * * A straightforward unsophisticated 1D FFT kernel is used. It is * sufficient to convey the general idea, but be aware that there are * better 1D FFTs available on many systems. * * AUTHOR: George Gusciora * LAST REVISED: * --------------------------------------------------------------- */ #include "ser_fft.h" #include #include #include #define IMAGE_SIZE 512 static mycomplex a[MAXN][MAXN]; /* input matrix */ static mycomplex w_common[MAXN/2]; /* twiddle factors */ main(argc,argv) int argc; char **argv; { int n; /* FFT size */ int logn; /* log base 2 of n */ int errors,sign; /* used for error checking */ int nx; /* used to compute logn */ int flops; /* total number of floating point ops */ float mflops; /* Mflops/s */ double fsecs; /* time spent doing 1D FFT's */ double tsecs; /* time spent doing the transpose */ double secs; /* total time of the 2D FFT */ int i,j; /* index variables */ struct timeval start, finish; /* gettimeofday structures */ void print_cmat(), print_cvec(); /* forward definitions */ n = IMAGE_SIZE; /* compute logn and ensure that n is a power of two */ nx = n; logn = 0; while(( nx >>= 1) > 0) logn++; nx = 1; for (i=0; i n*sign+EPSILON || a[i][j].r < n*sign-EPSILON || a[i][j].i > n*sign+EPSILON || a[i][j].i < n*sign-EPSILON) { printf("%d,%d\n",i,j); errors++; } sign *= -1; } } if (errors) { printf("%d errors!!!!!\n", errors); exit(0); } /* summarize the 2d FFT performance */ printf("%d x %d 2D FFT\n", n, n); secs = fsecs + tsecs; flops = (n*n*logn)*10; mflops = ((float)flops/1000000.0); mflops = mflops/(float)secs; printf("\n"); printf("1D FFTs : %10.6f secs (%2d%%)\n", fsecs, (int)(fsecs/secs*100)); printf("transpose : %10.6f secs (%2d%%)\n", tsecs, (int)(tsecs/secs*100)); printf("total : %10.6f secs\n", secs); printf("\n"); printf("%10.6f Mflop/s\n", mflops); exit(0); } /* * routines to print complex matrices and vectors */ void print_cvec(a, n) mycomplex *a; int n; { int i; for (i=0; i