/**************************************************************************** * Func: twoD_FFT * * * * Desc: performs an FFT on image data * * * * Params: complex_data - array of complex image data * * rows - number of rows in source image * * cols - number of cols in source image * * dir - direction of FFT (1=forward -1=reverse) * ****************************************************************************/ void twoD_FFT(complex_ptr complex_data, int rows, int cols, int dir) { unsigned long x,y; /* x and y indices to source image */ unsigned long index; /* index to output line buffer */ COMPLEX *col_data; /* storage for the columns */ COMPLEX *row_data; /* storage for the rows */ int M, N; /* power of 2 for each dimension */ int num; /* temporary variable */ /* compute power of 2s */ num = cols; M = 0; while(num >= 2) { num >>= 1; M++; } num = rows; N = 0; while(num >= 2) { num >>= 1; N++; } /* allocate memory for storage */ col_data = (COMPLEX *) malloc(sizeof(COMPLEX)*rows); row_data = (COMPLEX *) malloc(sizeof(COMPLEX)*cols); if((col_data == NULL) || (row_data == NULL)) exit(1); for(y=0; y j) { /* swap f[j] and f[i] */ temp = f[j].re; /* swap real */ f[j].re = f[i].re; f[i].re = temp; temp = f[j].im; /* swap imaginary */ f[j].im = f[i].im; f[i].im = temp; } m = numpoints>>1; while ((j >= m) & (m >= 2)) { j -= m; m = m >> 1; } j += m; } } /*************************************************************************** * Func: butterflies * * * * Desc: Calculates the butterflies for data in fft * * if a reverse fft, points are divided by numpoints * * * * Params: numpoints- number of points in the complex array * * logN- power of 2 (numpoints = 2^logN) * * dir- direction of fft (1=forward, -1=reverse) * * f- array of data * ***************************************************************************/ void butterflies(int numpoints, int logN, int dir, COMPLEX *f) { double angle; /* polar angle */ COMPLEX w, wp, temp; /* intermediat complex numbers */ int i, j, k, offset; /* loop variables */ int N, half_N; /* storage for powers of 2 */ double wtemp; /* temporary storage for w.re */ N = 1; for(k=0; k