0

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.

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
Chris S.
  • 131
  • 1
  • 7
  • 1
    I believe you have to use non-uniform FFT, something like [this](https://pythonhosted.org/pyNFFT/tutorial.html) – Severin Pappadeux Jun 19 '20 at 16:30
  • What is the benefit of using that approach? Why is the standard fft not working here? – Chris S. Jun 19 '20 at 16:34
  • Well, you have non-uniform time grid, this is why. Standard FFT in the assumption of the uniform time grid does not require X values at all. – Severin Pappadeux Jun 19 '20 at 16:44
  • 1
    And meself I never used NFFT, maybe there are better packages than one I proposed. You might reformulate the question and ask specifically for NFFT – Severin Pappadeux Jun 19 '20 at 16:46
  • @SeverinPappadeux Many thanks. I just thought about it and think the time information is not important here since I only want to see what the data is looking like in the frequency spectrum. How can I apply a normal FFT here when I have only one np.array? – Chris S. Jun 19 '20 at 16:48
  • Well, if you could ignore time stamps and assume uniform time grid, standard NumPy FFT shall work just fine, take a look at [that example](https://pythontic.com/visualization/signals/fouriertransform_fft) – Severin Pappadeux Jun 19 '20 at 16:51

1 Answers1

1

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.

bavaza
  • 10,319
  • 10
  • 64
  • 103
  • Many thanks! I can ignore my timestamps here. Do you have a minimalistic example how to do that in python? That would help me a lot. – Chris S. Jun 19 '20 at 16:49
  • 1
    The code you posted should work (see https://numpy.org/doc/1.18/reference/generated/numpy.fft.fft.html). By the way, are you sure you need FFT, and not the power-spectral density (PSD)? https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.welch.html?highlight=welch#scipy.signal.welch – bavaza Jun 19 '20 at 16:57