我有x-y-z形式的數據並想要創建沿x-y的功率譜。下面是我張貼檢查,我會用我的實際數據是想錯了一個基本的例子:2d fft numpy/python混淆
import numpy as np
from matplotlib import pyplot as plt
fq = 10; N = 20
x = np.linspace(0,8,N); y = x
space = x[1] -x[0]
xx, yy = np.meshgrid(x,y)
fnc = np.sin(2*np.pi*fq*xx)
ft = np.fft.fft2(fnc)
ft = np.fft.fftshift(ft)
freq_x = np.fft.fftfreq(ft.shape[0], d=space)
freq_y = np.fft.fftfreq(ft.shape[1], d=space)
plt.imshow(
abs(ft),
aspect='auto',
extent=(freq_x.min(),freq_x.max(),freq_y.min(),freq_y.max())
)
plt.figure()
plt.imshow(fnc)
這將導致以下function & frequency數字與不正確的頻率。謝謝。
'插值='nearest''會讓你的結果更加清晰 – Eric