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 eitherwsamples or a number derived from the durationt.If
wis given, it must be a strictly positive and odd integer, indicating the number of data points to include in the window. If a durationtis given, it will be converted to an integer width using the methodwindow_size().Returns a new time series
x, yof lengthlen(times) - w + 1.
- datkit.gaussian_smoothing(times, values, w=None, t=None)¶
Applies a Gaussian smoothing filter to
v, using a window of eitherwsamples or a number derived from the durationt.If
wis given, it must be a strictly positive and odd integer, indicating the number of data points to include in the window. If a durationtis given, it will be converted to an integer width using the methodwindow_size().The Gaussian kernel is determined as
np.exp(-i**2), whereiranges from -2 to +2 in the window.Returns a new time series
x, yof lengthlen(times) - w + 1.
- datkit.window_size(times, w=None, t=None)¶
Returns a window size of either
wsamples or durationt.If
wis given, it must be a strictly positive odd integer.If
tis given, the used width will be the nearest odd integer tot / dt, wheredtis the sampling interval. The nearest odd integer is defined as1 + 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 lengthlen(times) // 2**repeats.