Smoothing

datkit.moving_average(times, values, w=None, t=None)

Applies a moving average filter to v, using a window of either width w or a width derived from the duration t.

If w is given, it must be a strictly positive and odd integer. If t is given, the used width will be the nearest odd integer to t over the sampling interval. See window_size() for details.

Returns a new time series x, y of length len(times) - w + 1.

datkit.gaussian_smoothing(times, values, w=None, t=None)

Applies a Gaussian smoothing filter to v, using a window of either width w or a width derived from the duration t.

If w is given, it must be a strictly positive and odd integer. If t is given, the used width will be the nearest odd integer to t over the sampling interval. See window_size() for details.

The Gaussian kernel is determined as np.exp(-x**2), where x ranges from -2 to +2 in the window.

datkit.window_size(times, w=None, t=None)

Returns a window size of either w samples or width t.

If w is given, it must be a strictly positive odd integer.

If t is given, the used width will be the nearest odd integer to t / dt, where dt is the sampling interval. The nearest odd integer is defined as 1 + 2 * ((t / dt) // 2).

datkit.haar_downsample(times, values, repeats=1)

Returns a downsampled signal created by successive averaging of adjacent samples, similar to a Haar wavelet.

In each pass:

  • If the signal length is odd, the final sample is omitted

  • The first two samples are averaged, then the next two, etc.

Returns a new and downsampled time series (times_2, values_2).