I'm trying to implement the Matlab fft2() function in C using the FFTW3 library.
However, I've got different results.
Considering the next matrix:
Z=[
0.4791 0.4765 0.4791 0.4765 0.4791 0.4765 0.4791 0.4765
0.4798 0.4695 0.4798 0.4695 0.4798 0.4695 0.4798 0.4695
0.4791 0.4765 0.4791 0.4765 0.4791 0.4765 0.4791 0.4765
0.4798 0.4695 0.4798 0.4695 0.4798 0.4695 0.4798 0.4695
0.4791 0.4765 0.4791 0.4765 0.4791 0.4765 0.4791 0.4765
0.4798 0.4695 0.4798 0.4695 0.4798 0.4695 0.4798 0.4695
0.4791 0.4765 0.4791 0.4765 0.4791 0.4765 0.4791 0.4765
0.4798 0.4695 0.4798 0.4695 0.4798 0.4695 0.4798 0.4695
....
]
And using the following code:
Z-> Double*
fftw_complex* fft2;
fft2 = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*Samples*(Lines));
fftw_plan p1;
p1 = fftw_plan_dft_r2c_2d(Lines,Samples, Z, fft2, FFTW_ESTIMATE);
fftw_execute(p1);
The results with Matlab:
fft2= [
5534,25859596829 + 0,00000000000000i 186,747610745237 - 529,515274347496i
42,6452471730436 - 321,074636721419i -21,4495750160608 - 190,407528614266i
-50,3875107145668 - 50,5480303619799i 30,1151029075525 + 378,240946095017i
-196,295569635431 + 228,972218925794i 35,6434356803659 - 5,46216875816971i
36,2702126322693 - 38,5502177293316i 18,5093049539101 - 33,4608602804025i
....
]
The results with my C code:
5534.260423 + 0.000000 i 186.731496 + -529.495788 i
42.655319 + -321.068356 i -21.425010 + -190.382717 i
-50.277195 + -50.384210 i 29.909846 + 377.823957 i
-195.767224 + 228.693862 i 35.241375 + -5.315382 i
36.134134 + -38.527643 i 18.406395 + -33.467351 i
....
]
What am I doing wrong?