vitabel.utils.signal

Signal processing utilities (derivatives, integrals, smoothing, gaps, resampling, signal features).

Functions

deriv(→ numpy.typing.NDArray)

First derivative of data with respect to time: central

integrate(→ pandas.Series)

Cumulative integral of data over time (trapezoidal rule).

av_mean(→ numpy.typing.NDArray)

Calculate a centered average mean of data over k elements.

determine_gaps_in_recording(time, data, ...)

linear_interpolate_gaps_in_recording(time, data, ...)

Fill the gaps found by determine_gaps_in_recording() with points

resample_to_common_index(...)

Aligns two or more Channel objects by their time indices, ensuring

gaussian_kernel_regression_point(x0, x, y[, sigma, ...])

Module Contents

vitabel.utils.signal.deriv(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike) → numpy.typing.NDArray

First derivative of data with respect to time: central differences inside, forward / backward differences at the boundaries.

Parameters:
time

x values, in increasing order (not necessarily equidistant).

data

Corresponding y values.

Returns:
The derivative at every x value.
vitabel.utils.signal.integrate(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike) → pandas.Series

Cumulative integral of data over time (trapezoidal rule).

Parameters:
time

Times in seconds (not necessarily equidistant).

data

Data points.

Returns:
The integral from the first time to each time (starting at 0).
vitabel.utils.signal.av_mean(k: int, data: numpy.typing.ArrayLike) → numpy.typing.NDArray

Calculate a centered average mean of data over k elements.

The data is zero-padded at the boundaries.

vitabel.utils.signal.determine_gaps_in_recording(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike)
vitabel.utils.signal.linear_interpolate_gaps_in_recording(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike)

Fill the gaps found by determine_gaps_in_recording() with points at the median time step, linearly interpolated between the samples around the gap. The result is sorted like the input.

vitabel.utils.signal.resample_to_common_index(*channels: vitabel.timeseries.Channel) → tuple[vitabel.typing.DataSlice, Ellipsis]

Aligns two or more Channel objects by their time indices, ensuring all are sampled at the same time points, including zero-crossings. Data are interpolated to a common time base within their overlapping range.

Parameters:
*channels

Two or more Channel objects to be aligned and interpolated.

Returns:
tuple[DataSlice, …]

A tuple of DataSlice objects representing the aligned channels.

Raises:
ValueError

If there is no overlapping time range between the two channels.

Notes

Zero-crossings are inserted to improve alignment, especially for strongly oscillating signals.

vitabel.utils.signal.gaussian_kernel_regression_point(x0, x, y, sigma=1, max_width_factor=2)