2D Fourier transform- problems with the shift
显示 更早的评论
I have a 2D matrix representing a fluid's density field, I am trying to see if I can present it in an intelegent way with less parameters while maintaining key features. One of my thoughts was to represent it as a 2D fourier series and maintain only the leading spatial frequencies. I have written a code (attached) that performs an fft, sorts the terms based on their absolute values, and then adds them up from high to low to reconstruct the original field.
However, my reconstructed field is flipped. the corners and center are flipped. I am not sure why but it might be related to the fact that I used fftshit on the shifted data. I tried flipping it back by using fftshift again on the reconstructed field (or ifftshift), and it almost works, but not quite. you can see this by uncommenting line
would be thankful for any assistance!
Nathan
采纳的回答
更多回答(1 个)
William Rose
2024-11-1
0 个投票
Reconstructing the 2d DFT is a little tricky. The attached script uses the Nk largest components of the 2d DFT to reconstuct ther image. When Nk=10, it makes this:

When Nk=25, it makes this:

The inverse 2d DFT has very small non-zero imaginary parts, due to round-off error. Therefore I take the real part.
The code includes lines that reconstruct the full 2d DFT of the original image from the left half of its DFT. The image reconstructed this way is called rho1. You can edit the script to display rho1 instead of rho2. rho1 should exactly match the original, rho, and it appears to do so. The lines to make rho1 may help illustrate the symmetry of the 2d DFT.
I expect the script will fail if Nx or Ny is odd. You could add some if(...) lines to deal with this possibility, if necessary.
2 个评论
William Rose
2024-11-1
@nathan blanc, notice that my script does not use shift(). I think shift() is an unnecessary step that makes it harder to get the indexing right. By the way, due to symmetry of the 2d DFT of a real image, you can divide the 2d DFT top/bottom or left/right, and reconstruct one half from the other half. I chose to split left/right. I find the Nk largest components in one half. Then I build the other half, using the known symmetry of the 2d DFT of a real sequence.
Nathan Blanc
2024-11-3
类别
在 帮助中心 和 File Exchange 中查找有关 Bartlett 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
