Is there a difference in the output values of the functions fft vs fft2 vs fftn
10 views (last 30 days)
Show older comments
Anthony Hosein
on 17 Jun 2022
Commented: Anthony Hosein
on 17 Jun 2022
When applying an FFT to a 3D matrix will the information in the output be different if one were to apply fftn to the entire matrix or if one were to use an fft2 on each slice of the 3D matrix and then stack up the output?
If one were to use the second approach would it be valide to directly compare the magnitudes in one slice with those from another, or would the relative magnitudes between frequency peaks only be valide within any given slice unless a normalization is applied?
To take it one step further if one were to apply a 1D fft on each dimension of a slice how could the two outputs be combined to produce the output provided by an fft2.
The documentation for fftn states "The N-D transform is equivalent to computing the 1-D transform along each dimension of X."
But I am unclear as to how the output of 1D transforms could be combined to give the output of the fft2 or fftn transforms, and if the multidimensional transforms offer any advantages.
0 Comments
Accepted Answer
Walter Roberson
on 17 Jun 2022
For a 3d matrix, the code for fft2 is literally
fft(fft(x,[],2),[],1)
For a 2d matrix, fft2 calls fftn
The only remaining question is then whether calling that above fft code on a 2d array will give you the same result as calling fftn. The answer is that mathematically they are the same, but that fftn calls into a highly optimized multi-threaded library that might do operations in a different order and so might lead to slightly different roundoff. Just like 0.1+0.2-0.3 leads to different roundoff than 0.1-0.3+0.2
3 Comments
Walter Roberson
on 17 Jun 2022
They are directly comparable under the assumption that the means are the zero (and possibly other circumstances that I would have to think about more.)
However, there are cases where it can make sense to normalize the power first.
More Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!