我有速度与时间的数据。时间步长不统一,但速度数据是一个波。如何使用Python的FFT来计算速度的主频?我在网上看到的大多数例子都是为了统一的时间跨度。如何计算给定波的频率和时间
我的数据是一样
7.56683038E+02 2.12072850E-01
7.56703750E+02 2.13280844E-01
7.56724461E+02 2.14506402E-01
7.56745172E+02 2.15748934E-01
7.56765884E+02 2.17007907E-01
7.56786595E+02 2.18282753E-01
10000行这样。
看到一些网上的反应,我写了类似下面的代码,但它不工作:
#!/usr/bin/env python
import numpy as np
import scipy as sy
import scipy.fftpack as syfp
import pylab as pyl
# Calculate the number of data points
length = 0
for line in open("data.dat"):
length = length + 1
# Read in data from file here
t = np.zeros(shape=(length,1))
u = np.zeros(shape=(length,1))
length = 0
for line in open("data.dat"):
columns = line.split(' ')
t[length] = float(columns[0])
u[length] = float(columns[1])
length = length + 1
# Do FFT analysis of array
FFT = sy.fft(u)
# Getting the related frequencies
freqs = syfp.fftfreq(len(u))
# Create subplot windows and show plot
pyl.subplot(211)
pyl.plot(t, u)
pyl.xlabel('Time')
pyl.ylabel('Amplitude')
pyl.subplot(212)
pyl.plot(freqs, sy.log10(FFT), 'x')
pyl.show()
-------------------- - 编辑------------------------
与此代码我得到一个输出,如下图。我不确定这个数字显示的是什么。我期待在FFT图中看到一个峰值
----------------------编辑--------- ---------------
我与在下面的意见建议的罪恶功能模拟数据结果在这里:
你是什么意思的“它不工作”?另外,“主要频率”是什么意思? – tom10 2014-09-29 18:34:35
在FFT图中,如果绘制'sy.log10(np.abs(FFT))'(即注意在那里使用'abs'),你会看到什么。 – tom10 2014-09-29 19:45:40
不会改变输出中的任何内容。顺便说一句,我检查和时间步骤看起来几乎统一与DT = 0.02071,我有我的文件100000数据点。 – jhaprade 2014-09-29 19:50:50