matlab/matlab-agentic-toolkit / skills-catalog/signal-processing/matlab-prepare-signal-data
matlab-prepare-signal-data
VerifiedUse 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`.
references/fn-hampel.md
View on GitHub# Function: `hampel`
> Used in: wf-detrend-smooth-deoutlier.md
> Toolbox: Signal Processing Toolbox
Sliding-window outlier detector-and-replacer. For each sample it computes the
median of a window (the sample plus `k` neighbors per side) and estimates the
local standard deviation from the median absolute deviation. A sample more
than `nsigma` local standard deviations from the local median is replaced with
that median.
SPT-only. Use it when you want the same result as
`filloutliers(..., "movmedian")` *plus* the outlier mask and local statistics.
On a matrix, each column is an independent channel.
## Signature
```matlab
y = hampel(x) % k=3 (window 7), nsigma=3
y = hampel(x, k) % window = 2*k+1
y = hampel(x, k, nsigma)
[y, j] = hampel(___) % j = logical outlier mask
[y, j, xmedian, xsigma] = hampel(___) % local median + local sigma
hampel(___) % no output: plots signal + flagged outliers
```
## Arguments
| Argument | Default | Purpose |
|---|---|---|
| `k` | `3` | Neighbors per side. Window length is `2*k+1` (so default is 7). |
| `nsigma` | `3` | A sample must differ from the local median by more than `nsigma` local standard deviations to be flagged. |
## Outputs (the audit trail)
| Output | What it is |
|---|---|
| `y` | Filtered signal (outliers replaced with local median). |
| `j` | Logical mask, same size as `x`, true at flagged outliers. |
| `xmedian` | Local median at every sample. |
| `xsigma` | Estimated local standard deviation at every sample. |
The `[y, j, xmedian, xsigma]` outputs are the reason to pick `hampel` over
`filloutliers`: you get the flagged locations and the local median/sigma
bands, which plot directly as detection thresholds.
## Relationship to `filloutliers`
`hampel(x, k, nsigma)` is the same algorithm as:
```matlab
filloutliers(x, "center", "movmedian", 2*k+1, ThresholdFactor=nsigma)
```
The doc names the `"movmedian"` method "the Hampel filter." Choose between
them on outputs, not on the underlying math:
- Want a smooth interpolated fill instead of local median? `filloutliers`
with `"linear"`/`"pchip"`. See fn-filloutliers.md.
- Want the mask and local statistics for an audit trail? `hampel`.
## Gotchas
- **Default window is only 7 samples** (`k=3`). At `fs=1 kHz` that is 7 ms,
too short for many physiological signals. Bump `k` to roughly `fs/100` or
`fs/50` for a 10-20 ms window.
- **Endpoints use a truncated window.** Samples within `k` of the edge are
compared to a smaller window; the doc shows they can be flagged as outliers
more readily. Inspect the ends of `j`.
- **Column-wise on matrices.** Each column is an independent channel; expect
per-channel behavior.
- **Sparse spikes only.** Like `filloutliers`, it needs a normal local
majority. For dense impulse noise (>~10% of samples) use `medfilt1`
(fn-medfilt1.md).
- **Handles NaN in the window** but does not target NaN gaps. To fill missing
samples, that is fn-fillmissing.md / fn-fillgaps.md, not `hampel`.
## See also
- fn-filloutliers.md — same algorithm, control over the fill rule.
- fn-medfilt1.md — the dense-noise alternative.
- `isoutlier(x, "movmedian", win)` — detection mask only, no fill.
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |