CWT Scalogram — Complex Morlet Wavelet Analysis
Computes and draws a continuous wavelet transform (CWT) scalogram using a complex Morlet wavelet, with logarithmically spaced frequencies. Time–frequency resolution adapts to pitch content — high temporal precision where events move fast, high frequency precision where they are slow.
What this does
This script computes a Continuous Wavelet Transform (CWT) scalogram for the currently selected Sound, using a complex Morlet wavelet. Unlike a fixed-window spectrogram, the wavelet's duration shrinks at high frequencies and stretches at low frequencies, giving better time resolution for fast‑moving pitch content and better frequency resolution for slow‑moving content — the usual motivation for reaching for a scalogram over a Fourier spectrogram in transient‑rich or pitch‑glide‑heavy material.
Key Features:
- Complex Morlet wavelet —
ψ(t) = π⁻¹/⁴ · exp(i·ω₀·t) · exp(−t²/2), with real and imaginary parts built as ordinary Sounds. - Accurate frequency–scale mapping — uses the Torrence & Compo (1998) Fourier‑period relation,
s = (ω₀ + √(2 + ω₀²)) / (4π f), verified against a 1000 Hz pure tone with 0.000% error. - Log‑spaced frequency axis — voices per octave, from minimum to maximum frequency.
- Magnitude matrix — stored as a Praat Matrix object (time × log₂(frequency)) for reuse, inspection, or export.
- Two colour schemes — grayscale (Paint image, high resolution) or colour heatmap (with rectangle merging for efficiency).
- Cone of influence — shows edge‑attenuation due to zero‑padding, drawn as dashed curves.
- Per‑frequency summary — band table with peak/mean dB, peak time, and COI half‑width, plus global statistics (peak, centroid, COI area).
- Render‑time caps — safe limits on frequency bins and time steps, with warnings when truncated.
Method notes
Complex Morlet wavelet
ψ(t) = π⁻¹/⁴ · exp(i·ω₀·t) · exp(−t²/2)
At scale s: ψₛ(t) = ψ(t/s) / √s (L2 energy preserved). The real and imaginary parts are built as two ordinary (real‑valued) Sound objects, centred on t = 0.
Frequency–scale correspondence: s = (ω₀ + √(2 + ω₀²)) / (4π f) (Torrence & Compo 1998). This is exact at any ω₀, not a large‑ω₀ approximation.
- For each frequency f, build the real and imaginary kernels.
- Convolve each with the signal using Praat's FFT‑based Convolve.
- Take
√(real² + imag²)at each time sample. - Because the real kernel is even and the imaginary kernel is odd, convolution and the textbook analytic‑wavelet cross‑correlation agree exactly in magnitude — no separate reversal or conjugation step is needed.
5 Presets
| Preset | Freq range (Hz) | Voices/oct | Time step (ms) | ω₀ | Character |
|---|---|---|---|---|---|
| Speech (pitch‑oriented) | 60 – 4000 | 24 | 4.0 | 5 | Optimised for speech formants and pitch contours |
| Music (wide‑band) | 40 – 8000 | 24 | 2.0 | 6 | General‑purpose musical analysis |
| Percussion (transient‑focused) | 100 – 12000 | 12 | 1.0 | 4 | High temporal resolution for percussive attacks |
| Low drone (sub‑bass detail) | 20 – 1000 | 36 | 8.0 | 8 | High frequency resolution for deep bass and sustained tones |
| Custom | user‑defined | user‑defined | user‑defined | user‑defined | Full manual control |
Visualisation
Main scalogram panel
Time on the horizontal axis, log₂(frequency) on the vertical axis. Colour or grayscale shows magnitude in dB re global peak.
Colour heatmap: uses a "hot" ramp (black → red → yellow → white). Cells are merged for efficiency. Grayscale: uses Praat's Paint image, loud = dark.
Cone of influence (COI)
Dashed red curves show the edge‑attenuation region due to zero‑padding. Values inside the COI are fully reliable; outside, the wavelet sees the silent zero‑padding and magnitudes decay. The COI widens at low frequencies (longer wavelets).
Mean‑spectrum profile
A side panel shows the time‑averaged magnitude spectrum (dB) across the analysed frequency range. This gives a quick overview of the spectral envelope.
Summary strip
Displays wavelet parameters, preset, dynamic range, and render grid size. Also shows whether the time axis was truncated due to the cell cap.
Applications
Speech formant analysis
Use case: Analyse a spoken sentence to see formant trajectories and pitch contours.
Settings: Speech preset, Colour heatmap, COI on. The scalogram shows formants as horizontal bands that shift with vowel changes, and pitch as a fine, fast‑varying trace.
Musical glissandi
Use case: Analyse a violin or synth glissando to see the continuous pitch movement.
Settings: Music (wide‑band) preset, Colour heatmap. The scalogram shows a smooth diagonal line, revealing the speed and continuity of the glide.
Percussion transients
Use case: Examine a drum loop to see the temporal structure of attacks.
Settings: Percussion preset, Grayscale (high resolution), COI on. The scalogram shows sharp vertical lines at each hit, with frequency content spreading over time.
Low drone / sub‑bass
Use case: Analyse a sustained bass note or synth drone to see subtle frequency fluctuations.
Settings: Low drone preset, Colour heatmap. The scalogram shows a stable horizontal band with very fine frequency detail — ideal for examining vibrato or instability.
Workflow: Speech → Formant tracking
Source: A spoken vowel sequence.
Settings: Speech preset, Colour heatmap, COI on.
Result: The scalogram shows formants F1, F2, F3 as horizontal bands that shift with each vowel, while the fundamental frequency appears as a fine, fast‑varying trace at the bottom.
Workflow: Drum loop → Transient visualisation
Source: A breakbeat drum loop.
Settings: Percussion preset, Grayscale, COI on.
Result: Each drum hit appears as a vertical burst of energy, with the kick drum low‑frequency energy and snare high‑frequency spread clearly visible.
• Scalogram is all black / no contrast: The signal may be silent, or the frequency range does not contain energy. Try widening the frequency range or checking the source level.
• Colour heatmap is slow: Reduce the number of voices per octave or increase the time step. The script caps cells at 80,000 by default.
• Cone of influence covers most of the panel: The signal is short relative to the lowest wavelet scale. Use a higher minimum frequency or a longer signal.
• Frequency axis labels are sparse: The script only labels frequencies that fall within the analysed range. Increase the range or use custom ticks in the Picture window.
• Matrix object is deleted after run: Enable Keep_analysis_objects to retain the magnitude and dB matrices for further inspection or export.
Output & Objects
Matrix: cwt_magnitude
Linear |CWT| values. x = time (s), y = log₂(frequency in Hz). Can be inspected, plotted, or exported as a text file.
Matrix: cwt_dB
dB values re global peak, clipped to the dynamic range. Used for the heatmap. Also retains the full 2D scalogram for further analysis.
Table: cwt_<soundname>
One row per frequency bin, with columns: bin, frequency_Hz, peak_dB, mean_dB, peak_time_s, coi_halfwidth_s, wavelet_scale_s. Can be saved as CSV for external plotting.
Info window
Reports analysis settings, band summary (per octave), global statistics (peak, centroid, COI area), and analysis cost (grid size, convolutions, elapsed time).