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-fillmissing.md

View on GitHub
# Function: `fillmissing`

> Used in: wf-repair-missing.md
> Toolbox: MATLAB (base)

Fills missing entries (NaN for numeric/duration, NaT for datetime,
`<missing>` for string, etc.) using an interpolation or moving-window method.
This is the interpolation-based filler: it draws each fill value from
neighboring non-missing samples. For long gaps in oscillatory signals where
interpolation would inject spurious low-frequency content, use `fillgaps`
(AR-model) instead. See fn-fillgaps.md and wf-repair-missing.md.

On a matrix, operates column-wise; on a table/timetable, per variable.

## Signature

```matlab
F = fillmissing(A, method)                       % method REQUIRED, no default
F = fillmissing(A, "constant", v)
F = fillmissing(A, movmethod, window)            % "movmean" / "movmedian"
F = fillmissing(A, "knn")  |  fillmissing(A, "knn", k)
F = fillmissing(A, fillfun, gapwindow)           % custom function handle
F = fillmissing(___, dim)
[F, TF] = fillmissing(___)                        % TF = logical mask of filled entries
```

## Fill methods (the `method` argument)

| `method` | What it does |
|---|---|
| `"linear"` | Linear interpolation of neighbors. Honest; no invented curvature. Good when downstream is time-domain (statistics, plotting). |
| `"pchip"` | Shape-preserving cubic. No overshoot. Defensible default for short gaps in a smooth signal. |
| `"spline"` | Cubic spline. Can overshoot at gap edges. |
| `"makima"` | Modified Akima cubic. Shape-preserving, smoother than pchip. |
| `"nearest"` / `"previous"` / `"next"` | Nearest / previous / next non-missing value. |
| `"movmean"` / `"movmedian"` | Moving-window average / median (needs a `window`). |
| `"constant"` | A supplied scalar/vector `v`. |
| `"knn"` / `"knn", k` | Nearest-neighbor rows by Euclidean distance (matrix/table). |
| function handle | Custom fill over a `gapwindow` (see below). |
| `"mean"` / `"median"` / `"mode"` | Global statistic. *Since R2026a.* |

## Name-value pairs

| NV-pair | Default | Purpose |
|---|---|---|
| `MaxGap` | unfilled cap = none | Refuse to fill any gap wider than this (relative to `SamplePoints`). Use it to gate interpolation so wide gaps stay NaN instead of being fabricated. |
| `SamplePoints` | `[1 2 3 ...]` | Sample-point vector; interpolation and windows are relative to it. Not supported for timetables (row times are used) or `"knn"`. |
| `EndValues` | same as `method` | How to handle leading/trailing missing values. `"nearest"` clamps to the boundary value instead of extrapolating. |
| `MissingLocations` | auto by data type | Logical mask of non-standard missing values (e.g. treat `-99` as missing). *Since R2024a.* |
| `dim` | first non-singleton | Fill across rows (`2`) instead of columns. Not supported for tables. |
| `Distance` | Euclidean | Custom distance for `"knn"`. |

## Custom fill over a gap window

```matlab
F = fillmissing(A, @(xs, ts, tq) myfun(xs, ts, tq), gapwindow, SamplePoints=t);
```

The handle receives `xs` (surrounding sample values), `ts` (their locations),
and `tq` (the missing locations). The escape hatch for logic like
"forward-fill, but only within N samples of the gap."

## Gotchas

- **No method default.** `fillmissing(x)` is an error. The method is a
  required argument; pick it deliberately (usually `"linear"` or `"pchip"`).
- **Endpoints extrapolate by default.** Leading/trailing gaps use the same
  method, which can extrapolate poorly. Set `EndValues="nearest"` to clamp.
- **Wide gaps are silently interpolated** unless you set `MaxGap`. A 500-sample
  linear fill across a real dropout is a fabricated ramp. Use `MaxGap` to
  refuse, and disclose any gap you do fill.
- **Interpolation kills tones in long gaps.** In an oscillatory signal a
  smooth fill flattens the oscillation across the gap and adds a spurious
  low-frequency bump to the spectrum. If downstream is FFT/PSD and the gap is
  wider than ~half a cycle of the lowest frequency, use fn-fillgaps.md.

## See also

- fn-fillgaps.md — AR-model filler for long gaps in oscillatory signals.
- wf-repair-missing.md — the `fillmissing` (interp) vs `fillgaps` (AR)
  decision, end to end.
- `interp1` — general resampling onto an arbitrary output grid; `retime` for
  timetables.

----

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