Interpolate short NaN gaps¶
What it does¶
This utility estimates missing samples in short internal gaps while preserving signal length and sample alignment.
When to use it¶
Use it to reconstruct limited losses of samples before further analysis, independently of filtering or spectral estimation. The maximum gap is measured in missing samples on a regular sampling grid.
Canonical ID: tools.interpgap
Inputs¶
| Name | Meaning | Type | Unit | Requirements |
|---|---|---|---|---|
signal |
Regularly sampled real signal with missing samples marked as NaN. | real vector | a.u. | NaN allowed; finite |
max_gap |
Maximum number of consecutive missing samples to reconstruct. | integer scalar | sample | minimum: 0; no NaN; finite |
Parameters¶
| Name | Meaning | Type | Unit | Default | Requirements |
|---|---|---|---|---|---|
method |
Interpolation method: linear, nearest, pchip, or spline. | string | dimensionless | linear |
not specified |
Outputs¶
| Name | Meaning | Type | Unit |
|---|---|---|---|
interpolated_signal |
Signal with eligible gaps reconstructed, preserving original measurements and sample alignment. | real vector | a.u. |
How it works¶
Long gaps separate independent segments. Within each segment, interpolation uses the original finite samples and their positions. Linear interpolation joins neighboring values; nearest interpolation selects a measured value. PCHIP preserves local shape, while the spline provides a smooth cubic interpolation through the available support.
Interpretation and limitations¶
Reconstructed values are estimates. Choose the maximum gap and method for the signal and intended analysis. Cubic interpolation needs neighboring measurements to establish shape; with only two available values it reduces to a straight line. Boundary gaps remain missing because the method does not extrapolate. Spline interpolation may overshoot between measured values.