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?

 채택된 답변

Matt J
Matt J 2021년 3월 30일
편집: Matt J 2021년 3월 30일

0 개 추천

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

Mojtaba Zarei
Mojtaba Zarei 2021년 3월 30일
I see! BTW, would you please guide me if you know any other way which might be faster than ifft(ifft(A,[],2),[],1) to perform fft/ifft on the first n dimension of an n+1 dimension array?
Matt J
Matt J 2021년 3월 30일
No, I think that is the fastest.
Walter Roberson
Walter Roberson 2021년 3월 30일
there is ifft2() but it ends up doing multiple ifft. I seem to recall some transposes, so hypothetically it could be faster to transpose/permute to be ifft along the first dimension each time, might allow more efficient vectorization potentially.
Mojtaba Zarei
Mojtaba Zarei 2021년 3월 30일
Yes, for 2d, I used ifft2, but it seems a series of ifft/fft is the most efficient way for a bigger dimension.
Matt J
Matt J 2021년 3월 30일
편집: Matt J 2021년 3월 30일
Also, if your input has conjugate symmetry, it will be beneficial to use ifft(Y,[],dim,'symmetric') .
Mojtaba Zarei
Mojtaba Zarei 2021년 3월 30일
Yes, but it is not! Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2021a

질문:

2021년 3월 30일

댓글:

2021년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by