Skip to content

Signal Example — Time-Frequency Analysis

Interactive demo comparing three time-frequency analysis methods on a synthetic multi-component signal, with controls for baseline normalization and frequency-axis scaling.

Signal Example 3

What it shows

RowPlotDescription
1Time DomainSynthetic signal averaged across 20 trials. Dashed line = t = 0.
2Time-Frequency MapPower heatmap from the selected method, optionally baseline-corrected.

Up to three independent frequency components can be active simultaneously, each with its own onset–offset interval. This lets you directly compare how each method handles multiple overlapping signals with different frequencies and timings.

The Core Idea: Heisenberg's Uncertainty Principle

You cannot have perfect time and frequency resolution simultaneously — narrowing one always blurs the other. Every TF method is a choice about where to make that trade-off.

MethodWindowResolution trade-off
Morlet WaveletGaussian, adaptiveAt 10 Hz: wide window → sharp frequency, poor time. At 40 Hz: narrow window → sharp time, blurry frequency. The window scales automatically with frequency.
STFT (Hanning)Hanning, fixedSame window length for all frequencies → uniform resolution. 233 ms window gives ~4 Hz frequency resolution at every band.
Multitaper (DPSS)Slepian tapers, adaptiveLike Morlet but averages across multiple orthogonal tapers → lower variance estimates at the cost of slight frequency smoothing.

Cohen (2014), Ch. 12–13 — Morlet Wavelets and Wavelet Convolution Cohen (2014), Ch. 15 — Short-time FFT Cohen (2014), Ch. 16 — Multitaper

Baseline Normalization

Raw TF power cannot be compared across methods, frequencies, or participants because absolute power varies with electrode impedance, distance from the source, and method-specific scaling. Baseline normalization expresses power relative to a reference period (typically pre-stimulus).

MethodFormulaRangeWhen to use
Noneraw powerunboundedComparing absolute power (rarely appropriate)
dB10·log₁₀(P / BL)unbounded, 0 at baselineMost robust for EEG — log compression handles large dynamic range
% Change100·(P − BL) / BLunbounded, 0 at baselineIntuitively interpretable scale
Z-score(P − BL_mean) / BL_stdz-unitsGroup-level comparison; requires stable baseline std
RelativeP / BL_meanratio, 1 at baselineClean background; can't compare across frequencies
Rel. Change(P − BL) / BLratio, 0 at baselineLike % Change without the ×100
Norm. Change(P − BL) / (P + BL)−1 to +1Sensitive to small fluctuations in low-SNR regions
AbsoluteP − BLsame units as powerRarely used; frequency-dependent bias

The baseline window defaults to −1.0 – 0.0 s (pre-stimulus). Move it with the IntervalSlider — it can be placed anywhere in the epoch.

Cohen (2014), Ch. 18 — Time-Frequency Power and Baseline Normalizations

Things to Try

1. The resolution trade-off (Morlet) Enable Comp 1 (10 Hz, 0.0 – 0.8 s), baseline = dB. Sweep the Param slider from 3 to 12 cycles: watch the blob grow narrow in frequency but wide in time at high cycles, and vice versa. This is Heisenberg in action.

2. Morlet vs. STFT on the same signal Add Comp 3 (40 Hz, 1.0 – 2.0 s). Switch between Morlet and STFT with Param = 7. Notice:

  • STFT: all three component blobs are the same rectangular shape regardless of frequency.

  • Morlet: the 10 Hz blob is wider in time, the 40 Hz blob is narrower — because the window adapts.

3. STFT onset artifact Set Param to 3 (short window = 100 ms), enable only Comp 1, set baseline = None. Switch to STFT. The "flame" pattern at onset is real physics: as the fixed Hanning window slides past the signal's hard edge at t = 0, it captures successive phases of the 10 Hz oscillation, producing structured amplitude modulation across the transition. Switch to Morlet — the Gaussian taper handles the onset far more gracefully.

4. Multitaper variance reduction Enable all three components with a moderate noise (Noise = 2.0). Toggle rapidly between Morlet and Multitaper: the Multitaper map is smoother because it averages independent spectral estimates from multiple orthogonal Slepian tapers, reducing random variance without introducing the bias that additional smoothing would.

5. Baseline normalization sensitivity Set three components active and baseline = dB. Sweep the baseline window across the stimulus period: you can clearly see the baseline reference contaminating the normalization when signal is included. Move it back to pre-stimulus only to see clean dB increases.

6. Log frequency axis Enable the Log toggle. Low frequencies are spread out — revealing fine structure in the 1–10 Hz range — while high frequencies compress. This matches the 1/f power distribution of real EEG.

Controls

ControlRangeDescription
MethodMorlet / STFT / MultitaperTF decomposition method
Param3–12Cycles (Morlet/Multitaper) or window ≈ N/30 Hz in ms (STFT)
Noise0.5–5Amplitude of additive white noise per trial
BaselineNone / dB / % Change / …Baseline correction method (all EegFun tf_baseline types)
Window−1.0–2.0 sBaseline time window (IntervalSlider)
Freq scaleLinear / LogToggle log₁₀ y-axis on the TF map
☐ Comp 1/2/3on/offEnable/disable each component
Freq (×3)1–40 HzComponent frequency
Amp (×3)0–5Component amplitude
Interval (×3)−1.0–2.0 sComponent onset–offset window (IntervalSlider)

See Also

Code

julia
using EegFun
EegFun.signal_example_tf()