title: Plotting a fast Fourier transform in Python
body: <p>I have access to NumPy and SciPy and want to create a simple FFT of a data set. I have two lists, one that is <code>y</code> values and the other is timestamps for those <code>y</code> values.</p>
  <p>What is the simplest way to feed these lists into a SciPy or NumPy method and plot the resulting FFT?</p>
  <p>I have looked up examples, but they all rely on creating a set of fake data with some certain number of data points, and frequency, etc. and don't really show how to do it with just a set of data and the corresponding timestamps.</p>
  <p>I have tried the following example:</p>
  <pre><code>from scipy.fftpack import fft
  
  # Number of samplepoints
  N = 600
  
  # Sample spacing
  T = 1.0 / 800.0
  x = np.linspace(0.0, N*T, N)
  y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
  yf = fft(y)
  xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
  import matplotlib.pyplot as plt
  plt.plot(xf, 2.0/N * np.abs(yf[0:N/2]))
  plt.grid()
  plt.show()
  </code></pre>
  <p>But when I change the argument of <code>fft</code> to my data set and plot it, I get extremely odd results, and it appears the scaling for the frequency may be off. I am unsure.</p>
  <p>Here is a pastebin of the data I am attempting to FFT</p>
  <p><a href="http://pastebin.com/0WhjjMkb" rel="noreferrer">http://pastebin.com/0WhjjMkb</a>
  <a href="http://pastebin.com/ksM4FvZS" rel="noreferrer">http://pastebin.com/ksM4FvZS</a></p>
  <p>When I use <code>fft()</code> on the whole thing it just has a huge spike at zero and nothing else.</p>
  <p>Here is my code:</p>
  <pre><code>## Perform FFT with SciPy
  signalFFT = fft(yInterp)
  
  ## Get power spectral density
  signalPSD = np.abs(signalFFT) ** 2
  
  ## Get frequencies corresponding to signal PSD
  fftFreq = fftfreq(len(signalPSD), spacing)
  
  ## Get positive half of frequencies
  i = fftfreq&gt;0
  
  ##
  plt.figurefigsize = (8, 4)
  plt.plot(fftFreq[i], 10*np.log10(signalPSD[i]));
  #plt.xlim(0, 100);
  plt.xlabel('Frequency [Hz]');
  plt.ylabel('PSD [dB]')
  </code></pre>
  <p>Spacing is just equal to <code>xInterp[1]-xInterp[0]</code>.</p>