frequency

frequency(x, y, filter_window=5, filter_dim=2)[source]

Get frequency of oscillating signal.

First this tries FFT. If the true value is likely below or near the frequency resolution, the function tries low frequency fit with

\[f_{\rm est} = \frac{1}{2\pi {\rm max}\left| y \right|} {\rm max} \left| \frac{dy}{dx} \right|\]

given \(y = A \cos (2\pi f x + phi)\). In this mode, y data points are smoothed by a Savitzky-Golay filter to protect against outlier points.

Note

This function returns always positive frequency. This function is sensitive to the DC offset. This function assumes sorted, no-overlapping x values.

Parameters:
  • x (ndarray) – Array of x values.

  • y (ndarray) – Array of y values.

  • filter_window (int) – Window size of Savitzky-Golay filter. This should be odd number.

  • filter_dim (int) – Dimension of Savitzky-Golay filter.

Returns:

Frequency estimation of oscillation signal.

Return type:

float