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/wf-uniform-rate.md

View on GitHub
# Workflow: put one channel on a uniform rate (regularize / resample)

> Functions used: `retime`, `resample`, `decimate`, `interp`, `interp1`, `isregular`

A single channel goes onto a uniform grid at a chosen rate — whether it started
with irregular/jittery timestamps OR is already uniform but at the wrong rate.

> **Off-ramp.** Two or more channels that need a shared grid is align, not
> regularize — see wf-align-channels.md.

## When to use

One channel that you need on a uniform grid at a chosen rate. Two entry cases,
same machinery:

- **Non-uniform / jittery timestamps -> uniform grid.** The decision is which
  `retime` adjust method, and whether you need antialiasing (`resample`).
- **Already uniform, but the wrong rate -> new rate** (e.g. 1 kHz -> 400 Hz for a
  downstream pipeline). This is a pure rate change — pick the function from the
  table below.

## Pick the rate-change function first

`resample` is the general default, but it is NOT always right. Choose before you
code:

| Your situation | Reach for | Why / not `resample` |
|---|---|---|
| Non-integer or arbitrary ratio; non-uniform input | `resample(x, p, q)` (`[p,q]=rat(fsNew/fsOld)`) or `resample(x, tx, fs)` | The generalist: rational ratio, antialiased, linear phase, delay-compensated. |
| Integer factor, waveform SHAPE / peak timing must survive | `decimate(x, r, 'fir')` (down) / `interp(x, r)` (up) | `decimate`'s DEFAULT filter is IIR (nonlinear phase) -> distorts pulse shape; the `'fir'` flag is linear phase. |
| Integer factor, must PRESERVE original samples exactly | `interp(x, r)` or `interp1` on the original grid | `resample` filters *every* value, so it MODIFIES the original samples. `interp` passes originals through unchanged. |
| You will supply your own antialias/anti-image filter | `upfirdn` | Full control of the polyphase filter. |

**Never** `downsample`/`upsample` alone — they only stride / zero-stuff with no
filter, so they alias (down) or leave spectral images (up). Use them only with
your own filter or on already-band-limited data.

**`resample` gotchas** (once you have chosen it): integer `p,q` (never a float);
and the endpoint assumption — it treats the signal as zero outside the span, so a
large offset/trend rings at the edges (detrend -> resample -> re-trend). Full
contract: fn-resample.md.

## Recipe

### Step 1 — Confirm it is actually non-uniform

```matlab
isregular(TT)          % false => needs regularizing
```

### Step 2 — Put it on a uniform grid

Timetable path (the usual reach):

```matlab
TT2 = retime(TT, 'regular', 'linear', 'SampleRate', fs);
```

Numeric-vector path, or when you want antialiasing:

```matlab
[y, ty] = resample(x, tx, fs);     % non-uniform tx -> uniform fs, antialiased
```

### Step 3 — Pick the adjust rule deliberately

Rule selection is the one real decision here: pick `'linear'` (honest default)
unless the signal justifies something else - `'pchip'`/`'makima'` for known-smooth
no-kinks, `'previous'` for a held setting (throttle/valve, where interpolation
would be wrong), aggregation for coarser-than-input output. Do not default to
`'spline'` for "smoothness". The full method table is in fn-retime.md.

### `retime` vs `resample` here

- `resample(x, tx, fs)` / `resample(xTT)` — antialiased. **The default for any rate *reduction*** (target rate at or below the signal's content bandwidth). Applies the FIR anti-alias filter so nothing folds back into the band.
- `retime(...,'linear',...)` — plain interpolation, **no antialiasing**. Only for jitter cleanup or upsampling at the same-or-higher rate. **Never use it to lower the rate below the signal's content — it aliases silently.** See fn-resample.md.

## Gotchas

- **Method omitted = NaN fill**, not interpolation. `retime(TT, newTimes)` alone inserts `NaN`.
- **`'linear'` extrapolates by default** (`EndValues='extrap'`). Pass `EndValues=NaN` to keep from inventing values past the data span, then fill deliberately (wf-repair-missing.md).
- **`'regular'` needs `SampleRate` or `TimeStep`** — it errors alone.

## See also

- fn-retime.md — method vocabulary and rule selection.
- fn-resample.md — antialiased alternative.
- wf-align-channels.md — the multi-channel case.
- wf-repair-missing.md — fill any NaNs left behind.

----

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