【问题标题】:How to input data to FFT如何将数据输入到 FFT
【发布时间】:2017-12-02 12:06:36
【问题描述】:

所以我确实有两个数据数组:

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]

我如何让他们接收看起来像这样的 FFT?

我有一个程序可以显示这些数据,但我需要在 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

我还需要以某种方式实现 blackman 或 hamming 窗口,你能帮忙吗?

【问题讨论】:

  • 你遇到了什么麻烦?是编程问题还是数学问题?
  • 我猜都是。几周前,我开始使用 python 进行冒险,但使用该程序我必须做很多事情。数学问题也出现了。我知道我的问题很具体,但也许有人可以提供帮助。我阅读了很多关于 FFT 的帖子等,但仍然不知道如何去做。
  • 是的,我听说过,但我如何在该命令中描述它?最重要的是,您知道如何应用我的数据来获得该 fft 图表吗?

标签: python python-2.7 numpy hamming-window


【解决方案1】:

假设BxBy 是类数组,则可以通过* 运算符编写窗口。

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()

【讨论】:

  • 感谢您的帮助 :) 我应用了您的代码,但它看起来不像预期的那样。为什么我不能在评论中发布屏幕?
【解决方案2】:

我使用了 Welch 方法,这是一个好主意。帖子结束。问题解决了。

# Loop for FFT data
for dataset in [fft1]:
    dataset = np.asarray(dataset)
    freqs, psd = welch(dataset, fs=266336/300, window='hamming', nperseg=8192)
    plt.semilogy(freqs, psd/dataset.size**2, color='r')

for dataset2 in [fft2]:
    dataset2 = np.asarray(dataset2)
    freqs2, psd2 = welch(dataset2, fs=266336/300, window='hamming', nperseg=8192)
    plt.semilogy(freqs2, psd2/dataset2.size**2, color='b')

【讨论】:

    猜你喜欢
    • 2014-10-09
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多