python – Conversion of time series into frequency domain using the FFT

len(data) = 40000000

  data = time_series

  y= fft(data)

  sample = len(data)
  N = 96000 # sampling rate
  frequency = np.linspace (0.0, sample, int (N/2))
  y= 2/N * (y[0:np.int (N/2)]).astype(np.float64)
  fig, axs = plt.subplots(2, sharex=True, gridspec_kw={'hspace': 0})
  plt.suptitle('Time and freq ', fontsize="30")
  axs[0].plot(df.iloc[:,0])
  axs[0].set_xlabel('Time', fontsize="20")
  axs[0].set_ylabel('Q0', fontsize="20")
  axs[1].set_xlabel('freq', fontsize="20")
  axs[1].set_ylabel('feature', fontsize="20")
  axs[1].plot(frequency[0:len(frequency)], y[0:len(y)], color="g")
  plt.show()

Read more here: Source link