I am trying to use FFTw3 in Visual Studio using the Intel Fortran compiler. I am confused about normalization. I have setup a r2r spectral to grid plan for sinx siny components.
plan_spectral_to_grid_sin_sin = fftwf_plan_r2r_2d(Ny, Nx, dummy, dummy, FFTW_RODFT00, FFTW_RODFT00, FFTW_MEASURE)
plan_grid_to_spectral_sin_sin = fftwf_plan_r2r_2d(Ny, Nx, dummy, dummy, FFTW_RODFT00, FFTW_RODFT00, FFTW_MEASURE)
(Note the reversal of the x, y dimensions since this is a C library and FORTRAN is column-major)
I understand (maybe this is incorrect) that the normalization factor is
sin_sin_norm = (2.0 * REAL(currentDims%IXMAX + 1) * 2.0 * REAL(currentDims%IYMAX + 1))
So if I divide my spectral components A(k,l)sinkxsinly by this value and do the transform
call fftwf_execute_r2r(plan_spectral_to_grid_sin_sin, horzArr%G1, horzArr%G1)
I should be able to do the transform back
call fftwf_execute_r2r(plan_grid_to_spectral_sin_sin, horzArr%G1, horzArr%G1)
and get the original spectral components WITHOUT normalization. But that is not what I am seeing.
For reference
horzArr%G1 is a 2-d array of dimension currentDims%IXMAX, currentDims%IYMAX
1 Answer 1
Following the comment made by Martin Brown using the debugger and some modest code changes I found that taking
sin_sin_norm = (2.0 * REAL(currentDims%IXMAX + 1) * 2.0 * REAL(currentDims%IYMAX + 1))
I could set a spectral component horzArr%G1(2,2) = 1.0 / sin_sin_norm and do
call fftwf_execute_r2r(plan_spectral_to_grid_sin_sin, horzArr%G1, horzArr%G1)
followed by
call fftwf_execute_r2r(plan_grid_to_spectral_sin_sin, horzArr%G1, horzArr%G1)
and I would get my spectral component back. The AI I was using stated otherwise; normalization ahead of time was not sufficient. AI has been a great help (especially with syntaxes as you go from language to language and library to library) but one still has to be careful!
currentDims%IXMAXis and how it is related toNx. Try to show a minimal reproducible example.