Skip to content

Expand NaN gaps

What it does

This utility marks samples near missing spans as NaN without changing signal length or time alignment.

When to use it

Use it when a missing or invalid span also makes nearby samples unsuitable for analysis, for example when excluding a temporal margin around an artifact.

Canonical ID: tools.expandnans

Inputs

Name Meaning Type Unit Requirements
signal Signal whose original missing spans will be expanded. real vector a.u. NaN allowed; finite
sampling_frequency Sampling frequency of the signal. real scalar Hz greater than: 0; no NaN; finite
expansion_duration Time margin applied on each side of every original missing span. real scalar s minimum: 0; no NaN; finite

Outputs

Name Meaning Type Unit
expanded_signal Signal with enlarged missing spans, preserving length and sample alignment. real vector a.u.

How it works

The duration is converted to a symmetric sample radius. The method expands the original missing mask once, clips at the signal boundaries, and unites overlapping spans.

Interpretation and limitations

The duration applies on each side, so an isolated missing sample can exclude samples both before and after it. This operation deliberately discards nearby measurements and does not estimate missing values. Choose the margin to match the source of invalid data and the intended analysis.

Implementations and technical resources

Python source | MATLAB source

Normative JSON | Validation cases