蟒蛇运动中振动信号的快速傅里叶变换

时间:2018-01-17 10:22:36

标签: python pandas signals fft

我收集了一些电机振动信号的数据(178,432),单位为g(加速度)。信号采样率为25000 /秒,电机速度为1500rpm(25hz)。但是当我尝试使用python进行FFT时,图片并不正确。任何人都可以帮助我吗?

我的数据:https://drive.google.com/file/d/12V8H3h6ved4lBflVxoHo2Qv5rfVZqXf0/view?usp=sharing

这是我的代码:

import scipy.fftpack
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

nor = pd.read_csv('normal.csv', header=1)

N = nor.size # data size
T = 1.0 / 25000.0 # inverse of sampling rate
x = np.linspace(0.0, N*T, N)
y = nor.values
yf = np.abs(scipy.fft(y))
xf = scipy.fftpack.fftfreq(nor.size, d=T)

fig, ax = plt.subplots()
ax.plot(np.abs(xf), np.abs(yf))
plt.show()

我的FFT情节:

enter image description here

1 个答案:

答案 0 :(得分:1)

当您访问valuesDataFrame时,您会获得一组数组或二维数组:

In [23]: pd.read_csv('../Downloads/normal.csv', header=1).values
Out[23]: 
array([[ 0.006038 ],
       [ 0.0040734],
       [ 0.0031316],
       ..., 
       [-0.0103366],
       [-0.0025845],
       [ 0.0012779]])

因此scipy.fft(y)的结果是nor.size个单独的1项DFFT结果数组的数组,换句话说就是原始信号:

In [42]: scipy.fft(y)
Out[42]: 
array([[ 0.0060380+0.j],
       [ 0.0040734+0.j],
       [ 0.0031316+0.j],
       ..., 
       [-0.0103366+0.j],
       [-0.0025845+0.j],
       [ 0.0012779+0.j]])

然后,您继续根据FFT频率绘制原始信号的绝对值。相反,您将要对矢量执行单个DFFT:

In [49]: yf = scipy.fft(nor['Channel_0  '].values)  # column/series values

In [50]: yf
Out[50]: 
array([ 1.58282430+0.j        , -3.61766030-1.86904326j,
       -0.50666930+4.24825582j, ...,  4.54241118-0.97200708j,
       -0.50666930-4.24825582j, -3.61766030+1.86904326j])

In [51]: x = scipy.fftpack.fftfreq(yf.size, 1 / 25e3)

In [56]: plot(x[:x.size//2], abs(yf)[:yf.size//2])  # omit fold
Out[56]: [<matplotlib.lines.Line2D at 0x7f2f39f01cf8>]

enter image description here