在下面的程序中,我想计算由U给出的给定字段的快速傅里叶变换.fft和fft2的返回值之间有什么区别?任何帮助,将不胜感激!谢谢。
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!
这是我得到的:
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]]
谢谢!
答案 0 :(得分:2)
np.fft模块的docstring。
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.
如果您想要想象差异,那么绘制这两个基质会给出这个。我对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")