Effcient way to do FFT shift in matlab (without us

2019-05-22 22:16发布

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

2条回答
一纸荒年 Trace。
2楼-- · 2019-05-22 22:34

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.

查看更多
闹够了就滚
3楼-- · 2019-05-22 22:56

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.

查看更多
登录 后发表回答