sidSpectrogram¶
Python equivalent:
sid.spectrogram
Short-time FFT spectrogram.
result = sidSpectrogram(x)
result = sidSpectrogram(x, 'WindowLength', 256, 'Overlap', 128)
result = sidSpectrogram(x, 'Window', 'hamming', 'NFFT', 512)
Computes the short-time Fourier transform (STFT) spectrogram of one or more signals. Replaces the Signal Processing Toolbox spectrogram function with no toolbox dependencies.
Inputs¶
| Name | Description |
|---|---|
x |
Signal data, (N x n_ch) real matrix. Column vector for single channel. Each column is treated as a separate channel. For multiple trajectories: (N x n_ch x L) array. Power spectral density is ensemble-averaged across trajectories within each segment. |
Name-value options¶
| Name | Description |
|---|---|
'WindowLength' |
Segment length L. Default: 256. |
'Overlap' |
Overlap P between segments, 0 <= P < L. Default: floor(L/2). |
'NFFT' |
FFT length. Default: max(256, 2^nextpow2(L)). |
'Window' |
Window type: 'hann' (default), 'hamming', 'rect', or a numeric vector of length L. |
'SampleTime' |
Sample time in seconds. Default: 1.0. |
Outputs¶
| Name | Description |
|---|---|
result |
Struct with fields: |
.Time |
(K x 1) center time of each segment (seconds) |
.Frequency |
(n_bins x 1) frequency vector (Hz) |
.FrequencyRad |
(n_bins x 1) frequency vector (rad/s) |
.Power |
(n_bins x K x n_ch) power spectral density |
.PowerDB |
(n_bins x K x n_ch) power in dB |
.Complex |
(n_bins x K x n_ch) complex STFT coefficients |
.SampleTime |
sample time in seconds |
.WindowLength |
segment length L |
.Overlap |
overlap P |
.NFFT |
FFT length |
.NumTrajectories |
number of trajectories L |
.Method |
'sidSpectrogram' |
Examples¶
% Spectrogram of a chirp signal
Fs = 1000; Ts = 1/Fs; N = 5000;
t = (0:N-1)' * Ts;
x = cos(2*pi * (50 + 100*t/max(t)) .* t);
result = sidSpectrogram(x, 'WindowLength', 256, 'SampleTime', Ts);
sidSpectrogramPlot(result);
Algorithm¶
- Divide signal into overlapping segments of length L
- Apply time-domain window to each segment
- Compute FFT of each windowed segment
- Compute one-sided power spectral density
- If L trajectories: ensemble-average PSD across realizations
References¶
Oppenheim, A.V. and Schafer, R.W. "Discrete-Time Signal Processing", 3rd ed., Prentice Hall, 2010.
Specification¶
SPEC.md §7 — Short-Time Spectral Analysis
See also¶
sidFreqMap, sidSpectrogramPlot
Changelog¶
- 2026-03-28: First version by Pedro Lourenço.