所以我确实有两个数据数组:
Bx = [ -59.57011259 -74.20675537 -90.53224156 ..., -1676.9703173
-1676.9703173 -1676.9703173 ]
By = [ 1.48413511e+00 4.96417605e+00 8.39303992e+00 ..., -1.67697032e+03
-1.67697032e+03 -1.67697032e+03]
我有一个程序可以显示这些数据,但我需要在Python2.7中完成它。我尝试使用在本主题 ( Plotting a Fast Fourier Transform in Python ) 中找到的代码,但说实话,我在理解 FFT 方面遇到了困难,你能帮忙吗?
# Number of samples
N = 600
# Sample spacing
T = 300.0 / 266336
x = np.linspace(0.0, N*T, N)
y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
plt.plot(xf, 2.0/N * np.abs(yf[0:N/2]))
plt.grid()
plt.show()
有关我的数据的一些信息: 记录/样本数 266336; 时间300s = 300000ms
我还需要以某种方式实现布莱克曼或汉明窗,你能帮忙吗?
最佳答案
假设Bx
和By
是类似数组的,则可以通过*
运算符编写窗口。
import numpy as np
import matplotlib.pyplot as plt
# Number of samplepoints
N = 266336
# sample spacing
T = 300.0 / N
# Window
win = np.hamming(N)
x = np.linspace(0.0, N*T, N)
# y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
y = np.array(Bx)
y_win = win * y
yf = np.fft.fft(y_win)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
# Plot original data
ax = plt.subplot(3,1,1)
ax.grid()
ax.plot(y)
# Plot windowed data
ax = plt.subplot(3,1,2)
ax.grid()
ax.plot(y_win)
# Plot spectrum
ax = plt.subplot(3,1,3)
ax.grid()
ax.plot(xf, 2.0/N * np.abs(yf[:N/2]))
plt.show()
关于python - 如何将数据输入FFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47607732/