title: How to calculate frequency of a give wave and time
body: <p>I have data for Velocity vs time. The time steps are not uniform, but the Velocity data is a wave. How do I calculate the principal frequency of the velocity using FFT of Python? Most of the examples I am seeing online are for uniform time stepping.</p>
  
  <p>My data is like </p>
  
  <pre><code>7.56683038E+02  2.12072850E-01 
  7.56703750E+02  2.13280844E-01
  7.56724461E+02  2.14506402E-01
  7.56745172E+02  2.15748934E-01
  7.56765884E+02  2.17007907E-01
  7.56786595E+02  2.18282753E-01
  </code></pre>
  
  <p>10000 lines like that. </p>
  
  <p>Seeing some online responses, I wrote a code like the following, but it is not working:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import numpy as np
  import scipy as sy
  import scipy.fftpack as syfp
  import pylab as pyl
  
  # Calculate the number of data points
  length = 0
  for line in open("data.dat"):
      length = length + 1
  
  # Read in data from file here
  t = np.zeros(shape=(length,1))
  u = np.zeros(shape=(length,1))
  
  
  length = 0
  for line in open("data.dat"):
      columns = line.split(' ')
      t[length] = float(columns[0])
      u[length] = float(columns[1])
      length = length + 1
  
  # Do FFT analysis of array
  FFT = sy.fft(u)
  
  # Getting the related frequencies
  freqs = syfp.fftfreq(len(u))
  
  # Create subplot windows and show plot
  pyl.subplot(211)
  pyl.plot(t, u)
  pyl.xlabel('Time')
  pyl.ylabel('Amplitude')
  pyl.subplot(212)
  pyl.plot(freqs, sy.log10(FFT), 'x')
  pyl.show()
  </code></pre>
  
  <p>---------------------- edit ------------------------</p>
  
  <p>with this code I am getting an output like the following figure. I am not sure what this figure shows. I was expecting just to see one peak in the FFT diagram
  <img src="https://i.stack.imgur.com/hPZq7.png" alt="Output by the python program"></p>
  
  <p>---------------------- edit ------------------------</p>
  
  <p>My results with the mock data with the sin functions suggested in the comments below are here:</p>
  
  <p><img src="https://i.stack.imgur.com/XcE44.png" alt="results of the mock data"></p>