Fourier transformation Could someone be kind enough to review this Fourier transformation, please? I'm especially interested in going about unit testing the code (I don't really know where to begin, beyond applying the fft twice to retrieve the input), and have left test functions blank.

If you do spot a bug (and no doubt there are some), please don't tell me. I'd like to find them myself.

/*
  A simple radix 2 fast fourier transform. 
*/

#include &lt;complex&gt;
#include &lt;iostream&gt;
#include &lt;cassert&gt;
#define _USE_MATH_DEFINES
#include &lt;cmath&gt;

typedef std::complex&lt;double&gt; Complex;

void TestSpike(Complex* data, int length){
   assert( 1.0 == data[1]);
}

//Generates a spike in the DC bin, used for testing the fft
void GenerateSpike(Complex* data, int length){
  for(int i = 0 ; i &lt; length ; i++)
    {
      if(1 == i){
        data[i] = 1.0;
      } else {
        data[i] =  0.0;
      }
    }
  TestSpike(data, length);
}

void TestTwiddle(){
}

void TestButterfly(){
}

Complex w(int bin, int length){
  return (cos(2*M_PI*bin/length), sin(2*M_PI*bin/length));  
}

void butterfly(Complex* data, int bin, int stepSize, int fftlength){
  Complex x0 = data[bin];
  Complex x1 = data[bin+stepSize];

  data[bin]          = x0 + w(bin, fftlength)*x1;
  data[bin+stepSize] = x0 - w(bin, fftlength)*x1;
}

//Decimation in time
 void FFT(Complex *data, int length){
  for(int bflySize = 2 ; bflySize &lt; length ; bflySize *= 2)
    {
      int numBflys = length/bflySize;
      for(int i = 0 ; i &lt; numBflys ; i++)
        {
          int stepSize = bflySize/2;
            for(int j = 0 ; j &lt; bflySize ; j+= stepSize)
            {
               butterfly(data, (bflySize*i)+j, bflySize/2, length);
            }
        }
    }
}

int Reverse(unsigned int i, int size){
  int reversed = 0;
  while(size &gt; 1){
    reversed = (reversed &gt;&gt; 1) | (i &amp; 1);
    i &gt;&gt;= 1;
    size &gt;&gt;= 1;
  }
  return reversed;
}

int main(int argv, char** argc){

  int length;
  std::cout &lt;&lt; "Please input the length of the FFT" &lt;&lt; std::endl;
  std::cin &gt;&gt; length;
  std::complex&lt;double&gt; data[length];
  GenerateSpike(data, length);
  FFT(data, length);
  for(int i = 0 ; i &lt; length ; i++)
     {
       int j = Reverse(i,length);
       std::cout &lt;&lt; data[j] &lt;&lt; std:: endl;
     }
  return 0;
}
Using operator== on doubles isn't usually a good idea, although it may be okay in the TestSpike case as you know you've assigned exactly 1.0 to it previously.

I would write GenerateSpike as follows:

void GenerateSpike(Complex* data, int length) {
  std::fill(data, data+length, 0.0);
  if (length &gt;= 2)
    data[1] = 1.0;
}


By the way, you're not checking that the array is of sufficient length in TestSpike.

stepSize in FFT does not depend on the parameters of the second-outermost loop, so it should be in the outermost loop.  You should also use stepSize instead of bflySize/2 in the call to butterfly.

About testing:  w, butterfly, Reverse, and FFT all seem to be pure functions, so you can test them simply by checking the return value.  You might want to get a framework like GTest or Boost.Test to make them easier to write.