pandas python中电机振动信号的快速傅里叶变换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48298724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fast Fourier Transform on motor vibration signal in python
提问by yang
I collected some data(178,432) of motor vibration signal, and the unit was g(Acceleration). The Sampling rate of signal is 25000/sec, motor speed is 1500rpm(25hz). But while I try to do the FFT using python, the picture isn't right. Can anyone help me with it?
我收集了一些电机振动信号的数据(178,432),单位是g(加速度)。信号采样率为25000/sec,电机转速为1500rpm(25hz)。但是当我尝试使用 python 进行 FFT 时,图片不正确。任何人都可以帮助我吗?
my data : https://drive.google.com/file/d/12V8H3h6ved4lBflVxoHo2Qv5rfVZqXf0/view?usp=sharing
我的数据:https: //drive.google.com/file/d/12V8H3h6ved4lBflVxoHo2Qv5rfVZqXf0/view?usp=sharing
Here is my code:
这是我的代码:
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()
my FFT plot:
我的 FFT 图:
采纳答案by Ilja Everil?
When you access the values
of a DataFrame
you get an array of arrays, or a 2D array:
当您访问values
a 时,DataFrame
您将获得一个数组数组,或一个二维数组:
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]])
And so the result of scipy.fft(y)
is an array of nor.size
separate 1-dimensional 1-item DFFT result arrays, in other words the original signal:
所以结果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]])
You then proceeded to plot the absolute value of the original signal, against the FFT freqs. Instead you'll want to perform a single DFFT against a vector:
然后,您继续根据 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>]