Comparing MATLAB ifft result to C FFTW result
5 views (last 30 days)
Show older comments
I am converting a MATLAB script into C code, and I am having a trouble understanding why my C results dont match more accurately my MATLAB results.
Specifically, I have an iterative process that computes the IFFT of a 2D array for each step. The result of the IFFT is used to compute the values of the 2D array for the next step. My problem is that the C results are on the order of E-07 different from my MATLAB results. As you can imagine, this deviation only gets worse over iterations.
I dont understand the difference I am seeing. My C code is using doubles, and I believe they are in the same internal format as MATLAB doubles. I've also done stand alone tests on IFFT (using junk data) and compared the results to C using FFTW -- in these cases, the difference is only E-17.
My only suspect at the moment is the MATLAB IFFT call is like:
z2 = iff(z1, P, 1);
Where z1 is a 57x3648 matrix, and P is 256.
I know that MATLAB uses FFTW, but I am wondering if it formats the input data or internal call to FFTW differently than I do in C.
In C, I take the first 57 elements and put them into a tempory vector of size 256 whose elements 58 and higher are all zero. I then execute a plan that calls for a 256 point transform on that temporary vector. I then divide each element of the resulting vector by 256 (as required by FFTW documentation).
As mentioned, the C result differs from the MATLAB result by E-07 -- and I am at a loss to explain why.
0 Comments
Answers (1)
Brani Dzepina
on 10 May 2018
Is it perhaps the scaling factor. You can read about it on the FFTW docs page http://www.fftw.org/fftw2_doc/fftw_2.html#SEC5
0 Comments
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!