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

View on GitHub
# Function: `smoothdata`

> Used in: wf-detrend-smooth-deoutlier.md
> Toolbox: MATLAB (base)

The dispatcher for smoothing. One function, eight methods, an auto-window
heuristic. This is the default first reach for "make the signal less wiggly"
whenever you cannot name a cutoff frequency in Hz (if you can, use `lowpass`
instead).

`smoothdata` covers the common cases directly. Reach for `sgolayfilt`
(fn-sgolayfilt.md) only as the escape hatch: when you need a polynomial order
other than 2, or you want the filter's derivative output. For everything else
`smoothdata` is the more honest choice because you are not pretending to know
a frequency cutoff.

## Signature

```matlab
B = smoothdata(A)                       % "movmean", auto window
B = smoothdata(A, dim)
B = smoothdata(A, method)
B = smoothdata(A, method, window)
B = smoothdata(A, method, window, nanflag)
[B, winsize] = smoothdata(___)          % returns the window it chose
B = smoothdata(___, Name=Value)
```

## Methods (the `method` argument)

| Method | What it does | When |
|---|---|---|
| `"movmean"` (default) | Moving average. Hard-edged, reduces periodic trends. | Boring, defensible, no special story. |
| `"movmedian"` | Moving median. Robust to outliers; mean is not. | Outliers still in the signal that you did not pre-clean. |
| `"gaussian"` | Gaussian-weighted moving average. Smoother in the derivative than `movmean`. | Want a smooth result without hard window edges. |
| `"lowess"` | Local linear regression over each window. | **Trend extraction** - captures the slow component (see detrend use below). |
| `"loess"` | Local quadratic regression. | Trend with local curvature; slightly more expensive than lowess. |
| `"rlowess"` / `"rloess"` | Robust variants of lowess/loess. | Same as above but outlier-robust, at a speed cost. |
| `"sgolay"` | Savitzky-Golay (degree 2 by default). | Peak shapes matter. For degree != 2 or derivatives, use fn-sgolayfilt.md instead. |

## Name-value pairs / arguments

| Argument | Default | Purpose |
|---|---|---|
| `window` (positional) | auto (heuristic) | Window size. Scalar = centered length; `[b f]` = b preceding + current + f succeeding samples. `duration` when sample points are datetime/duration. |
| `nanflag` | `"omitmissing"` | Default **ignores** NaN. `"includenan"` makes any-NaN-in-window produce NaN (rarely wanted). |
| `SmoothingFactor` | `0.25` | Scales the auto window when `window` is not given. Near 0 = small window (less smoothing), near 1 = large. Cannot be combined with an explicit `window`. |
| `Degree` | `2` | Savitzky-Golay polynomial degree - only valid with `"sgolay"`. Must be less than the window size. |
| `SamplePoints` | `[1 2 3 ...]` | x-axis locations; windows are defined relative to these. Not for timetables (they use row times). |
| `DataVariables` | all numeric | Which table/timetable variables to smooth. |
| `ReplaceValues` | `true` | `false` appends smoothed variables instead of replacing (table/timetable only). |

## Using `smoothdata` for detrending

`"lowess"` / `"loess"` **estimate** a local trend - they do not subtract it.
To detrend a signal whose drift is non-stationary (no single polynomial fits),
estimate the trend and subtract it manually:

```matlab
trend = smoothdata(x, "lowess", win);   % local linear trend estimate
xd    = x - trend;                       % detrended signal
```

This is the alternative to `detrend(x, n)` when the drift shape varies across
the record. See fn-detrend.md for the polynomial path and when to prefer it.

## Verify the auto-chosen window

When you do not pass `window`, `smoothdata` picks one from a heuristic tied to
`SmoothingFactor` (it targets attenuating ~100*factor percent of the input
energy). Capture the choice so it is not a mystery:

```matlab
[B, winsize] = smoothdata(x, "gaussian");   % winsize tells you what it used
```

## Gotchas

- **NaN is ignored by default** (`"omitmissing"`). If you need NaN to
  propagate through the window, pass `"includenan"` explicitly.
- **`SmoothingFactor` and `window` are mutually exclusive.** Pass one or the
  other, not both.
- **`"movmean"` has hard window edges; `"gaussian"` is smoother** in the
  derivative. If a downstream step differentiates the signal, prefer gaussian.
- **`Degree` only applies to `"sgolay"`.** For a non-default polynomial order
  or for derivative output, `smoothdata` is the wrong tool - use
  fn-sgolayfilt.md, which exposes both directly.
- **Operates column-wise on matrices** by default; pass `dim` for row-wise.

## See also

- fn-sgolayfilt.md — the escape hatch for non-default polynomial order or
  derivative output.
- `lowpass` — use instead when you can name a cutoff frequency in Hz.
- fn-detrend.md — polynomial detrending; `smoothdata("lowess")` is the
  non-stationary-drift alternative.
- wf-detrend-smooth-deoutlier.md — where smoothing sits in the recipe.

----

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