title: How to FFT a sound array correctly?
body: <p>I am trying to get a list of frequencies present in an input audio sample. It seems I need to do an FFT to get this result, but I get odd answers when I FFT it (using FFTW): I get arrays containing mostly zeros with a few impossibly large elements (300+ digits!) - and these large numbers are always in the same place (5 places from the end, 46 places from the end and a few others that show up sporadically) whether I change the frequency of the input tone or even if I change the sample length for the FFT. What am I doing wrong? Here is my code:</p>
  
  <pre><code>#include &lt;fftw3.h&gt;
  #include &lt;sndfile.h&gt;
  #include &lt;math.h&gt;
  #include &lt;algorithm&gt;    
  
  int main (int argc, char * argv []) {
      char        *infilename ;
      SNDFILE     *infile = NULL ;
      FILE        *outfile = NULL ;
      SF_INFO     sfinfo ;
  
      infile = sf_open("test.wav", SFM_READ, &amp;sfinfo);
  
      int N = pow(2, 10);
      double samples[N];
  
      sf_read_double(infile, samples, 1);
  
      fftw_complex out[N];
      fftw_plan p;
      p = fftw_plan_dft_r2c_1d(N, samples, out, FFTW_ESTIMATE);
  
      fftw_execute(p);
      fftw_destroy_plan(p); 
  
      for (int i=0; i&lt;N; i++) {
          printf("%f %f\n", out[i][0], out[i][1]);
      }
  
      sf_close (infile) ;
  
      return 0 ;
  }
  </code></pre>