Smoothing

The methods below can perform basic smoothing of noisy time series.

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

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

If w is given, it must be a strictly positive and odd integer, indicating the number of data points to include in the window. If a duration t is given, it will be converted to an integer width using the method window_size().

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 w samples or a number derived from the duration t.

If w is given, it must be a strictly positive and odd integer, indicating the number of data points to include in the window. If a duration t is given, it will be converted to an integer width using the method window_size().

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

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

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

Returns a window size of either w samples or duration 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) of length len(times) // 2**repeats.