amep.utils.spectrum#

amep.utils.spectrum(xdata, ydata)#

Calculates the spectrum of one-dimensional real data by using fft. Assumes equally spaced xdata.

Parameters:
  • xdata (np.ndarray) – Equally spaced x-values as array of shape (N,).

  • ydata (np.ndarray) – Corresponding y-values as array of shape (N,).

Returns:

  • np.ndarray – Spectrum.

  • np.ndarray – Frequencies.

Examples

>>> import amep
>>> import numpy as np
>>> x = np.linspace(0,10,500)
>>> y = np.sin(2*np.pi*2*x) + 0.5*np.cos(2*np.pi*x)
>>> s, f = amep.utils.spectrum(x, y)
>>> fig, axs = amep.plot.new(nrows=2, figsize=(3,3))
>>> axs[0].plot(x,y)
>>> axs[0].set_xlabel('Time')
>>> axs[0].set_ylabel('Data')
>>> axs[1].plot(f, s)
>>> axs[1].set_xlabel('Frequency')
>>> axs[1].set_ylabel('Spectrum')
>>> fig.savefig('./figures/utils/utils-spectrum.png')
>>>
../_images/utils-spectrum.png