如何从 2d FFT 计算波数域坐标
我有一个复数二维数组,表示沿真实空间中的平面测量的势场。假设该阵列为 128 个单元 x 128 个单元,平面的总面积为 500m x 500m。该数组中的每个单元代表空间域中的一个点,其坐标以 x 和 y 给出。
当我在这个二维数组上使用 scipy.fftpack 的二维 FFT 时,我得到了波域中表示的相同信息。如何计算输出阵列点的波域坐标 kx 和 ky?
I have a 2d Array of complex numbers that represent a potential field measured along a plane in real space. Lets say that the array is 128 cells by 128 cells and the the total area of the plane is 500m x 500m. Each cell in this array represents a point in the spatial domain with co-ordinates given in x and y.
When I use the 2d FFT from scipy.fftpack on this 2d array I get the same information represented in the wave domain. How do I calculate the wave domain co-ordinates kx and ky for the points the output array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一些代码来充分演示问题和我能够找到的解决方案。
我知道这可能不是最有效的方法,但希望它很容易理解。我希望这可以帮助人们避免一点挫折。
Here is some code to fully demonstrate the problem and the solution I was able to find.
I know this is likely not the most efficient way of doing this, but hopefully it is easy to understand. I hope this helps someone avoid a little frustration.
嗯,看来如果我使用 FFT 函数,DC 最终会出现在零元素处,在您的情况下,频率之间的间距也是 1/500m。因此,以下(不是很简洁)片段将获得您的频率轴:
当然,这些频率的单位是每米周期,而不是每米弧度。如果我希望 kx 和 ky 是以拉德/米为单位的空间频率数组,我只会说
(假设我已经导入了 arange 和 pi 等内容)。
编辑
Stu对高于奈奎斯特的频率提出了很好的观点,您可能更愿意将其视为负值(我通常这样做,但不在代码中)。你总是可以这样做:
但如果你真的想要负频率,你可能还想玩一下 fftshift——另一堆蠕虫。
Hmm, it seems if I use the FFT function, that DC ends up at element zero, also in your case the spacing between frequencies is 1/500m. Thus the following (not very concise) snippet will get your frequency axis:
Naturally these frequencies are in cycles-per-meter, not radians-per-meter. If I wanted kx and ky to be arrays of spatial frequencies in rads/meter I would just say
(Assuming I have imported in things like arange, and pi already).
edit
Stu makes a good point about frequencies above the Nyquist, which you might prefer to think of as negative (I usually do, but not in the code). You can always do:
But if you really want negative frequencies you might also want to play with fftshift, as well -- another can of worms.
我在下面的 FORTRAN 代码中找到了子例程,并尝试将其实现为 matlab 函数。请大家评论我的翻译是否正确。
开始吧,这是 FORTRAN 子程序:
我翻译成 MATLAB 函数:
谢谢。
I found subroutine in FORTRAN code below, and try to implemented it as matlab function. Please give me a comment whether my translation is right.
Here we Go, This is FORTRAN subroutine :
I translate to MATLAB function :
Thank you.