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

View on GitHub
# Workflow: extract a signal's envelope

> Functions used: `envelope`

Extract the amplitude outline of a signal - the smooth curve that rides the
peaks (and troughs) rather than the signal itself. This mirrors the
**Envelope** pane in Signal Analyzer's preprocessing.

> **Off-ramp - do you actually want the envelope, or a cleaner signal?**
> `envelope` is NOT a denoiser. It returns the AMPLITUDE OUTLINE, discarding
> the carrier. If you want a cleaned version of the signal itself, you're in
> the denoise family - see wf-denoise.md, not here.

## When to reach for it (distinct from smoothing)

Reach for `envelope` when the *amplitude trend* is the quantity of interest,
not the signal:

- **AM demodulation** - recover the modulating envelope of an
  amplitude-modulated carrier.
- **Amplitude / energy tracking** - how loud is this over time (audio RMS
  loudness, vibration amplitude, burst energy).
- **Peak-hull tracking** - the upper/lower bound curve that hugs an
  oscillation (decaying sinusoid outline, fault-signature amplitude).
- **Feature for ML** - the envelope is often a more stable input than the
  raw carrier for classifying amplitude-varying signals.

How this differs from smoothing (wf-denoise.md): a smoother returns a signal
that still oscillates, just with less noise. `envelope` returns a curve that
does NOT oscillate at the carrier frequency - it traces the peaks. If your
answer still has the carrier in it, you wanted smoothing; if it's the outline
above/below the carrier, you wanted envelope.

## Choosing the method

`envelope` has three methods; the method is the third positional argument.

| Method | Call | Use when |
|---|---|---|
| **analytic** (default) | `envelope(x)` or `envelope(x, fl, "analytic")` | Narrowband / AM-style signals. Uses the Hilbert transform of an FIR-filtered version; `fl` is the Hilbert filter length. The smooth analytic envelope. Default when you call `envelope(x)` or `envelope(x, fl)`. |
| **rms** | `envelope(x, wl, "rms")` | Energy / loudness tracking. Moving-RMS over a window of `wl` samples. Good for audio level and vibration amplitude. |
| **peak** | `envelope(x, np, "peak")` | Peak-hull / spline-through-peaks. Fits a spline over local maxima (and minima) separated by at least `np` samples. Good for tracing a decay envelope or a jagged peak outline. |

Both an upper and a lower envelope come back:
`[yupper, ylower] = envelope(...)`.

## Choosing the length parameter

The second positional argument means something different per method:

- **analytic**: `fl` = Hilbert FIR filter length. Larger `fl` = smoother,
  more selective envelope but more edge transient. Start modest (tens of
  samples) and increase if the envelope is too jagged.
- **rms**: `wl` = window length in samples. Set it to roughly one period of
  the slowest amplitude variation you want to follow. Too short tracks the
  carrier; too long over-smooths the amplitude trend.
- **peak**: `np` = minimum peak separation in samples. Set it near the
  carrier period so the spline hits one peak per cycle, not the noise
  wiggles between peaks.

## Recipe

```matlab
% Analytic (default) - AM demod / narrowband amplitude
[yup, ylo] = envelope(x, fl, "analytic");

% RMS - loudness / energy over a wl-sample window
[yup, ylo] = envelope(x, wl, "rms");

% Peak - spline hull over peaks at least np samples apart
[yup, ylo] = envelope(x, np, "peak");
```

1. Confirm you want the amplitude outline, not a cleaned signal
   (if you want the signal cleaned, see wf-denoise.md).
2. Pick the method from the table (AM/narrowband -> analytic; energy -> rms;
   peak hull -> peak).
3. Set the length parameter relative to the carrier period as above.
4. Overlay `yupper` (and `ylower`) on the original to confirm it hugs the
   peaks without tracking the carrier or over-smoothing.
5. Emit a runnable `.m` script.

## Gotchas

- **`envelope` needs the Signal Processing Toolbox** (not a separate license
  like `wdenoise`, but not base MATLAB either).
- **It discards the carrier by design** - do not use it expecting a denoised
  signal.
- **Column-wise on matrices** - each column is an independent channel.
- **Edge transients** on the analytic method grow with `fl`; the first/last
  `~fl/2` samples of the envelope are less reliable.

## Signatures & mechanism (folded from the function detail)

```matlab
[yupper, ylower] = envelope(x)                 % analytic via DFT hilbert (exact, full-length)
[yupper, ylower] = envelope(x, fl, "analytic") % analytic via length-fl Hilbert FIR
[yupper, ylower] = envelope(x, wl, "rms")      % moving RMS over wl-sample window
[yupper, ylower] = envelope(x, np, "peak")     % spline through peaks >= np samples apart
envelope(___)                                  % no output args -> plots signal + envelopes
```

- `envelope(x)` (DFT `hilbert`) and `envelope(x, fl, "analytic")` (FIR) are
  **distinct algorithms**, not one call with a default — passing a length
  switches from the DFT `hilbert` to the FIR Hilbert filter (which is where the
  edge transients come from; the first/last ~`fl/2` samples are less reliable).
- `x` is processed **column-wise** on a matrix (one channel per column).
- Primitives behind the three methods: `hilbert`, `findpeaks`, `movmean` /
  `movmax` / `movmin`, `rms`. Signal Processing Toolbox; introduced R2015b.

## Related

- If you actually wanted to clean the signal: wf-denoise.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