title: GSL Fast-Fourier Transform - Nonsense Output
body: <p>The Fourier transform of a gaussian is a gaussian, but for some reason the fast Fourier transform library from GSL (GNU scientific library) doesn't give this at all. I've included the code I've used to generate the (attempted) Fourier transform, and two relevant plots right after it. <strong>Could help me identify what I've messed up?</strong></p>
  
  <pre><code>#include &lt;gsl/gsl_fft_complex.h&gt;
  #include &lt;fstream&gt;
  
  #define REAL(z,i) ((z)[2*(i)]) //complex arrays stored as    
  #define IMAG(z,i) ((z)[2*(i)+1])
  
  using namespace std;
  
  int main(){
  
  double N = pow(2,9); //power of 2 for Cooley-Tukey algorithm
  int n = (int) N;
  
  double f[2*n];
  double dx = 10./N;
  double x = -5.;
  ofstream fileo("out.txt");
  
  for (int i=0; i&lt;n; ++i){      //initialize gaussian
      REAL(f,i)=exp(-0.5*x*x);  
      IMAG(f,i)=0.;
      x+=dx;
     }
  
     gsl_fft_complex_radix2_forward(f, 1, n);  //Fourier transform
  
     for (int i=0; i&lt;n; ++i){
          fileo&lt;&lt;i&lt;&lt;" "&lt;&lt;REAL(f,i)&lt;&lt;'\n';  //plot frequency distribution
     }
  
     fileo.close();
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yWa2I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yWa2I.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/31smO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/31smO.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>EDIT: Solved!</strong></p>
  
  <p>As stated in @roadrunner66's answer, the width of the original Gaussian was very broad, leading to a ridiculously narrow Gaussian in Fourier space. Moreover, my plot looked funky because, as suggested in @n.m's (now removed) comment, the Fourier transform returns the DFT with projections onto k-values indexed as k=0,1,...,N/2,-N/2,...-2,-1.</p>
  
  <p><a href="https://i.stack.imgur.com/icqtZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/icqtZ.png" alt="enter image description here"></a></p>