Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/signal-processing/matlab-prepare-signal-data

matlab-prepare-signal-data

Verified

Use this skill when conditioning, loading, preparing, or labeling signal data for analysis or ML training. Covers: cleaning a single signal (fill gaps, remove drift, deoutlier, denoise, resample/align a time base) BEFORE analysis; building a `signalDatastore` pipeline; creating a `labeledSignalSet` for Signal Labeler; deriving labels (filename, folder, in-file, ROI, time-frequency ROI); stratified train/val/test splits; framing long signals; parallel processing; and shaping datastore output for `trainnet`. Triggers include "clean up this signal", "remove drift / detrend", "fill gaps", "remove spikes / outliers", "denoise", "resample to a uniform rate", "align channels", "labels from filenames", "stratified split", "prepare for Signal Labeler", and function names like `fillgaps`, `fillmissing`, `detrend`, `filloutliers`, `smoothdata`, `resample`, `synchronize`, `signalDatastore`, `labeledSignalSet`, `filenames2labels`, `folders2labels`, `splitlabels`, `framesig`, `framelbl`, `createDatastores`.

FileKindSize
SKILL.mdskill md9.5 KB
manifest.yamlconfig650 B
references/fn-countlabels.mdmarkdown2.1 KB
references/fn-detrend.mdmarkdown4.6 KB
references/fn-filenames2labels.mdmarkdown4.8 KB
references/fn-fillgaps.mdmarkdown3.3 KB
references/fn-fillmissing.mdmarkdown4.2 KB
references/fn-filloutliers.mdmarkdown5.0 KB
references/fn-folders2labels.mdmarkdown3.4 KB
references/fn-framelbl.mdmarkdown7.1 KB
references/fn-framesig.mdmarkdown4.1 KB
references/fn-hampel.mdmarkdown3.3 KB
references/fn-labeledsignalset.mdmarkdown9.1 KB
references/fn-labelspectrogramoptions.mdmarkdown4.6 KB
references/fn-medfilt1.mdmarkdown3.3 KB
references/fn-partition.mdmarkdown4.6 KB
references/fn-resample.mdmarkdown4.6 KB
references/fn-retime.mdmarkdown4.7 KB
references/fn-sgolayfilt.mdmarkdown3.5 KB
references/fn-signaldatastore.mdmarkdown11.9 KB
references/fn-signallabeldefinition.mdmarkdown5.9 KB
references/fn-signalmask-getmask.mdmarkdown8.6 KB
references/fn-smoothdata.mdmarkdown4.8 KB
references/fn-splitlabels.mdmarkdown5.3 KB
references/fn-subset.mdmarkdown3.9 KB
references/fn-synchronize.mdmarkdown4.7 KB
references/fn-wdenoise.mdmarkdown5.2 KB
references/wf-align-channels.mdmarkdown6.6 KB
references/wf-custom-readfcn.mdmarkdown5.0 KB
references/wf-denoise.mdmarkdown2.6 KB
references/wf-detrend-smooth-deoutlier.mdmarkdown6.6 KB
references/wf-envelope.mdmarkdown5.3 KB
references/wf-frame-and-label.mdmarkdown4.7 KB
references/wf-handoff-to-dl.mdmarkdown9.1 KB
references/wf-label-and-export.mdmarkdown8.7 KB
references/wf-load-and-split.mdmarkdown4.6 KB
references/wf-parallel-process.mdmarkdown4.8 KB
references/wf-repair-missing.mdmarkdown6.7 KB
references/wf-uniform-rate.mdmarkdown4.2 KB

references/fn-fillgaps.md

View on GitHub
# Function: `fillgaps`

> Used in: wf-repair-missing.md
> Toolbox: Signal Processing Toolbox

Fills NaN gaps by autoregressive modeling: it fits forward and reverse AR
models to the non-missing samples and extrapolates them into each gap. Because
the AR model continues the signal's dominant oscillation, it preserves the
spectrum across long gaps where interpolation would inject a spurious
low-frequency ramp.

This is the function cold agents miss and invent names for (`regularizeNaNs`,
`inpaintn` do not exist). It is SPT-only. When the gap is long AND the signal
is oscillatory AND downstream is spectral, this is the right call over
`fillmissing`. See wf-repair-missing.md.

On a matrix, each column is an independent channel.

## Signature

```matlab
y = fillgaps(x)                     % maxlen = all samples, order = "aic"
y = fillgaps(x, maxlen)             % cap samples used per fit
y = fillgaps(x, maxlen, order)      % explicit AR order
fillgaps(___)                       % no output: plots original + reconstruction
```

`x` carries NaN at the missing samples. Output `y` is the same size with the
gaps reconstructed.

## Arguments

| Argument | Default | Purpose |
|---|---|---|
| `maxlen` | all available samples | Maximum number of samples on each side of a gap to use in the AR fit. Cap it when the signal is not well described by a single AR process across its whole range (non-stationary), so each gap is modeled from a local window. |
| `order` | `"aic"` | AR model order. `"aic"` auto-selects the order minimizing the Akaike information criterion. Pass a positive integer to fix it. Order is truncated when there are not enough samples. |

## Why it preserves the spectrum (the mechanism)

Because the forward/reverse AR models continue the signal's dominant
oscillation through the gap, `fillgaps` keeps the spectrum intact where a plain
interpolation (`fillmissing("pchip")`) would draw a smooth ramp across the gap —
flattening the tone and injecting a spurious low-frequency bump into the FFT.
That advantage is real **only when the signal is AR-suitable** (oscillatory /
quasi-stationary); on noise-like data, a monotonic trend, or a lone transient
the AR fit has nothing to continue and `fillmissing` is as good or better.

The full `fillmissing`-vs-`fillgaps` decision (both gates: gap-width and
AR-suitability) is the workflow's — see wf-repair-missing.md.

## Gotchas

- **SPT required.** The only function in the missing-data set that is not base
  MATLAB.
- **`order="aic"` can over-fit on short signals.** With fewer than ~50
  non-missing samples, pass a small explicit order (e.g. 4-8) rather than
  letting AIC choose.
- **Very high orders misbehave.** Large `order` values hit finite-precision
  problems and can produce a worse reconstruction than a moderate order. The
  doc shows order 70 reconstructing worse than order 40.
- **Per-channel on matrices.** Each column is fit independently, so expect
  different AR orders per column unless you fix `order`.
- **NaN-only.** It fills NaN gaps; it does not resample onto a new grid (that
  is `interp1` / `retime`) or remove outliers (that is fn-filloutliers.md).

## See also

- fn-fillmissing.md — interpolation-based filler for short gaps.
- wf-repair-missing.md — the full `fillmissing` vs `fillgaps` decision.
- `arburg` — the AR-estimation primitive underneath.

----

Copyright 2026 The MathWorks, Inc.

----
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall