title: Discrepency in Matlab FFT and Fortran Rosetta Code FFT
body: <p>I copied the example of resettacode's from</p>
  
  <p><a href="http://rosettacode.org/wiki/Fast_Fourier_transform#Fortran" rel="nofollow">http://rosettacode.org/wiki/Fast_Fourier_transform#Fortran</a></p>
  
  <pre><code>module fft_mod
    implicit none
    integer,       parameter :: dp=selected_real_kind(15,300)
    real(kind=dp), parameter :: pi=3.141592653589793238460_dp
  contains
  
    ! In place Cooley-Tukey FFT
    recursive subroutine fft(x)
      complex(kind=dp), dimension(:), intent(inout)  :: x
      complex(kind=dp)                               :: t
      integer                                        :: N
      integer                                        :: i
      complex(kind=dp), dimension(:), allocatable    :: even, odd
  
      N=size(x)
  
      if(N .le. 1) return
  
      allocate(odd((N+1)/2))
      allocate(even(N/2))
  
      ! divide
      odd =x(1:N:2)
      even=x(2:N:2)
  
      ! conquer
      call fft(odd)
      call fft(even)
  
      ! combine
      do i=1,N/2
         t=exp(cmplx(0.0_dp,-2.0_dp*pi*real(i-1,dp)/real(N,dp),kind=dp))*even(i)
         x(i)     = odd(i) + t
         x(i+N/2) = odd(i) - t
      end do
  
      deallocate(odd)
      deallocate(even)
  
    end subroutine fft
  
  end module fft_mod
  
  program test
    use fft_mod
    implicit none
    complex(kind=dp), dimension(8) :: data = (/1.0, 1.0, 1.0, 1.0, 0.0, 
  
  0.0, 0.0, 0.0/)
    integer :: i
  
    call fft(data)
  
    do i=1,8
       write(*,'("(", F20.15, ",", F20.15, "i )")') data(i)
    end do
  
  end program test
  </code></pre>
  
  <p>and ran the code. As is, results match a simple input to matlab R2008a:</p>
  
  <pre><code>fft([1 1 1 1 0 0 0 0]')
  
  ans =
  
     4.0000          
     1.0000 - 2.4142i
          0          
     1.0000 - 0.4142i
          0          
     1.0000 + 0.4142i
          0          
     1.0000 + 2.4142i
  </code></pre>
  
  <p>But using a different data set, for example (in Matlab):</p>
  
  <pre><code>fft((1:10)')
  
  ans =
  
    55.0000          
    -5.0000 +15.3884i
    -5.0000 + 6.8819i
    -5.0000 + 3.6327i
    -5.0000 + 1.6246i
    -5.0000          
    -5.0000 - 1.6246i
    -5.0000 - 3.6327i
    -5.0000 - 6.8819i
    -5.0000 -15.3884i
  </code></pre>
  
  <p>The Fortran rosettacode yields</p>
  
  <pre><code>(  55.000000000000000,   0.000000000000000i )
  (   9.854101966249685,   4.081740616606390i )
  (   6.854101966249685,  -5.706339097770921i )
  (   0.381966011250106,  -9.510565162951536i )
  (   0.909830056250527,  -5.877852522924733i )
  (  -5.000000000000000,   0.000000000000000i )
  (  -2.326237921249264,   3.526711513754838i )
  (   3.145898033750315,   5.706339097770921i )
  (  12.090169943749473,   1.902113032590309i )
  (  17.090169943749473,   5.877852522924733i )
  </code></pre>
  
  <p>The Rosettacode line were the data initialized was</p>
  
  <pre><code> complex(kind=dp), dimension(10) :: data = (/1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0/)
  </code></pre>
  
  <p>And the do-loop was extended to</p>
  
  <pre><code>  do i=1,10
  </code></pre>
  
  <p>So my question is: is the data ill conditioned? Or is one of them wrong? Matlab claims to use the same algorithm, so I'm stuck not being sure.</p>