Search code examples
pythonfftvibrationnfft

FFT using Python


I am receiving data from a vibration sensor in the form of two numpy arrays. The first array represents the actual values for the vibration measurement and the second array is the corresponding time information (timestamp). For example:

vibraton_data = np.array([621,1546,262])

timestamps = np.array([1592583531, 1592583548, 1592583555])

That means that for every vibration measurement I have the time information.

I would like to apply now the Fast-Fourier-Transformation. Does anyone know how to do that? My first try would be something like this:

N = 600 
T = 1.0 / 800.0 
x = np.linspace(0.0, N*T, N)
yf = fft(vibration_data)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)

But I dont know here how to deal with the time information from my time array.


Solution

  • This is really a signal processing question, not a Python one. You have several options here:

    • if your data is uniformly sampled - you can ignore the timestamps altogether. All the information you need is in the data, and the (constant) sampling frequency: f_s = 1.0 / (timestamps[1] - timestamps[0])
    • if not, you can either:
      • use Non-uniform DFT (here is one implementation, haven't tried)
      • interpolate the data between non-uniform timestamps so it becomes uniform. Note that effectively, this applies a low-pass filter to your data, which may be not what you want (more on the effects of interpolation here).

    In all cases, when you perform FFT, time information is not required anymore, as you are in the frequency domain.