title: 3d c2c fft with fftw library
body: <p>I am trying to do a 3D FFT with the FFTW library, but I have some difficulties with the inverse transformation.</p>
  
  <p>At first I do the foreword transformation via:</p>
  
  <pre><code>fftwf_plan_dft_3d(_dimensions[0], _dimensions[1], _dimensions[2], (fftwf_complex*)_inputBuffer, (fftwf_complex*)_outputBuffer, FFTW_FORWARD, FFTW_ESTIMATE);
  </code></pre>
  
  <p>Although my data is real data I am using the complex to complex transformation, as want to 
  replace it later by an opencl fft which only supports complex to complex transformations.</p>
  
  <p>In 3D fourier space I do a very simple low pass filter:</p>
  
  <pre><code>for all x, y, z:
  
  // global position of the current bin
  int gid = (y * w + x) + (z * w * h);
  
  // position of the symmetric bin
  vec3 conPos(M - x - 1, N - y - 1, L - z - 1);
  
  // global position of the symmetric element
  int conGid = (conPos.y * w + conPos.x) + (conPos.z * w * h);
  
  if (sqrt(x * x + y * y + z * z) &gt; 500)
  {
      complex[gid].real = 0.0f;
      complex[gid].imag = 0.0f;
      complex[conGid].real = 0.0f;
      complex[conGid].imag = 0.0f;
  }
  </code></pre>
  
  <p>At last the inverse transformation:</p>
  
  <pre><code>fftwf_plan_dft_3d(_dimensions[0], _dimensions[1], _dimensions[2], (fftwf_complex*)_inputBuffer, (fftwf_complex*)_outputBuffer, FFTW_BACKWARD, FFTW_ESTIMATE);
  // normalization ...
  </code></pre>
  
  <p>The Result is not as I would expect it. After the inverse transformation the imaginary parts are not all zero as they are supposed to be.</p>
  
  <p>As far as I see it, after the forward transformation of real data only the half of the total buffer size is used and there are no conjugate complex values in the other half. (see: <a href="http://www.dspguide.com/ch12/1.htm" rel="nofollow">c2c with real data</a>) If this is the case I have to compute them on my own before the backward transformation, but I could not found a hint in the fftw docs which half is computed and which is not.</p>
  
  <p>I have written a very simple 2D-Test-Case to view this symmetry in the fourier space:</p>
  
  <pre><code>int w = 4;
  int h = 4;
  int size  = w * h;
  
  cl_float rawImage[16] = ...; // loading image
  
  fftwf_complex *complexImage = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * size);
  fftwf_complex *freqBuffer = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * size);
  
  for (int i = 0; i &lt; size; i++)
  {
      complexImage[i][0] = rawImage[i]; complexImage[i][1] = 0.0f;
  }
  
  fftwf_plan forward = fftwf_plan_dft_2d(w, h, complexImage, freqBuffer, FFTW_FORWARD, FFTW_ESTIMATE);
  
  fftwf_execute(forward);
  
  for (int y = 0; y &lt; h; y++)
  {
      for (int x = 0; x &lt; w; x++)
      {
          int gid = y * w + x;
          qDebug() &lt;&lt; gid &lt;&lt; "real:" &lt;&lt; freqBuffer[gid][0] &lt;&lt; "imag:" &lt;&lt; freqBuffer[gid][1];
      }
  }
  </code></pre>
  
  <p>This gives me the following output:</p>
  
  <pre><code>gid
  0    real 3060 imag 0 
  1    real 510 imag 510 
  2    real 0 imag 0 
  3    real 510 imag -510 
  4    real 510 imag 510 
  5    real 0 imag -510 
  6    real 0 imag 0 
  7    real -510 imag 0 
  8    real 0 imag 0 
  9    real 0 imag 0 
  10   real 0 imag 0 
  11   real 0 imag 0 
  12   real 510 imag -510 
  13   real -510 imag 0 
  14   real 0 imag 0 
  15   real 0 imag 510 
  </code></pre>
  
  <p>As far as I see it there are no symmetric values. Why?</p>
  
  <p>It would be nice if someone could give me a hint.</p>
  
  <p>Greetings</p>
  
  <p>Wolf</p>