From data to plot

2D STFT spectrograms and time–frequency resolution

A single averaged power spectrum discards timing information: it shows which frequencies appear across a recording, not when chirps sweep, oscillations turn on, or bursts decay. A Short-Time Fourier Transform (STFT) spectrogram slides a finite window along time to map power density across both time and frequency, trading temporal localization directly against frequency sharpness.

Updated · 8 min read

On this page
  1. When a static PSD hides non-stationary dynamics
  2. How the 2D spectrogram heatmap untangles the signal
  3. Time–frequency trade-off: nperseg, overlap, and FFT zero-padding
  4. Choosing dB, log₁₀(PSD), or linear scaling and colorbars
  5. Autoplot vs Igor Pro, MATLAB, and SciPy for STFT spectrograms
  6. Spectrogram (STFT) in Autoplot
  7. Frequently asked questions

When a static PSD hides non-stationary dynamics

In a raw 1D time trace (signal_v over time_s below), every oscillation adds together on one vertical amplitude axis. You can spot a brief loudness bump near t=1.8s, yet by eye alone you cannot tell which frequencies exist or whether a pitch is steady or changing.

Computing an averaged 1D power spectrum only reverses the blind spot: pooling all 4 seconds into one frequency curve blurs a moving sweep across a wide flat band and dilutes brief pulses toward the noise floor. To inspect when each frequency turns on, sweeps, or fades—whether tracking seizure onset in clinical EEG spectrograms (Aboyeji et al., 2025) or forecasting peak earthquake ground motion from multi-scale P-wave STFT spectrograms (Hsu and Liu, 2025)—you need time and frequency on separate axes at once.

Autoplot X&Y Plot of the 4,000-sample input waveform signal_v against time_s from 0 to 4 s at 1,000 Hz, showing dense oscillations near ±1.5 V with a brief amplitude swell to roughly ±2.2 V around t = 1.8 s
The raw 4,000-sample input waveform (fs = 1,000 Hz): an envelope burst appears near 1.8 s, but overlapping oscillations hide both the steady 120 Hz tone and the 30–340 Hz chirp.

How the 2D spectrogram heatmap untangles the signal

The Short-Time Fourier Transform (STFT) slices the recording into short, overlapping time windows and runs an FFT power spectrum on each slice (Allen, 1977; Allen and Rabiner, 1977):

S(tm,fk)∝|∑n=0Nw−1x[n+mH]w[n]e−i2πkn/Nfft|2

where Nw=nperseg samples set the slice width, w[n] tapers the window edges, H=Nw−noverlap steps each slice forward in time, and Nfft≥Nw sets the zero-padded frequency grid. Valid frames require uniform sampling (step variation ≤1%) across at least 16 finite samples.

Instead of folding all 4 seconds into one 1D curve, stacking every time slice side by side turns the signal into a 2D time–frequency heatmap (Time (s) across, Frequency (Hz) up, color brightness = power):

  • Horizontal axis (Time (s)): when in the recording each slice was measured (0 to 4 s), matching the horizontal axis of the waveform above.
  • Vertical axis (Frequency (Hz)): how fast the signal oscillates at that moment (0 Hz at the bottom up to 450 Hz at the top), splitting slow and fast waves vertically rather than adding them together.
  • Color (Power (dB re max)): vibration strength at each (time, frequency) cell (0 dB bright yellow = strongest component; -80 dB dark purple = quiet noise floor).

Looking at the spectrogram output below for that exact 1D waveform, all three hidden components separate on sight:

  1. Flat horizontal yellow stripe at 120 Hz: a steady, unchanging tone oscillating from t=0s all the way to t=4s.
  2. Rising diagonal yellow band (30 Hz to 340 Hz): a frequency sweep (chirp) starting slow at t=0s and pitching linearly upward, crossing the 120 Hz carrier near t≈1.16s.
  3. Isolated bright yellow oval at 400 Hz around 1.8 s: the short high-frequency burst that produced the ±2.2V amplitude bump in the raw time trace—pinpointed cleanly in both onset (1.5–2.1 s) and pitch (400 Hz).
Autoplot Heat Map displaying the 2D STFT Spectrogram of signal_v (fs = 1000 Hz, Hann window, Constant detrend, nperseg = 256, 75% overlap, 2x FFT padding, dB scale with 80 dB dynamic range, 0 to 450 Hz) separating the rising linear chirp (30 to 340 Hz), steady 120 Hz horizontal band, and localized 400 Hz burst near t = 1.8 s, alongside the Viridis Power (dB re max) colorbar and Figure Inspector Results showing fs = 1000, Δf = 1.953, Δt = 0.064, grid = 231×59
The 2D STFT heatmap computed from signal_v (nperseg = 256, 75% overlap, 2x FFT pad) reveals what the 1D wave hid: a continuous 120 Hz band, a 30–340 Hz linear chirp, and the short 400 Hz burst near 1.8 s.

Time–frequency trade-off: nperseg, overlap, and FFT zero-padding

Every spectrogram parameter balances how sharply localized ridges look against how closely two simultaneous frequencies can be separated (Gabor, 1946; Harris, 1978):

ControlPhysical roleTypical effectWatch out for
npersegWindow duration Tw=nperseg/fsLonger frames narrow true frequency width (∼fs/nperseg)Excessively long windows blur fast chirps diagonally and widen brief bursts across time
OverlapFrame hop Δt=(nperseg−noverlap)/fsHigher overlap (75%–90%) smooths frame-to-frame transitionsOverlapping segments re-use the same samples and do not improve intrinsic frequency sharpness
FFT PadZero-padding factor (Nfft=nperseg×pad)Interpolates bin spacing Δf=fs/Nfft (1×, 2×, 4×)Finer bin spacing reduces scalloping visual steps but cannot resolve two tones inside one main lobe
Window & DetrendSidelobe taper & per-segment baseline removalHann balances resolution and leakage; Constant strips DC driftBoxcar spills strong narrowband ridges across adjacent frequencies at -13 dB sidelobes

Notice why FFT Pad works differently from doubling nperseg. Zero-padding inserts interpolated spectral samples cleanly along a single main lobe without observing the signal over a longer duration; if two frequencies differ by less than the window main-lobe width (≈2fs/nperseg for Hann), increasing padding from 1× to 4× renders a smoother ridge without splitting them apart.

Choosing dB, log₁₀(PSD), or linear scaling and colorbars

Raw PSD power spans orders of magnitude between coherent tones and background noise floors, so color mapping directly determines what features stay visible. Three intensity modes address distinct comparisons:

LdB(t,f)=max(10log10S(t,f)Smax,−Drange)
  • dB relative to peak (Dyn Range): normalizes power by the peak cell Smax and clamps values below −Drange (20 to 140 dB). Use dB to reveal faint transients and harmonics alongside dominant carriers without zero-floor blowouts.
  • log₁₀(PSD): takes the un-normalized base-10 logarithm of segment density (log10(V2/Hz)). Choose log₁₀(PSD) when comparing signal amplitude across multiple experimental runs on a fixed colorbar range, because normalizing by each trace's own Smax hides global power changes.
  • Linear PSD: plots untransformed S(t,f) directly. Best for checking where dominant energy concentrates when faint sidebands should stay visually suppressed.

Because a spectrogram is rendered inside a 2D color grid, colormap perception and scale discipline follow the same rules as general matrix plots—choose sequential perceptually uniform palettes (Viridis by default) and match colorbar ranges across panels as described in how to make a scientific heat map.

Autoplot vs Igor Pro, MATLAB, and SciPy for STFT spectrograms

Match the tool to whether your task centers on interactive uniform-grid inspection or custom time–frequency research transforms:

CapabilityAutoplot (Spectrogram)Igor ProMATLAB / SciPy
Mac executionNative Apple silicon (macOS 15+)9.05 Intel under Rosetta 2; 10 is Windows-onlyNative macOS binaries and Python scripts
STFT controlsWindow, Detrend, nperseg, Overlap, FFT Pad (1×–4×), Min/Max FreqFFT / STFT wave procedures in Igor proceduresspectrogram, stft, pspectrum, Wavelet Toolbox (cwt)
Intensity scalingLive switch across dB (Dyn Range), log10(PSD), Linear PSDManual log/dB matrix transform after FFTComputed explicitly before plotting
Best roleInteractive spectrogram styling, results readout, and vector export on CSVsLegacy .pxp/.ibw experiments and custom Igor scriptsContinuous wavelets, reassigned/synchrosqueezed STFTs, cross-spectrograms

For real uniform-time CSV or delimited recordings on Apple silicon—especially when replacing everyday plotting and spectrogram checks from Intel-only Igor Pro—Autoplot keeps STFT computation, Viridis/sequential colorbars, grid export, and figure formatting in one interactive canvas. Keep MATLAB or custom SciPy scripts when you need continuous wavelet transforms (CWT), reassigned or synchrosqueezed spectra for razor-sharp chirp ridges, phase extraction, or cross-channel coherence.

In Autoplot

Spectrogram (STFT) in Autoplot

Autoplot's Spectrogram (STFT) analysis (Layers → Run Analysis → Spectrogram (STFT) inside any Heat Map figure, Plus — free for 30 days) runs windowed STFT PSD computation locally on your Mac:

  • Inputs (Data): choose a finite numeric Signal (≥16 finite samples) and optional uniform Time (opt.) (step deviation ≤1% to infer fs automatically and preserve t0), or supply a positive Rate (Hz) when time is omitted.
  • STFT & scaling controls: select Window (Hann, Hamming, Blackman, Flat-Top, Boxcar), Detrend (Constant, Linear, None), nperseg (≥4, blank for auto up to 256), Overlap (0%–90%), FFT Pad (1×, 2×, 4×), Scale (dB, log₁₀(PSD), Linear PSD), Dyn Range (20–140 dB in dB mode), and optional [Min Freq, Max Freq] in Hz, then click Run (Rerun).
  • Results & exports (Figure Inspector → Results, Visual): inspect fs, Δf, Δt, nperseg, overlap, nfft, and grid dimensions (F × T), customize colormap and colorbar in Axes / Range / Visual, or export flattened (time, frequency, value) columns to Derived Variables via Export Spectrogram Data. AI Assistant Execute also drives Spectrogram setup and runs without sending raw array values off your Mac.
  • Where it stops: requires uniform 1D real signals (≤1% step variation); continuous wavelets (CWT), phase/complex STFT outputs, synchrosqueezed transforms, cross-spectrograms, and 2D density/surface fits (disabled while a Spectrogram layer is selected) require either a separate scalar/joint-density Heat Map layer or a Python/MATLAB script.

See features and pricing.

Frequently asked questions

Frequently asked questions
Does increasing FFT Pad improve true frequency resolution?No: FFT Pad appends zeros to extend the DFT length (Nfft=nperseg×pad), which interpolates closer display bins (Δf=fs/Nfft) along the same spectral main lobe. To genuinely separate two closely spaced sinusoids, increase nperseg so each frame observes more signal cycles.
When should I choose log₁₀(PSD) instead of dB?Choose dB (Dyn Range) when studying relative features inside one trace, because dB rescales power relative to that spectrogram's peak cell Smax. Choose log10(PSD) when comparing two separate recordings on an identical color scale so overall signal amplitude shifts remain visible.
Why do short transients smear in frequency or narrowband chirps smear in time?That trade-off is set by the Gabor uncertainty limit: short nperseg windows pinpoint burst onset tightly in time at the expense of wide frequency lobes, whereas long nperseg windows narrow frequency lines while averaging across changing chirp intervals. Tune nperseg for the dominant feature scale, then raise Overlap (75%–90%) for smooth frame stepping.
Can Autoplot run continuous wavelet transforms or phase spectrograms?No: Spectrogram (STFT) computes real one-sided PSD magnitude maps from uniformly sampled 1D signals (scipy.signal.spectrogram). Export derived (time, frequency, value) grids or use PyWavelets / scipy.signal.stft in Python when you need variable-Q wavelet scales, complex phase maps, or reassigned time–frequency ridges.

Sources

Algorithm details (compute_spectrogram, ≤1% uniform grid check, t0 offset alignment, scaling="density" / mode="psd" dB clamping, log10(PSD), and Linear PSD modes) and UI labels (Spectrogram (STFT), nperseg, FFT Pad, Dyn Range, Min Freq, Max Freq, Export Spectrogram Data) were verified directly against Autoplot 2.5.2 source (math_logic.py, HeatMapCardRow.swift, HeatMapResultsPanel.swift, and Autoplot's Spectrogram documentation) on 27 November 2026. Underlying STFT computation wraps SciPy's scipy.signal.spectrogram. Time–frequency resolution trade-offs draw on D. Gabor, "Theory of communication. Part 1: The analysis of information," Journal of the Institution of Electrical Engineers — Part III 93(26), 429–441 (1946), DOI 10.1049/ji-3-2.1946.0074; DFT STFT formulation and filter-bank synthesis draw on J. B. Allen, "Short term spectral analysis, synthesis, and modification by discrete Fourier transform," IEEE Transactions on Acoustics, Speech, and Signal Processing 25(3), 235–238 (1977), DOI 10.1109/TASSP.1977.1162950, and J. B. Allen and L. R. Rabiner, "A unified approach to short-time Fourier analysis and synthesis," Proceedings of the IEEE 65(11), 1558–1564 (1977), DOI 10.1109/PROC.1977.10770; window leakage and scalloping loss draw on F. J. Harris, "On the use of windows for harmonic analysis with the discrete Fourier transform," Proceedings of the IEEE 66(1), 51–83 (1978), DOI 10.1109/PROC.1978.10837; and recent biomedical EEG and seismic STFT spectrogram applications draw on S. T. Aboyeji, I. Ahmad, X. Wang, Y. Chen, C. Yao, G. Li, M. C. F. Tong, A. K. Y. Siu, G. Zhao, and S. Chen, "DCSENets: Interpretable deep learning for patient-independent seizure classification using enhanced EEG-based spectrogram visualization," Computers in Biology and Medicine 185, 109558 (2025), DOI 10.1016/j.compbiomed.2024.109558, and T.-Y. Hsu and K.-L. Liu, "Onsite early prediction of peak amplitudes of ground motion using multi-scale STFT spectrogram," Earth, Planets and Space 77, 60 (2025), DOI 10.1186/s40623-025-02194-w.

Try it on your own data.

Autoplot computes 2D STFT spectrograms with selectable windows, overlap, FFT zero-padding, and dB, log₁₀, or linear scales locally on your Mac. Part of Plus (free for 30 days).

Read power spectral density and 1/fᵅ slopes →
Download .dmg

Without Private Cloud Compute · macOS 15–26

Apple silicon · macOS 15 or later · Free plan · Plus free for 30 days · 11 starter AI credits

Send to my Mac

Autoplot runs on a Mac. Send the link to yourself, or open it in the Mac App Store.