yang
yang

Reputation: 45

Fast Fourier Transform on motor vibration signal in python

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?

my data : 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:

enter image description here

Upvotes: 3

Views: 20119

Answers (1)

Ilja Everilä
Ilja Everilä

Reputation: 53017

When you access the values of a DataFrame you get an array of arrays, or a 2D array:

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:

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:

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

Upvotes: 4

Related Questions