fftn, fftshift and interp3
Show older comments
In short, I'm trying to take the FT (FT_shape) of a 3D binary shape (shape), use interp3 on the resulting complex array (distorted_FT_shape), and apply an inverse FT to recover a "distorted" version of the shape (distorted_shape).
This, in theory, should work:
FT_shape = fftshift(fftn(shape));
distorted_FT_shape = interp3(Xgrid, Ygrid, Zgrid, FT_shape, rel_x, rel_y, rel_z,'linear',0);
distorted_shape = ifftn(ifftshift(distorted_FT_shape));
However, distorted_shape doesn't give me a "shape" when plotted. It appears I need an additional fftshift and ifftshift when taking the ffn and ifftn as follows:
FT_shape = fftshift(fftn(fftshift(shape)));
distorted_FT_shape = interp3(Xgrid, Ygrid, Zgrid, FT_shape, rel_x, rel_y, rel_z,'linear',0);
distorted_shape = ifftshift(ifftn(ifftshift(distorted_FT_shape)));
The second set of lines gives me a real, distorted shape as expected, but the additional fftshift and ifftshift do not make sense according to the MATLAB documentation. Can someone please explain why?
Additional info:
shape: a 256x256x256 zero array with a "blob" of ones size 128x128x128 about the centre of the array
Xgrid, Ygrid, Zgrid: meshgrid(-(256-1)/2:(256-1)/2, -(256-1)/2:(256-1)/2, -(256-1)/2:(256-1)/2)
rel_x, rel_y, rel_: rotated Xgrid, Ygrid, Zgrid
I'm doing X-ray diffraction research, so I need to "distort" things in the reciprocal space, for those wondering
Accepted Answer
More Answers (0)
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!