datasmooth#

torchspin.datasmooth(y, m, method='binom', poly_order=2, deriv=0)[source]#

Smooth a 1D signal using a moving-window filter.

Parameters:
  • y (array-like) – Input signal (1D array or 2D column array).

  • m (int) – Half-width of the filter window. The full window is 2*m+1 points.

  • method (str) – 'binom' (default) — binomial-weighted moving average. 'flat' — unweighted (uniform) moving average. 'savgol' — Savitzky-Golay polynomial filter.

  • poly_order (int) – Polynomial order for Savitzky-Golay (default 2).

  • deriv (int) – Derivative order for Savitzky-Golay (default 0 = smoothing only).

Returns:

y_smooth (ndarray, same shape as input *y.*)

Return type:

np.ndarray

Examples

>>> x = np.linspace(0, 2*np.pi, 200)
>>> y = np.sin(x) + 0.2*np.random.randn(200)
>>> y_s = datasmooth(y, 5)