Generated banner for Matlab Analyze Time Frequency Content
Generated logo for Matlab Analyze Time Frequency Content

Matlab Analyze Time Frequency Content

MathWorksOfficialCreated by MathWorks

  • Skill
  • Tool integration
  • Science and research
  • BSD-2-Clause
  • No issues found

From the author

Perform time-frequency analysis in MATLAB using CWT, STFT, synchrosqueezing, reassignment, wavelet coherence, cross spectrogram, EMD/VMD, multiresolution analysis, and time-frequency filtering. Triggers on: time-frequency, spectrogram, scalogram, cwt, stft, istft, fsst, wsst, wcoherence, xspectrogram, modwt, modwtmra, modwpt, emd, vmd, hht, tffilt, dgt, gabor, instantaneous frequency, synchrosqueezing, reassignment, ridge extraction, wavelet coherence, cross spectrum, mode decomposition, signal decomposition, time-frequency filtering.
— the description by MathWorks

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a comprehensive framework for analyzing how frequency content evolves over time using MATLAB. It covers a wide range of analytical techniques including Short-Time Fourier Transform (STFT), Continuous Wavelet Transform (CWT), synchrosqueezing, reassignment, and adaptive signal decomposition (EMD/VMD). The skill is designed to help users select the appropriate method based on their specific signal characteristics and research goals, offering guidance on visualization, mode extraction, and cross-signal analysis.

What it does

  • Visualizes time-frequency content using spectrograms and scalograms.
  • Supports advanced signal decomposition via EMD, VMD, and multiresolution analysis.
  • Enables mode extraction and signal reconstruction from time-frequency representations.
  • Computes time-varying coherence and cross-spectra between two signals.
  • Provides diagnostic tools to assess signal properties before analysis.
  • Offers a decision logic for choosing between STFT, CWT, and other transform methods.

When to use it

  • When you need to analyze the evolution of frequency content over time.
  • When choosing between different time-frequency representations like STFT or CWT.
  • When you need to extract and reconstruct individual signal components.
  • When comparing two signals using time-varying coherence or cross-spectrum analysis.
  • When decomposing signals into additive time-domain components.

Advantages

  • Provides a structured decision tree for selecting the optimal analysis method.
  • Includes diagnostic scripts to assess signal length, bandwidth, and nonstationarity.
  • Supports both interactive exploration and programmatic data analysis.
  • Clearly distinguishes between invertible and non-invertible analysis techniques.
  • Offers specific guidance on handling boundary effects and frequency resolution.

Usage examples

“How do I visualize the time-frequency content of a non-stationary signal?”
The agent will recommend using signalAnalyzer for interactive exploration or cwt for multi-resolution visualization, depending on the signal's bandwidth.
“I need to extract a specific mode from my signal using synchrosqueezing.”
The agent will guide you through the fsst or wsst workflow, including ridge extraction and subsequent signal reconstruction.
“How can I compare the time-varying coherence of two signals?”
The agent will provide the wcoherence syntax and explain how to interpret the phase arrows and coherence magnitude.
“What is the best way to decompose a signal into adaptive components?”
The agent will recommend emd or vmd based on whether the number of components is known and provide the necessary function calls.

Install

Documentation by MathWorks

Time-Frequency Analysis in MATLAB

Analyze how frequency content evolves over time using STFT, CWT, synchrosqueezing, reassignment, cross-signal methods, and data-adaptive decomposition.

Agent directive: Consult the reference guides in references/ before answering. Each guide covers a specific domain with syntax, gotchas, and common mistakes.

When To Use

  • Analyzing how frequency content evolves over time (spectrogram, scalogram)

  • Choosing between STFT, CWT, synchrosqueezing, reassignment, or EMD/VMD

  • Extracting and reconstructing individual signal components from a TF representation

  • Computing time-varying coherence or cross-spectrum between two signals

  • Decomposing signals into additive time-domain components (wavelet MRA, EMD, VMD)

  • Estimating instantaneous frequency or Hilbert spectrum

When Not To Use

  • Designing or applying classical FIR/IIR filters — use matlab-design-digital-filter

  • Extracting scalar features for ML classification — use matlab-extract-signal-features

  • Signal preprocessing (resampling, detrending, gap filling) — use matlab-prepare-signal-data

  • Quadratic/bilinear TFDs (Wigner-Ville) — not supported in MATLAB toolboxes

  • Audio-specific representations (mel spectrogram, MFCC) — use Audio Toolbox

Method Selection

Choose the analysis method based on the user's goal and signal characteristics:

GoalMethodGuide
Interactive TF exploration (spectrogram + scalogram)signalAnalyzer—
General TF visualization (uniform freq resolution)stft, spectrogram, pspectrumreferences/stft-guide.md
TF visualization (multi-resolution, constant-Q)cwt, cwtfilterbankreferences/cwt-guide.md
Sharpest TF picture (non-invertible)spectrogram("reassigned"), pspectrum(Reassigned=true)references/reassignment-guide.md
Remove specific TF regions (mask-based filtering)tffilt with binary maskreferences/stft-guide.md
Mode extraction + reconstruction (STFT domain)fsst → tfridge → ifsstreferences/reassignment-guide.md
Mode extraction + reconstruction (CWT domain)wsst → wsstridge → iwsstreferences/reassignment-guide.md
Signal reconstruction from CWTicwt (exact or approximate)references/cwt-guide.md
Additive decomposition (octave bands)modwt + modwtmrareferences/multiresolution-guide.md
Additive decomposition (uniform bands)modwptdetailsreferences/multiresolution-guide.md
Adaptive decomposition (unknown components)emdreferences/multiresolution-guide.md
Adaptive decomposition (known mode count)vmdreferences/multiresolution-guide.md
Hilbert spectrum / instantaneous frequencyhht, instfreqreferences/multiresolution-guide.md
Time-varying coherence between two signalswcoherencereferences/cross-analysis-guide.md
Cross spectrogram between two signalsxspectrogramreferences/cross-analysis-guide.md
Global coherence (no time axis)mscohere, cpsdreferences/cross-analysis-guide.md

For detailed decision logic, see references/method-selection-guide.md.

Quick Decision Tree

What is the primary goal?
│
├── Interactive exploration (adjust parameters, compare views)
│   └── signalAnalyzer — supports spectrogram + scalogram (CWT) side by side
│
├── Visualize one signal's TF content
│   ├── Need uniform frequency resolution? → stft / spectrogram / pspectrum
│   ├── Need multi-resolution (better low-freq)? → cwt
│   └── Need sharpest picture (no reconstruction)? → spectrogram("reassigned")
│
├── Remove unwanted content visible in spectrogram
│   └── Define binary mask over TF plane → tffilt (Gabor domain)
│
├── Extract and reconstruct individual components
│   ├── From TF representation (invertible)?
│   │   ├── STFT domain → fsst → tfridge → ifsst
│   │   └── CWT domain → wsst → wsstridge → iwsst
│   ├── Additive time-domain components?
│   │   ├── Octave bands → modwt + modwtmra
│   │   ├── Uniform bands → modwptdetails
│   │   └── Data-adaptive → emd or vmd
│   └── From CWT directly? → icwt (see references/cwt-guide.md)
│
├── Compare two signals
│   ├── Time-varying coherence? → wcoherence
│   ├── Time-varying cross-spectrum? → xspectrogram
│   └── Global relationship? → mscohere / cpsd
│
└── Estimate instantaneous frequency
    ├── Single monocomponent signal? → instfreq(x, fs)
    ├── Multicomponent (want per-mode IF)? → emd → instfreq(imf, fs)
    └── Multicomponent (want single average)? → instfreq(x, fs, Method="tfmoment")

Critical Rules

  1. stft has no reassignment option. Use fsst for invertible synchrosqueezing or spectrogram("reassigned") for non-invertible visualization.

  2. wsstridge argument order differs from tfridge:

    • wsstridge(sst, penalty, f, ...) — penalty is 2nd positional arg

    • tfridge(tfm, f, penalty, ...) — penalty is 3rd positional arg

  3. wsst subtracts the signal mean internally. iwsst does NOT restore it. Add mean(x) back manually if DC matters.

  4. ifsst is machine-precision; iwsst is approximate (Morlet single-integral formula).

  5. xspectrogram first output is real (cross-spectrogram magnitude). For phase, use the 4th output P. This differs from spectrogram whose first output is complex STFT.

  6. wcoherence has no Parent option. For App Designer, compute outputs and plot manually.

  7. wcoherence phase arrows show the phase lag of Y relative to X:

    • ↑ = Y lags X by π/2

    • ↓ = Y leads X by π/2

    • → = in-phase

    • ← = anti-phase PhaseDisplayThreshold (default 0.5) is plot-only — it controls which arrows are drawn but has no effect on returned numeric outputs.

  8. hht takes IMFs, not raw signal. Always decompose first: imf = emd(x); hht(imf, fs).

  9. instfreq Hilbert method is meaningless for multicomponent signals. Decompose first, or use Method="tfmoment" for a single average curve.

  10. Synchrosqueezing is precision-sensitive. Use double-precision data with fsst/wsst for reproducible results across MATLAB, codegen, and GPU.

Signal Assessment Workflow

When the user provides a signal and asks "what should I use?", run the assessment script then apply agent-side interpretation:

Step 1: Run MATLAB assessment
report = assessSignalForTF(x, fs);
disp(report)
disp(report.recommendations)

The script returns: signal length, occupied bandwidth, number of spectral peaks (with frequencies), nonstationarity indicator, DC content, precision, and auto-generated recommendations.

Step 2: Agent-side interpretation (combine script output with user goals)
User GoalKey Report FieldsRecommendation Logic
"Explore / I'm not sure what I need"—Suggest signalAnalyzer for interactive exploration (spectrogram + scalogram views, adjustable parameters)
"Visualize frequency content over time"likelyNonstationary, fractionalBandwidthIf wideband (>2 octaves): cwt. If narrowband or uniform resolution needed: stft/spectrogram
"Separate/extract components"numSpectralPeaks, peakFrequenciesHz2–3 peaks: synchrosqueezing (fsst/wsst). Many peaks: emd/vmd. Closely-spaced: modwptdetails or fsst
"Reconstruct after filtering"hasDC, precisionfsst/ifsst for exact. wsst/iwsst for CWT-domain (warn about mean). icwt for CWT bandpass
"Compare two signals"(run on both)wcoherence for coherence. xspectrogram for cross-spectrum
"Detect transients/events"signalLength, occupiedBandHzcwt with low TimeBandwidth. Or short-window stft
Step 3: Refine with follow-up questions if ambiguous
  • "Do you need to reconstruct the signal, or just visualize?"

  • "Do you need uniform frequency resolution, or is multi-resolution acceptable?"

  • "Are you comparing this signal to another?"

Reference Guides

FileCoverage
references/stft-guide.mdstft/istft, spectrogram, pspectrum, stftmag2sig, length preservation, COLA
references/cwt-guide.mdcwt, cwtfilterbank, icwt, dlicwt/icwtLayer, boundary, constant-Q
references/reassignment-guide.mdfsst/ifsst, wsst/iwsst, spectrogram("reassigned"), pspectrum(Reassigned=true), ridge extraction, penalty
references/cross-analysis-guide.mdwcoherence, xspectrogram, cpsd, mscohere, phase arrows, unsmoothed cross-spectrum
references/multiresolution-guide.mdmodwt/modwtmra, modwpt/modwptdetails, emd, vmd, hht, instfreq, instbw
references/method-selection-guide.mdDecision logic for choosing among all methods

Toolbox Requirements

ToolboxFunctions
Signal Processingstft, istft, spectrogram, pspectrum, fsst, ifsst, tfridge, xspectrogram, instfreq, instbw, stftmag2sig, cpsd, mscohere
Waveletcwt, cwtfilterbank, icwt, wsst, iwsst, wsstridge, wcoherence, modwt, modwtmra, modwpt, modwptdetails, emd, vmd, hht, tffilt, dgt
FunctionAvailable FromNote
tffiltR2025aTF mask-based filtering; all other functions available in R2024b

Documentation References


Copyright 2026 The MathWorks, Inc.


Files

references/cross-analysis-guide.md

Cross-Signal Time-Frequency Analysis Guide

DomainCross-spectrumCoherenceToolbox
CWTwcoherence (2nd output)wcoherence (1st output)Wavelet
STFTxspectrogram— (no time-varying STFT coherence)Signal Processing
Global (no time axis)cpsdmscohereSignal Processing

Wavelet Coherence: wcoherence

wcoherence computes magnitude-squared wavelet coherence and the wavelet cross-spectrum between two equal-length real signals. It provides time-resolved coherence with automatic scale-smoothing.

Syntax
[wcoh, wcs, f, coi, wtx, wty] = wcoherence(x, y, fs);
[wcoh, wcs, f, coi, wtx, wty] = wcoherence(x, y, fs, ...
    FrequencyLimits=[flo fhi], VoicesPerOctave=16);
wcoherence(x, y, fs);   % no outputs → auto-plot with phase arrows
% NOTE: wcoherence has no Parent option — cannot direct plot to a specific
% axes/uiaxes. For App Designer or tiled layouts, compute outputs and
% reimplement the plot manually (imagesc + quiver for phase arrows).
Outputs
OutputContentSize
wcohMagnitude-squared coherence ∈ [0, 1]nFreq × nTime
wcsComplex wavelet cross-spectrum (smoothed CWT_x · conj(CWT_y))nFreq × nTime
fFrequency vector (Hz)nFreq × 1
coiCone of influence (Hz)1 × nTime
wtxCWT of x (individual wavelet coefficients)nFreq × nTime
wtyCWT of y (individual wavelet coefficients)nFreq × nTime
Key Details
  • Wavelet is always amor (analytic Morlet) — not configurable

  • VoicesPerOctave range: 10–32 (default 12; narrower than wsst's 10–48)

  • Coherence formula: |smooth(CWT_x · conj(CWT_y))|² / (smooth(|CWT_x|²) · smooth(|CWT_y|²))

  • Smoothing is across scales (not time) via NumScalesToSmooth (default: min(floor(nScales/2), VoicesPerOctave))

  • Both signals must be real and equal length (≥ 4 samples)

  • NumOctaves controls frequency range (default: fix(log2(N))-1); cannot combine with FrequencyLimits or PeriodLimits

  • Supports duration objects for sampling period and PeriodLimits for geophysical/climate data

  • COI boundary effects are significant at low frequencies — discard or flag regions outside COI

Period-Based Analysis (Geophysical / Climate Data)
% Input sampling interval as a duration → output in period units
wcoherence(x, y, years(1/12), PhaseDisplayThreshold=0.7);
[wcoh, wcs, P, coi] = wcoherence(x, y, seconds(0.1));
% P is now period vector (not frequency), COI is in period units
% PeriodLimits restricts the analysis range
[wcoh, wcs, P, coi] = wcoherence(x, y, years(1/12), PeriodLimits=[years(0.5) years(8)]);

When using period-based input, the y-axis displays period (low periods at top, high periods at bottom) and the COI is inverted relative to frequency-based plots.

Phase Relationship

The cross-spectrum phase angle(wcs) gives the phase lag of Y relative to X at each time-frequency point. When plotted (zero-output call), arrows show this lag:

  • → (right): in-phase — Y and X aligned (lag = 0)

  • ← (left): anti-phase (lag = ±π)

  • ↑ (up): Y lags X by π/2

  • ↓ (down): Y leads X by π/2 (lag = −π/2)

The arrow angle equals angle(wcs) measured counterclockwise from rightward.

PhaseDisplayThreshold (default 0.5) suppresses phase arrows where coherence is below the threshold — plot-only, has no effect on returned outputs. Values above 0.7 typically produce clean, interpretable plots. When working programmatically (with outputs), apply your own mask: phase(wcoh < 0.7) = NaN.

Converting Phase to Time Delay

At a given frequency (or period), phase difference translates to time delay:

% Frequency-based: delay in seconds
delay = angle(wcs) ./ (2*pi*f);     % f is frequency vector (Hz)

% Period-based: delay as fraction of period
delay = angle(wcs) / (2*pi) .* (1./f);  % equivalent

For geophysical data at period P: a phase of π (anti-phase) = delay of P/2.

Typical Workflow
% 1. Compute coherence
[wcoh, wcs, f, coi] = wcoherence(x, y, fs);

% 2. Identify time-frequency regions of high coherence
mask = wcoh > 0.8;

% 3. Extract phase relationship in those regions
phase_diff = angle(wcs);
phase_diff(~mask) = NaN;

% 4. Determine lead/lag (convert phase to time delay)
% At frequency f_k, a phase difference φ corresponds to delay φ/(2πf_k)
delay = phase_diff ./ (2*pi*f);
When wcoherence vs cwt
GoalUse
Analyze ONE signal's time-frequency contentcwt
Compare TWO signals' shared oscillatory activitywcoherence
Extract phase/lag between signals at specific frequencieswcoherence (use angle(wcs))
Perform individual CWTs of both signalswcoherence (use 5th/6th outputs wtx, wty)
Advanced: Unsmoothed Cross-Spectrum and Velocity Change Estimation

The smoothed wcs (2nd output) trades temporal precision for stable coherence estimates. For applications requiring finer temporal resolution (e.g., seismic velocity monitoring), compute the unsmoothed cross-wavelet spectrum from the individual CWTs (5th/6th outputs):

[wcoh, wcs, f, coi, wtref, wtcurr] = wcoherence(ref, curr, fs, ...
    FrequencyLimits=[0.5 5], VoicesPerOctave=32, NumScalesToSmooth=3);

% Unsmoothed cross-wavelet spectrum — finer temporal detail
xwt = wtref .* conj(wtcurr);

% Phase-to-delay: Δt(f,t) = φ(f,t) / (2πf)
phi = unwrap(angle(xwt), [], 2);       % unwrap along time axis
timeDelay = phi ./ (2*pi*f);            % f is column vector, broadcasts

% Weight by cross-spectrum amplitude (suppress low-energy regions)
W = log(1 + abs(xwt));
W = W ./ max(W, [], 2);                % normalize per frequency

% Relative velocity change: dv/v = -Δt/t
% Fit delay vs. travel-time using weighted least squares (lscov)

Key points:

  • NumScalesToSmooth=3 reduces smoothing for tighter temporal tracking

  • unwrap(..., [], 2) prevents ±π jumps along the time dimension

  • Weighting by log(1+|xwt|) downweights regions with poor SNR

  • Use lscov for weighted least-squares when fitting delay vs. frequency or delay vs. time

  • The smoothed wcs is appropriate for coda-wave analysis (scattered energy); unsmoothed xwt is better for direct-wave phase tracking

Cross Spectrogram: xspectrogram

xspectrogram computes the time-varying cross-spectrum between two signals using the STFT. It uses the same windowed-segment approach as spectrogram.

Syntax
[S, F, T, P] = xspectrogram(x, y, window, noverlap, nfft, fs);
xspectrogram(x, y, window, noverlap, nfft, fs);   % no outputs → plot
Outputs
OutputContent
SMagnitude of cross-spectrum (
FFrequency vector
TTime vector
PComplex cross-power spectral density (4th output) — use for phase
Key Details
  • Interface mirrors spectrogram: same window/noverlap/nfft/fs positional args

  • Critical difference from spectrogram: spectrogram's first output is the complex STFT; xspectrogram's first output S is the cross-spectrogram — a purely real, non-negative quantity (abs(cpsd(...))). For the complex cross-spectrum (needed for phase), request the 4th output P.

  • Internally computes cpsd segment-by-segment (no cross-segment averaging)

  • No reassignment option — unlike spectrogram("reassigned")

  • Both signals must be real, finite, non-sparse vectors

  • Supports FrequencyRange ("onesided", "twosided", "centered") and SpectrumType ("psd", "power")

Typical Workflow
% 1. Compute cross spectrogram
win = hann(256);
[S, F, T, P] = xspectrogram(x, y, win, 200, 512, fs);

% 2. Plot magnitude
figure;
imagesc(T, F, 10*log10(S));
axis xy; colorbar;
xlabel('Time (s)'); ylabel('Frequency (Hz)');
title('Cross Spectrogram Magnitude');

% 3. Extract phase difference (from 4th output)
phase_diff = angle(P);

% 4. Find coherent regions (threshold on magnitude)
coherent = S > 0.1 * max(S(:));

Non-Time-Resolved Cross-Analysis (Welch Methods)

When you don't need time resolution (stationary relationship):

FunctionOutputUse Case
cpsd(x, y, window, noverlap, nfft, fs)Complex cross-PSDFrequency-domain transfer function estimation
mscohere(x, y, window, noverlap, nfft, fs)Coherence ∈ [0, 1]Frequency bands where signals are linearly related

These use Welch averaging (segment + average), giving a single spectrum — no time axis. The time-dependent nature of coherent behavior is completely obscured by these methods. Use wcoherence when the coherence relationship is non-stationary (appears/disappears over time, or the phase lag evolves).

Decision Guide: Which Cross-Analysis Function?

Need time-resolved cross-analysis?
├── YES
│   ├── Want coherence (normalized measure)?
│   │   └── wcoherence (wavelet domain, multi-resolution)
│   ├── Want cross-spectrum with uniform frequency resolution?
│   │   └── xspectrogram (STFT domain)
│   └── Want both time-varying coherence AND uniform freq resolution?
│       └── No single function — compute xspectrogram, then manually
│           normalize: |Sxy|² / (Sxx · Syy) per time-frequency bin
│           (requires spectrogram of each signal individually)
└── NO (stationary/global relationship)
    ├── Cross-power spectral density → cpsd
    └── Magnitude-squared coherence → mscohere

Common Mistakes

MistakeWhy It's WrongCorrect Approach
Using mscohere when time resolution is neededmscohere averages across time (Welch method) — no time axisUse wcoherence for time-varying coherence
Expecting xspectrogram to give coherencexspectrogram returns cross-spectrum magnitude, not normalized coherenceNormalize manually, or use wcoherence
Using first output of xspectrogram for phaseFirst output S is magnitude (real)Use 4th output P for complex cross-spectrum
Passing complex signals to wcoherenceOnly real signals acceptedTake real/imag parts separately, or use magnitude
Expecting xspectrogram("reassigned")Cross spectrogram has no reassignment optionUse standard xspectrogram; for sharp cross-analysis, use wcoherence
Using different VoicesPerOctave > 32 with wcoherenceMaximum is 32 (unlike wsst which allows 48)Keep VoicesPerOctave ≤ 32
Ignoring cone of influence in wcoherenceBoundary effects contaminate edge regionsMask or discard time-frequency points outside COI
Interpreting wcoherence phase without checking coherence magnitudePhase is meaningless where coherence is lowOnly interpret angle(wcs) where wcoh > threshold (typically 0.5–0.8)
Using wcoherence(..., Parent=ax) to embed in App Designerwcoherence has no Parent option (unlike xspectrogram/spectrogram)Compute outputs programmatically, then build the plot manually with imagesc + quiver for phase arrows

Documentation References


Copyright 2026 The MathWorks, Inc.


Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
MathWorks
Publisher
MathWorks (Official)
Source
matlab/matlab-agentic-toolkit · skills-catalog/signal-processing/matlab-analyze-time-frequency-content · commit 2a7f215
Licence
BSD 2-Clause License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.

Get it from the source

1 of this skill’s files are not mirrored here, so there is no ZIP. Get the complete skill from its source: matlab/matlab-agentic-toolkit