/* This is a sample program for 1D fast Fourier transform (FFT). Compile it with "cc myfft.c -lm -o myfft" The code includes a function fft(xr,xi,m,inverse) which can do both forward (inverse=0) and inverse (inverse=1) Fourier transform. xr and xi are the real and imaginary parts of the complex data and m is the number of complex values in the 1D array. Run it to see the data in the frequency domain. Since the input data is real, the spectrum is symmetric (even for real part, odd for imaginary art). The program then does the inverse transform to get back to time domain. See that the data is recovered in time domain. You can use the fft function in this program for your project. I wrote this fft function following closely what I showed you in class (and also the handout). Do not treat it as a black box. Read it to understand it. */ #include #include #include #include #include "array_utility.h" #define Pi 3.141592653589 #define SWAP(a,b) tempr=(a); (a)=(b); (b)=tempr void bitreversal(x,N) /* bit reverses a given vector x[] */ float *x; int N; { int i,j,k, m=log((float)N)/log(2.0); float w; for (i=0; i> k)); if (j < i) { w=x[i]; x[i]=x[j]; x[j]=w; } } } fft(xr,xi,N,inv) float *xr,*xi; // real and imaginary parts of data int N; // N: size of data, int inv; // inv=0 for FFT, inv=1 for IFFT { int i,j,k,j1,m,n; float arg,s,c,w,tmpr,tmpi; m=log2f((float)N); printf("N=%d, m=%d\n",N,m); for (i=0; i> k)); if (j < i) { w=xr[i]; xr[i]=xr[j]; xr[j]=w; w=xi[i]; xi[i]=xi[j]; xi[j]=w; } } for (i=0; i