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

View on GitHub
# Function: `retime`

> Used in: wf-uniform-rate.md, wf-align-channels.md
> Toolbox: MATLAB (base) — timetable method

Resample or aggregate the data in a **single** timetable onto a new set of
row times.
Use it to put one timetable onto a uniform grid, change its rate, or move it
onto an explicit time vector.

For merging several timetables onto a shared time base, use `synchronize`
(fn-synchronize.md) — `retime` operates on one table at a time.

## Signature

```matlab
TT2 = retime(TT1, newTimeStep, method)                     % 'hourly', 'daily', ...
TT2 = retime(TT1, 'regular', method, 'SampleRate', Fs)     % uniform at Fs
TT2 = retime(TT1, 'regular', method, 'TimeStep', dt)       % uniform at spacing dt
TT2 = retime(TT1, newTimes, method)                        % explicit target time vector
TT2 = retime(TT1, ___)                                     % method omitted -> fillwithmissing
```

`method` selects how each variable is adjusted at the new times.

### Interpolating / carrying methods (upsampling, arbitrary times)

| `method` | Behavior | Reach for when |
|---|---|---|
| `'linear'` | Linear interpolation | Default first reach. Signal is smooth, no invented bandwidth. |
| `'pchip'` | Shape-preserving cubic | You want smoothness without linear kinks; no overshoot. |
| `'spline'` | Cubic spline | Signal is known-smooth (physical model); tolerate edge overshoot. |
| `'makima'` | Modified Akima | Smoother than pchip, still shape-preserving; fewer oscillations than spline. |
| `'previous'` / `'next'` | Hold the previous / next sample | Zero-order hold; signal is a held setting (throttle, valve state). |
| `'nearest'` | Nearest sample in time | Categorical or quantized data where interpolation is meaningless. |
| `'fillwithmissing'` (default) | Insert `NaN` at new times | You want the grid changed but no values fabricated. |
| `'fillwithconstant'` | Insert a constant (`Constant` NV) | You have a known default for absent samples. |

### Aggregating methods (downsampling into bins)

`'mean'`, `'sum'`, `'prod'`, `'min'`, `'max'`, `'median'`, `'mode'`,
`'firstvalue'`, `'lastvalue'`, `'count'` — each new time is a bin, and the
rule collapses the samples that fall in it.
Use these when the new rate is **coarser** than the input (many samples per
new time), not when interpolating up.

## Name-value pairs

| NV-pair | Default | Purpose |
|---|---|---|
| `EndValues` | `'extrap'` | Extrapolation rule for interpolation methods. `'extrap'` extends past the data; a scalar clips to that value at the ends. |
| `Constant` | — | Fill value when `method` is `'fillwithconstant'`. |
| `IncludedEdge` | `'left'` | Bin edge included when aggregating (`'left'` or `'right'`). |

## Rule selection is the whole decision

**Pick the right adjust method.** The split:

- **Upsampling / arbitrary new times -> interpolating method.** Choose by signal character: `'linear'` unless you can justify smoothness (`'pchip'`/`'makima'`) or a held value (`'previous'`).
- **Downsampling -> aggregating method.** `'mean'` decimates with averaging; `'lastvalue'` takes a snapshot. Do not use an interpolating method to downsample — it ignores the samples between grid points.

## Gotchas

- **Method omitted = `fillwithmissing`.** `retime(TT, newTimes)` with no method inserts `NaN`, it does not interpolate. Same trap as `synchronize`.
- **`'linear'` extrapolates by default** (`EndValues='extrap'`). New times outside the input span get extended trend values. Pass `EndValues=NaN` to refuse.
- **Interpolating to a coarser grid loses information.** If the new spacing is wider than the input, an interpolating method samples the curve at the new times and silently drops everything between — use an aggregation rule instead.
- **No antialiasing — do not use `retime` to downsample a signal.** Interpolating (or even aggregating) onto a coarser grid does not run an anti-alias filter, so real bandwidth folds back into the band silently. For any genuine rate *reduction* of signal content, use `resample` / `decimate` (fn-resample.md); reserve `retime` for regularizing jitter or upsampling.
- **`'regular'` needs a rate.** `retime(TT,'regular',method)` alone errors; supply `'SampleRate'` or `'TimeStep'`.
- **Duplicate or unsorted row times** must be resolved first; `retime` errors on duplicates unless the method is an aggregation rule that bins them.

## See also

- fn-synchronize.md — the multi-timetable sibling (same method vocabulary, merges several tables).
- fn-resample.md — antialiased rate conversion for a signal / timetable; use when you need the FIR antialiasing filter, not plain interpolation.
- wf-uniform-rate.md — non-uniform timestamps to a uniform grid.
- wf-align-channels.md — bringing multi-rate channels together.

----

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