title: GSL Fast-Fourier Transform - Non-zero Imaginary for Transformed Gaussian?
body: <p>As an extension to <a href="https://stackoverflow.com/questions/37014966/gsl-fast-fourier-transform-double-valued-gaussian">this question</a> that I asked. The Fourier transform of a real Gaussian is a real Gaussian. Now of course a DFT of a set of points that only resemble a Gaussian will not always be a perfect Gaussian, but it should certainly be close. In the code below I'm taking this [discrete] Fourier transform using GSL. Aside from the issue of the returned/transformed real components (outlined in linked question), I'm getting a weird result for the imaginary component (which should be identically zero). Granted, it's very small in magnitude, but its still weird. <strong>What is the cause for this asymmetric &amp; funky output?</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;gsl/gsl_fft_complex.h&gt;
  #include &lt;gsl/gsl_errno.h&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt; 
  
  #define REAL(z,i) ((z)[2*(i)]) //complex arrays stored as    [Re(z0),Im(z0),Re(z1),Im(z1),...]
  #define IMAG(z,i) ((z)[2*(i)+1])
  #define MODU(z,i) ((z)[2*(i)])*((z)[2*(i)])+((z)[2*(i)+1])*((z)[2*(i)+1])
  #define PI 3.14159265359
  
  using namespace std;
  
  int main(){
  
      int n = pow(2,9);
      double data[2*n];
      double N = (double) n;
  
      ofstream file_out("out.txt");
  
      double xmin=-10.;
      double xmax=10.;
      double dx=(xmax-xmin)/N;
      double x=xmin;
  
      for (int i=0; i&lt;n; ++i){
          REAL(data,i)=exp(-100.*x*x);
          IMAG(data,i)=0.;
          x+=dx;
      }
  
      gsl_fft_complex_radix2_forward(data, 1, n); 
  
      for (int i=0; i&lt;n; ++i){
          file_out&lt;&lt;(i-n/2)&lt;&lt;"    "&lt;&lt;IMAG(data,((i+n/2)%n))&lt;&lt;'\n';
      }
  
      file_out.close();
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pCufd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pCufd.png" alt="enter image description here"></a></p>