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-frame-and-label.md

View on GitHub
# Workflow: frame long signals + per-frame labels

> Functions used: `signalDatastore`, `framesig`, `framelbl`, `splitlabels`, `subset`

Per-frame supervision: long signals, each file containing many windowed
observations with their own labels. Joint framing of signal and labels.

> **Off-ramp.** If each file is one observation (one signal → one label),
> see wf-load-and-split.md instead.

## Recipe

### Step 1 — Construct the datastore

For ROI-bearing files, load the ROI table alongside the signal:

```matlab
sds = signalDatastore("dataset", FileExtensions=".mat", ...
    SignalVariableNames=["x", "rois"]);
```

`read(sds)` returns a `2×1` cell per file: `{signal; roiTable}` (default
`ReadOutputOrientation="column"`). Linear indexing `c{1}` / `c{2}` works
for either orientation, so the rest of this workflow doesn't depend on the
choice.

### Step 2 — Frame the signal

```matlab
frames = framesig(x, frameLength, OverlapLength=overlap);
% frames is frameLength × numFrames
```

See fn-framesig.md for parameter detail.

### Step 3 — Frame the labels with the same schedule

```matlab
frameLabels = framelbl(rois, frameLength, OverlapLength=overlap, ...
    ConsolidationMethod="mode");
% frameLabels is 1 × numFrames, aligned with frames(:, k)
```

**Decision point — `ConsolidationMethod`.** When ROIs overlap a frame
boundary, you must decide which label wins. Valid values are `"none"`
(default — returns the per-frame raw labels as an `fl × numFrames` matrix,
one column per frame), `"mode"`, `"priority"`, `"max"`, `"median"`,
`"mean"`. Two most common for classification:

- `"mode"` — most-prevalent: the label covering the most samples in the frame.
- `"priority"` — explicit rank order via `PriorityList`.

**Anti-pattern: hand-rolled most-prevalent voting** with a `containers.Map`
accumulator has a *containment trap* — a label whose ROI is fully nested
inside another's ROI never wins a most-prevalent vote. If your labels
nest (e.g. `voiced` inside `speech`), use `priority` with an explicit
`PriorityList`. See fn-framelbl.md for the trap detail.

### Step 4 — Wrap framing into a `transform` for training

One frame per network observation. Wrap steps 2-3 in a transform:

```matlab
sdsFrames = transform(sds, @(c) {framesig(c{1}, frameLength, ...
    OverlapLength=overlap), framelbl(c{2}, frameLength, ...
    OverlapLength=overlap, ConsolidationMethod="mode")});
```

`transform` returns a datastore whose `read()` yields `{frames, frameLabels}`
per file.

### Step 5 — Split (per-file or per-frame)

If the split is **per-file** (frames from the same file stay together —
common to avoid leakage), use the same `splitlabels` + `subset` chain as
wf-load-and-split.md, on a file-level label:

```matlab
fileLabels = filenames2labels(sds, Extract = "subj" + digitsPattern);
splitIndices = splitlabels(fileLabels, [0.7 0.15 0.15]);
sdsTrain = subset(sds, splitIndices{1});
% then transform sdsTrain (not sds) into frames.
```

If the split is **per-frame** (frames are i.i.d. observations regardless
of source file), materialize the framed datastore first and split on the
per-frame label vector. Less common and risks leakage if a single
observation spans the split boundary.

## Anti-patterns (recap)

| Anti-pattern | Why | Detail |
|---|---|---|
| Manual `(i-1)*hopSize+1` framing loop | Reinvents `framesig`; misses streaming semantics | fn-framesig.md |
| `containers.Map` per-sample voting for frame labels | Containment trap — nested labels never win | fn-framelbl.md |
| Splitting per-frame when frames come from the same source file | Leaks information across train/val/test | This file, step 5 |

## Worked end-to-end example

```matlab
sds = signalDatastore("dataset", FileExtensions=".mat", ...
    SignalVariableNames=["x", "rois"]);

frameLength = 1024;
overlap     = 512;

sdsFrames = transform(sds, @(c) { ...
    framesig(c{1}, frameLength, OverlapLength=overlap), ...
    framelbl(c{2}, frameLength, OverlapLength=overlap, ...
        ConsolidationMethod="priority", ...
        PriorityList=["voiced","unvoiced","silence"]) ...
});

% Per-file split:
fileLabels = filenames2labels(sds, Extract = "subj" + digitsPattern);
splitIndices = splitlabels(fileLabels, [0.7 0.15 0.15]);

% Apply the same framing transform on the train subset:
sdsTrain = transform(subset(sds, splitIndices{1}), @(c) { ...
    framesig(c{1}, frameLength, OverlapLength=overlap), ...
    framelbl(c{2}, frameLength, OverlapLength=overlap, ...
        ConsolidationMethod="priority", ...
        PriorityList=["voiced","unvoiced","silence"]) ...
});
```

## Next in the chain

- **Per-file label workflow** (each file = one observation, no framing) →
  wf-load-and-split.md.
- **Hand-off to `trainnet` / `dlarray`** → wf-handoff-to-dl.md.

----

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