title: Calculating correlation with FFT between two signals
body: <p>I am having a problem getting a correct result for a correlation between two sets of values (I know the results are wrong because I've tried calculating the correlation in Octave)(also I'm calculating like the <a href="https://dsp.stackexchange.com/questions/736/how-do-i-implement-cross-correlation-to-prove-two-audio-files-are-similar">post</a> says).
  I've been using a library I found that's written in C  that's found on: <a href="http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html" rel="nofollow noreferrer">http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html</a></p>
  
  <p>The documentation for it is rather scarce and I don't have much experience in calculating FFT.</p>
  
  <p>An example of the program's results and the results from Octave are following:</p>
  
  <p>The two vectors are:
  a = [1 2 1 1 0 0 0 0], b = [0 0 0 0 1 3 1 1]</p>
  
  <p>the results for fft of the vector a and b on Octave are:</p>
  
  <p><a href="https://i.stack.imgur.com/1wq3k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1wq3k.png" alt="fft-octave"></a></p>
  
  <p>While the results of fft of the same vectors are (divided into real and imaginary numbers):</p>
  
  <p><a href="https://i.stack.imgur.com/hzzUJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hzzUJ.png" alt="result from C lib function"></a></p>
  
  <p>The output of the function is originally:</p>
  
  <p>5
  -1
  1.70711
  3.12132
  0
  1
  0.292893
  1.12132</p>
  
  <p>(the division into real and imaginary numbers was done how it was specified in the documentation)</p>
  
  <p><a href="https://i.stack.imgur.com/idEfo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/idEfo.png" alt="enter image description here"></a></p>
  
  <p>Now my problem starts when i multiply (I'm using element-wise multiplication) the two vectors that contain results from the DFT (I'm using Real DFT) since the results from Octave are different than the result of my program</p>
  
  <p><a href="https://i.stack.imgur.com/3DItV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3DItV.png" alt="Octave result"></a></p>
  
  <p>my multiplication code is:</p>
  
  <pre><code>for (j = 0; j &lt; n; j++) {
      a[j] = a[j] * b[j];
  }
  </code></pre>
  
  <p>and the result is:</p>
  
  <p><a href="https://i.stack.imgur.com/m7bFI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m7bFI.png" alt="multiplication of output of rdft function from lib"></a></p>
  
  <p><a href="https://i.stack.imgur.com/16quG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/16quG.png" alt="formatted result"></a></p>
  
  <p>This is the point where I'm stuck at the moment.</p>