简体   繁体   English

将fft / fft2的返回值应用于矩阵有什么区别?

[英]What is the difference between the return of fft / fft2 applied to a matrix?

In the following program, I would like to compute the fast Fourier transform of a given field given by U. what is the difference between the returned values for fft and for fft2? 在下面的程序中,我想计算U给定的给定字段的快速傅立叶变换。fft和fft2的返回值之间有什么区别? Any help would be appreciated! 任何帮助,将不胜感激! Thank you. 谢谢。

import numpy as np
from numpy import sin, cos, pi

nx=3
ny=3

px=2*pi
py=2*pi

qx=1.0*px/(nx-1)
qy=1.0*py/(ny-1)

x = np.linspace(0,px,nx)
y = np.linspace(0,py,ny)

X,Y = np.meshgrid(x,y)

U=cos(X)*sin(Y)

#compite fft's
Uh1=np.fft.fft(U)

Uh2=np.fft.fft2(U)

print('For fft')
print(Uh1)

print('For fft2')
print(Uh2)

#What is the difference between Uh1 and Uh2? Thank you!

Here is what I get: 这是我得到的:

For fft
[[  0.00000000e+00 +0.00000000e+00j   0.00000000e+00 +0.00000000e+00j
0.00000000e+00 +0.00000000e+00j]
[  1.22464680e-16 +0.00000000e+00j   1.22464680e-16 +2.12115048e-16j
1.22464680e-16 -2.12115048e-16j]
[ -2.44929360e-16 +0.00000000e+00j  -2.44929360e-16 -4.24230095e-16j
-2.44929360e-16 +4.24230095e-16j]]
For fft2
[[ -1.22464680e-16 +0.00000000e+00j  -1.22464680e-16 -2.12115048e-16j
-1.22464680e-16 +2.12115048e-16j]
[  6.12323400e-17 -3.18172572e-16j   6.12323400e-16 -2.12115048e-16j
-4.89858720e-16 -4.24230095e-16j]
[  6.12323400e-17 +3.18172572e-16j  -4.89858720e-16 +4.24230095e-16j
6.12323400e-16 +2.12115048e-16j]]

Thank you! 谢谢!

docstring of the np.fft module. np.fft模块的文档字符串。

Standard FFTs
-------------

.. autosummary::
   :toctree: generated/

   fft       Discrete Fourier transform.
   ifft      Inverse discrete Fourier transform.
   fft2      Discrete Fourier transform in two dimensions.
   ifft2     Inverse discrete Fourier transform in two dimensions.
   fftn      Discrete Fourier transform in N-dimensions.
   ifftn     Inverse discrete Fourier transform in N dimensions.

Plotting the two matricies gives this if you wan't to visualize the differences. 如果您不想可视化差异,则绘制两个矩阵可以得出此结果。 I do not know enough about fft's to even know if it makes any sense to plot them this way. 我对fft的了解不足,甚至不知道以这种方式绘制它们是否有意义。

在此处输入图片说明

在此处输入图片说明

plt.figure()

plt.subplot(2,2,1)
plt.plot(Uh1.real.ravel())
plt.title("1 - real")
plt.subplot(2,2,2)
plt.plot(Uh2.real.ravel())
plt.title("2 - real")

plt.subplot(2,2,3)
plt.plot(Uh1.imag.ravel())
plt.title("1 - imaginary")
plt.subplot(2,2,4)
plt.plot(Uh2.imag.ravel())
plt.title("2 - imaginary")

plt.figure()

plt.subplot(2,2,1)
plt.hist(Uh1.real.ravel())
plt.title("1 - real")
plt.subplot(2,2,2)
plt.hist(Uh2.real.ravel())
plt.title("2 - real")

plt.subplot(2,2,3)
plt.hist(Uh1.imag.ravel())
plt.title("1 - imaginary")
plt.subplot(2,2,4)
plt.hist(Uh2.imag.ravel())
plt.title("2 - imaginary")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM