-1

I have 3D real data, say, 64 * 64 * 64 real data points, and I want to do a 3D Fourier transform. Specifically, I want to do DFT (exponential transform, containing both sine and cosine terms) on two of the three dimensions and DCT (discrete cosine transform) on the third dimension. The reason why I want to do this is because I'm solving partial differential equations (PDEs) where I want to impose periodic boundary condition in two directions while Neumann boundary condition in the third direction. To achieve this, I want to use fftw_plan_r2r_3d in FFTW, in which the DFT is done by R2HC who outputs data in the halfcomplex format. However, FFTW manual explicitly mentions that multiple R2HC is not recommended:

enter image description here

So now I need to figure out how to interpret the output and reconstruct the correct coefficients after the transform.

Just to make it a bit simpler, I will first ignore the DCT in the third dimension and just consider now 2D R2HC transform. My way to try to understand it is to compare the 2D R2HC transform to a 2D R2C transform. Take 4*4 case as an example, using some synthesized real space data and transform it using R2C without truncation (FFTW truncates it because there is some symmetry if the real space data is purely real and thus some data are redundant) we have:

enter image description here

where the data points related through complex conjugate are boxed by the same colour (except for the first row and column for which I did not draw box). As we can see here, due to the symmetry, you only need one of the two data points with the same colour to get all the information required to reconstruct the whole data. Due to this reason, FFTW truncates the last dimension of the data outputted by multidimensional r2c transform from N to N/2+1, and in our simple example that is:

enter image description here

For R2HC transform, the halfcomplex format means that the truncated coefficients are stored in a double-type array where the real and imaginary parts are separated and arranged in some order (introduced in FFTW manual). The data outputted by 2D R2HC looks like:

enter image description here

And now if I compare 2D R2HC to 2D r2c, problem comes. In 2D R2HC transform, the output coefficients are truncated in both dimensions, and if we try to visualize it in the equivalent way to r2c transform, it's like:

enter image description here

We can see that the two yellow (or orange) boxes are both gone. In this case, when I try to use the output from R2HC to reconstruct the whole coefficients, I can sorta successfully get all the values by combining different pieces except for the one in yellow box (I guess, in my understanding, that makes sense because two yellow boxes are both gone). However, if I call the reverse transform (2D HC2R) and normalize it, the real space data is fully recovered, which means all the information are still preserved. So that means I should be able to reconstruct the yellow one as well it's just I don't know how (due to my lack of understanding of the symmetry in dft).

Now, I wonder how I could reconstruct all the correct coefficients from the raw output of 2D R2HC transform so that I can then use them in solving the PDEs.

Dennis
  • 109
  • 2
  • How much compute time do you expect you'll save by using a 2D R2HC transform over a regular R2C transform? Take their advice, use the R2C transform. It basically does what you are trying to do: it computes the missing components from the computed ones for you. – Cris Luengo Mar 20 '23 at 16:51
  • @CrisLuengo I think the reason that I need to use 2D R2HC is because I want to then add a DCT in the third dimension as stated in the post. R2C gives you output in FFTW_COMPLEX but to use DCT you need DOUBLE. If there's a way to get round this, it'll be great too.. – Dennis Mar 20 '23 at 16:56
  • I don't understand the combination of DCT and DFT, what does the DCT of Fourier coefficients mean? If it's separable (like the DFT, which can be computed on each dimension in turn, and the order of computation is irrelevant) then you could compute the 1D DCT on the real input data first, then compute a R2C FFT on the other two dimensions. But since I don't understand the goal, I can't really advice in this regard. – Cris Luengo Mar 20 '23 at 17:02
  • @CrisLuengo My understanding is that just like one can do 3D DFT and also 3D DCT or DST, one can also mix them in different dimensions, and the resultant coefficients should be the same regardless the order of performing them. I think the plan `fftw_plan_r2r_3d` in FFTW is designed specifically for this situation where one has mixed transforms and the required input `kind0`, `kind1` and `kind2` by `fftw_plan_r2r_3d` are used to specify which transform one wants to do in each of these dimensions. – Dennis Mar 20 '23 at 17:49

1 Answers1

0

Just by looking at the 4x4 real numbers you produce, which we name like this:

m11  m21  m31  m41
m12  m22  m32  m42
m13  m23  m33  m43
m14  m24  m34  m44

We can see that the complex output is:

m11           m21 + m41·i   m31           m21 + m41·i
m12 + m14·i   A             m32 + m34·i   B
m13           m23 + m43·i   m33           m23 + m43·i
m12 + m14·i   B             m32 + m34·i   A

with

A = (m22 - m44) + (m24 + m42)·i
B = (m22 + m44) + (m24 - m42)·i

How this generalizes to larger array sizes I don't know, but it looks like there's a pattern.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • That's an interesting observation! Maybe this results from the symmetry and it's how the coefficients could be reconstructed? I will check if it's correct for higher dimensions, Thanks! – Dennis Mar 20 '23 at 17:51