I am trying out different FFT solvers, with two of them being FFTW (fftw version 3.3.3.8, https://www.fftw.org/index.html) and FAST FFT ( https://www.kurims.kyoto-u.ac.jp/~ooura/fft.html).
I am using DCT/inverse DCT to accomplish the following:
(1) solve a discrete Poisson equation on an NxN map => result is same between FFTW, FFT
(2) I multiply the DCT result with the wave numbers to obtain the two spectral derivatives (in x and y) and compare with the numerical derivatives of the Poisson Equation solution (latter computed using finite differences).
My issue is that (2) gives me a different result when I try FFTW. The spectral gradient is inverted and goes negative for 1/2 of the map.
I am multiplying the 2D map grid points with pi x i/N (wavelets), where i is the index of the square (in x and y). I also tried multiplying the 2nd half by pi x (i - (N - 1))/N and combinations thereof, to "corrrect" the result, but did not make any progress.
Code is 100% identical for both FFT, FFTW.
Result looks perfect with FAST FFT code I used (https://www.kurims.kyoto-u.ac.jp/~ooura/fft.html), but perturbed with FFTW. I am sure it is something to do with the coefficients and what FFTW expects/orders frequencies?
Any idea why this happens?
I attach two screenshots showing the FFTW, FFT spectral gradient result against the numerical gradient (identical for both as the poisson solution is indeed identical).
FFTW x-coord spectral gradient vs x-coord Numerical gradient
Fast FFT x-coord spectral gradient vs x-coord Numerical gradient