skg.sin

Sinusoidal fit based on the clustering algorithms in skg.cluster1d.

The only parameter that is estimated with high accuracy is frequency. All the other paramters can be obtained from other non-linear estimation techniques.

f(x) = a sin(\omega t - \phi) + b

An alternative to this method is Jean Jacquelin’s method.

Todo

Add link to JJ’s method above.

Todo

Add proper handling of colinear inputs (and other singular matrix cases).

Todo

Add proper handling for < 1 period.

Todo

Add tests.

Todo

Add nan_policy argument.

Todo

Add axis parameter. Figure out how to do it properly.

Todo

Add PEP8 check to formal tests.

Todo

Allow broadcasting of x and y, not necessarily identical size

Functions

model(t, a, omega, phi, b) Compute a sin(\omega t - \phi) + b.
sin_fit(t, y[, sorted, _debug]) Compute estimated initial parameters for noisy sinusoidal data.
skg.sin.model(t, a, omega, phi, b)[source]

Compute a sin(\omega t - \phi) + b.

Parameters:
  • t (array-like) – The value of the model will be the same shape as the input.
  • a (float) – The amplitude of the sine wave at t = \frac{\left( \frac{\pi}{2} + \phi \right)}{\omega}.
  • omega (float) – The angular frequency of the sinusoid. This is 2 \pi f, where f is the frequency.
  • phi (float) – The angular phase shift of the sinusoid. This is the phase shift in units of periods. The phase shift can be expressed as t_0 = \frac{\phi}{\omega}.
  • b (float) – The bias of the sinusoid.
Returns:

y – An array of the same shape as t, containing the model computed for the given parameters.

Return type:

array-like

skg.sin.sin_fit(t, y, sorted=True, _debug=False)[source]

Compute estimated initial parameters for noisy sinusoidal data.

The result will have a very accurate approximation of the frequency, which is the crucial parameter for non-linear estimator initial values.

Parameters:
  • t (array-like) – The x-values of the data points. The fit will be performed on a raveled version of this array.
  • y (array-like) – The y-values of the data points corresponding to x. Must be the same size as x. The fit will be performed on a raveled version of this array.
  • sorted (bool) – Set to True if x is already monotonically increasing or decreasing. If False, x will be sorted into increasing order, and y will be sorted along with it.
Returns:

  • a (float) – Amplitude.
  • omega (float) – Angular frequency: \omega = \frac{2\pi}{\lambda}.
  • phi (float) – Angular phase-shift.
  • b (float) – Additive bias.

References

  • Currently none. This function, and the underlying clustering algorithm are entirely the work of the author. A peer reviewed paper is currently in the works.