home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / fftlib / fft.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-06  |  915 b   |  54 lines

  1. #include <math.h>
  2.  
  3. #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
  4.  
  5. void four1(data,nn,isign)
  6. double data[];
  7. int nn,isign;
  8. {
  9.     int n,mmax,m,j,istep,i;
  10.     double wtemp,wr,wpr,wpi,wi,theta;
  11.     double tempr,tempi;
  12.  
  13.     n=nn << 1;
  14.     j=1;
  15.     for (i=1;i<n;i+=2) {
  16.         if (j > i) {
  17.             SWAP(data[j],data[i]);
  18.             SWAP(data[j+1],data[i+1]);
  19.         }
  20.         m=n >> 1;
  21.         while (m >= 2 && j > m) {
  22.             j -= m;
  23.             m >>= 1;
  24.         }
  25.         j += m;
  26.     }
  27.     mmax=2;
  28.     while (n > mmax) {
  29.         istep=2*mmax;
  30.         theta=6.28318530717959/(isign*mmax);
  31.         wtemp=sin(0.5*theta);
  32.         wpr = -2.0*wtemp*wtemp;
  33.         wpi=sin(theta);
  34.         wr=1.0;
  35.         wi=0.0;
  36.         for (m=1;m<mmax;m+=2) {
  37.             for (i=m;i<=n;i+=istep) {
  38.                 j=i+mmax;
  39.                 tempr=wr*data[j]-wi*data[j+1];
  40.                 tempi=wr*data[j+1]+wi*data[j];
  41.                 data[j]=data[i]-tempr;
  42.                 data[j+1]=data[i+1]-tempi;
  43.                 data[i] += tempr;
  44.                 data[i+1] += tempi;
  45.             }
  46.             wr=(wtemp=wr)*wpr-wi*wpi+wr;
  47.             wi=wi*wpr+wtemp*wpi+wi;
  48.         }
  49.         mmax=istep;
  50.     }
  51. }
  52.  
  53. #undef SWAP
  54.