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

View on GitHub
# Function: `sgolayfilt`

> Used in: wf-detrend-smooth-deoutlier.md
> Toolbox: Signal Processing Toolbox

Savitzky-Golay FIR smoothing filter. It fits a polynomial of order `m` over a
sliding odd-length frame `fl` and takes the center value. Unlike a moving
average, it preserves higher-order moments - peak height, peak width,
derivatives - which is why it is the tool for spectra, chromatograms, and
transient detection.

This is the **escape hatch**, not the default. `smoothdata`
(fn-smoothdata.md) is the dispatcher you reach for first. Come here only when
you need a polynomial order other than 2 (`smoothdata(x, "sgolay")` fixes
degree 2 unless you set `Degree`) or when you want direct access to the FIR
formulation. `sgolayfilt` has **no defaults** - both `m` and `fl` are
required.

## Signature

```matlab
y = sgolayfilt(x, m, fl)              % order m, frame length fl (both required)
y = sgolayfilt(x, m, fl, w)           % w = weighting vector, length fl
y = sgolayfilt(x, m, fl, w, dim)
```

## Arguments

| Argument | Default | Purpose |
|---|---|---|
| `m` (polynomial order) | **none - required** | Nonnegative integer, must be `< fl`. Order 2-4 is typical. Higher order preserves more signal detail but rejects less noise. |
| `fl` (frame length) | **none - required** | Positive **odd** integer. Must satisfy `fl >= 2*m + 1`. Larger `fl` = more smoothing. |
| `w` (weighting) | `ones(fl,1)` | Real positive vector of length `fl` for the least-squares fit. Use a `kaiser(fl, beta)` window to taper the fit. |
| `dim` | first non-singleton | Dimension to filter along. Default is the first dimension whose size is `> 1`. |

## No defaults - you must pick both `m` and `fl`

There is no `sgolayfilt(x)` form. Sensible starting values:

```matlab
m  = 2;                 % quadratic; go 3-4 for sharper peaks
fl = 11;                % odd, and >= 2*m + 1
y  = sgolayfilt(x, m, fl);
```

- `m` in `{2, 3, 4}` covers almost all uses. Order 2 is the `smoothdata`
  default; pick `sgolayfilt` when you want 3 or 4.
- `fl` odd, `fl >= 2*m + 1`. Larger frame = smoother output.

## Gotchas

- **Both `m` and `fl` are required; no defaults exist.** A caller who expects
  `sgolayfilt(x)` to work is thinking of `smoothdata`.
- **`fl` must be odd.** An even frame length errors.
- **`m` must be `< fl`. If `m = fl - 1` the filter does nothing** - the doc
  states a polynomial of order `fl-1` fits the frame exactly, so the output
  equals the input (no smoothing).
- **Preserves peaks but rejects less noise** than a plain moving average. That
  is the deliberate tradeoff: it is more effective at keeping high-frequency
  signal components and less successful at rejecting high-frequency noise.
- **Operates column-wise on matrices** unless you pass `dim`.

## Choosing between this and the smoothing dispatcher

`sgolayfilt` is the escape hatch (see the intro): reach for it when you need a
polynomial order other than 2, a weighted (`w`) least-squares fit, or the direct
FIR form. Picking a smoother for the job at all - `smoothdata` default vs.
`smoothdata(x,"sgolay")` vs. this vs. `lowpass` - is the workflow decision:
see wf-detrend-smooth-deoutlier.md (Step 3).

## See also

- fn-smoothdata.md — the dispatcher; `smoothdata(x, "sgolay")` is degree 2.
- `lowpass` — use when a cutoff frequency in Hz separates noise from signal.
- `sgolay` — returns the filter matrix if you need the transient-region rows.
- 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