ifft on gpu returns wrong values

2 views (last 30 days)
Mojtaba Zarei
Mojtaba Zarei on 30 Mar 2021
Commented: Mojtaba Zarei on 30 Mar 2021
I wanted to calculate a 2D FFT on a 3D array and then get the 2D IFFT back. I wanted to use the gpuArray to accelerate the implementation, and I am not sure why I am getting the wrong answer when I have the 3D array on the gpu. For example:
A = fft2(gpuArray(rand(10,10,5)));
A1 = ifft2(A);
A2 = ifft(ifft(A,[],2),[],1);
all(A1==A2,'all')
gpuArray logical
0
A1 = ifft2(gather(A));
A2 = ifft(ifft(gather(A),[],2),[],1);
all(A1==A2,'all')
logical
1
The reason that I used ifft(ifft(A,[],2),[],1) is that I am going to extend the code for a 4D array, and I could not use FFTn to perform a 3D FFT on the first three dimensions! But, when I wanted to get a 3D FFT and then a 3D IFFT using 1d FFT/IFFT, I noticed different GPU and CPU results. Would you please explain what I am doing wrong here?

Accepted Answer

Matt J
Matt J on 30 Mar 2021
Edited: Matt J on 30 Mar 2021
Your criterion for agreement is too strong:
A = fft2(gpuArray(rand(10,10,5)));
A1 = ifft2(A);
A2 = ifft(ifft(A,[],2),[],1);
>> max(abs(A1-A2),[],'all')
ans =
3.3529e-16
  6 Comments
Matt J
Matt J on 30 Mar 2021
Edited: Matt J on 30 Mar 2021
Also, if your input has conjugate symmetry, it will be beneficial to use ifft(Y,[],dim,'symmetric') .
Mojtaba Zarei
Mojtaba Zarei on 30 Mar 2021
Yes, but it is not! Thank you for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!