home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / Articles / AIandBeyond / FFT.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-14  |  657 b   |  21 lines

  1. #include <iostream.h>
  2. #include <math.h>
  3. #include <complex.h>
  4.  
  5. void FFT(float *X, float *Y)
  6. {
  7.    int k, n;                        // integers for the loops
  8.    complex mult;                    // a complex number
  9.    float prod;                        // a floating point number for the real component
  10.    complex i=complex(0, 1);    // the square root of -1
  11.  
  12.     for(k=0; k<512; k++)                // loops through each sub harmonic
  13.    {
  14.         for(n=0; n<1024; n++)        // loops through each sample
  15.       {
  16.           mult=exp((-2*M_PI*i*k*(n+1))/1024);    // calculates the equation
  17.          prod=real(mult);                            // gets the real component
  18.          Y[k]=+X[n]*prod;                            // multiplies the real component
  19.       }
  20.    }
  21. }