Effcient way to do FFT shift in matlab (without using fftshift function)

无人久伴 提交于 2019-12-08 01:41:06

问题


http://www.mathworks.com/help/techdoc/ref/fftshift.html

If you check that link - thats what I want to do in the first picture - swap quadrants of a matrix.

However, I cant seem to think of a good way to do this without having several loops to pull out the relevant sub-matrices.

I need it to work with MxN matrices, where M and N can be any combination of even and odd.

Thanks


回答1:


If you enter type fftshift.m at MATLAB's command line, you'll see the source code for MATLAB's implementation of the function (use edit fftshift.m if you want to view it in the editor with syntax highlighting). I'm not posting the code here, as it is copyrighted. However, you can try it on your machine and re-implement the same in C. Its up to you to figure out the license terms etc, if you're into any of that.




回答2:


The following should work

sz = ceil(size(A)/2)
A = A([sz(1)+1:end, 1:sz(1)], [sz(2)+1:end, 1:sz(2)])

That only works for 2d matrices, but can be easily generalized to the Nd case.



来源:https://stackoverflow.com/questions/5735720/effcient-way-to-do-fft-shift-in-matlab-without-using-fftshift-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!