title: How to find peaks of FFT graph using Python?
body: <p>I am using Python to perform a Fast Fourier Transform on some data. I then need to extract the locations of the peaks in the transform in the form of the x-values. Right now I am using Scipy's fft tool to perform the transform, which seems to be working. However, when i use Scipy's find_peaks I only get the y-values, not the x-position that I need. I also get the warning:</p>
  <pre><code>ComplexWarning: Casting complex values to real discards the imaginary part
  </code></pre>
  <p>Is there a better way for me to do this? Here is my code at the moment:</p>
  <pre><code>import pandas as pd
  import matplotlib.pyplot as plt
  from scipy.fft import fft
  from scipy.signal import find_peaks
  
  headers = [&quot;X&quot;,&quot;Y&quot;]
  
  original_data = pd.read_csv(&quot;testdata.csv&quot;,names=headers)
  
  x = original_data[&quot;X&quot;]
  y = original_data[&quot;Y&quot;]
  
  a = fft(y)
  peaks = find_peaks(a)
  print(peaks)
  
  plt.plot(x,a)
  plt.title(&quot;Fast Fourier transform&quot;)
  plt.xlabel(&quot;Frequency&quot;)
  plt.ylabel(&quot;Amplitude&quot;)
  plt.show()
  </code></pre>