nan_filter
biosigpy.tools.nan_filter.nan_filter ¶
nan_filter(b: ArrayLike, a: ArrayLike, x: ArrayLike, max_gap: int = 0) -> np.ndarray
Causally filter a signal with NaN-aware gap handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b | array_like | Numerator filter coefficients. Values must be finite. | required |
a | array_like | Denominator filter coefficients. Values must be finite. | required |
x | array_like | One-dimensional real numeric signal. | required |
max_gap | int | Maximum internal | 0 |
Returns:
| Type | Description |
|---|---|
ndarray | One-dimensional filtered signal with the same length as |
Raises:
| Type | Description |
|---|---|
TypeError | If |
ValueError | If filter coefficients are empty or non-finite, if |
Notes
This function implements the Biosiglib tools.nan_filter specification. Filtering is causal and uses :func:scipy.signal.lfilter on each valid finite segment.
Boundary NaN gaps are preserved. Internal short gaps with length less than or equal to max_gap are interpolated before filtering. Internal long gaps with length greater than max_gap are preserved and split the signal into separate segments. Segments that are too short for causal filtering return NaN.
Examples:
>>> import numpy as np
>>> from biosigpy.tools import nan_filter
>>> b = np.array([0.5, 0.5])
>>> a = np.array([1.0])
>>> x = np.array([1.0, np.nan, 3.0, 4.0])
>>> nan_filter(b, a, x, max_gap=1).shape
(4,)
Source code in src/biosigpy/tools/nan_filter.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |