Hilbert Transform (Time-Reversed Envelope) — User Guide

Extract amplitude envelope using Hilbert transform, reverse it in time, and apply it backwards to create retrograde envelope effects with preserved pitch.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 0.1 (2025) License: MIT License Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

What this does

This script performs time-reversed envelope processing using the Hilbert transform — a sophisticated signal processing technique that extracts the amplitude envelope of a sound (how loud it is over time) and applies it backwards. The result: sounds that seem to "grow" into their attacks rather than decay from them. Imagine drums that swell into the hit, voices that inhale into words, or music that builds backwards into each note. The pitch and harmonic content remain unchanged — only the amplitude contour is reversed. This creates dreamlike, reversed-yet-forward, impossibly organic temporal effects.

Key Features:

What is the Hilbert Transform? The Hilbert transform creates an "analytic signal" — a complex representation of audio that separates amplitude (envelope) from phase (frequency content). Think of it as extracting the "shape" of sound over time independent of its pitch. Normal envelope followers (peak detection, RMS) are crude approximations. Hilbert transform is mathematically exact: it creates a 90-degree phase-shifted version of the signal, combines it with the original to form a complex number at each sample, then calculates the magnitude. This magnitude is the instantaneous amplitude envelope — smooth, continuous, capturing subtle amplitude variations impossible to extract otherwise. Used in: modulation analysis, speech processing, seismic analysis, and experimental music (Trevor Wishart, Curtis Roads).

Technical Implementation: (1) Convert Sound to Spectrum using FFT or DFT, (2) Create Hilbert transform via 90-degree phase shift: swap real/imaginary components and negate, (3) Convert Hilbert spectrum back to time domain → hilbert_sound, (4) Calculate envelope: sqrt(original² + hilbert²) — this is the analytic signal magnitude, (5) Scale and optionally sharpen envelope with exponent, (6) High-pass filter envelope to reduce low-frequency buildup, (7) Reverse original sound in time, (8) Multiply reversed sound by forward-time envelope (applies envelope backwards), (9) Reverse result back to forward time → sound with time-reversed envelope, (10) Peak normalize. Key insight: Because we reverse the sound, apply the envelope, then reverse again, the final result has pitch/timbre moving forward but amplitude envelope moving backward.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…Hilbert Transform.praat.
  3. Leave defaults (fast_fourier: no, sharpening off, highpass 50Hz) for standard envelope reversal.
  4. Click OK — script extracts envelope, reverses it, applies backwards, plays result.
  5. Experiment with envelope sharpening (exponent 0.5-0.8) for more dramatic swells.
Quick tip: Start with default settings on short files (under 30 seconds). Try on drums for reverse-swell effect, on vocals for inhale-into-words quality. Processing creates dreamlike, "building backwards" effect. Enable envelope sharpening (apply_envelope_sharpening: yes, exponent 0.7) for more pronounced swells. Script shows "WARNING" about runtime — Hilbert transform requires two FFT operations, making it slower than simple reverb effects.
Important: LONG PROCESSING TIME — Hilbert transform requires multiple FFT calculations. Files over 1 minute can take 30+ seconds. Files over 5 minutes can take several minutes. This is normal and unavoidable (mathematical necessity of analytic signal computation). Progress not shown during FFT — Praat will appear frozen but is working. For very long files, consider processing shorter segments. Effect cannot be previewed — must complete entire process. Save work before processing long files.

Hilbert Transform Theory

🌊 Analytic Signal Fundamentals

Real signal: Standard audio — real numbers representing amplitude

Analytic signal: Complex representation — amplitude (magnitude) + phase (angle)

Hilbert transform: Creates imaginary component that pairs with real signal

Key insight: Magnitude of analytic signal = instantaneous envelope, independent of phase/frequency

The Hilbert Transform Operation

Mathematical Foundation

Standard audio signal:

s(t) = A(t) · cos(φ(t)) where: A(t) = amplitude envelope (what we want to extract) φ(t) = instantaneous phase (frequency information)

Hilbert transform creates:

H{s(t)} = A(t) · sin(φ(t)) (90-degree phase shift — cos becomes sin)

Analytic signal combines both:

z(t) = s(t) + i·H{s(t)} = A(t) · [cos(φ) + i·sin(φ)] = A(t) · e^(iφ) (Euler's formula — complex exponential form)

Envelope extraction:

envelope(t) = |z(t)| = √[s(t)² + H{s(t)}²] = A(t) (magnitude of complex number = envelope amplitude)

Why Hilbert Transform?

Traditional envelope methods (crude):

Hilbert transform advantages:

Frequency-Domain Implementation

The Hilbert transform is most efficiently computed in frequency domain:

Step 1: FFT — Convert time-domain sound to frequency-domain spectrum

Original spectrum: Real part: cosine components Imaginary part: sine components

Step 2: 90-degree phase shift — Swap and negate components

Hilbert spectrum formula: if row=1 then Spectrum[2,col] else -Spectrum[1,col] Translation: New real part = original imaginary part New imaginary part = -(original real part) This rotates each frequency by 90 degrees in complex plane

Step 3: Inverse FFT — Convert Hilbert spectrum back to time domain

Result: hilbert_sound Time-domain representation of 90-degree phase-shifted signal Has same frequencies as original, different phase relationship

Step 4: Envelope calculation — Compute magnitude of analytic signal

envelope = sqrt(original² + hilbert²) For each sample: Take original sample value Take hilbert sample value Square both, add, take square root Result: instantaneous amplitude at that moment

Time Reversal Process

Once envelope extracted, script applies it backwards:

Visual Representation

Original sound with natural envelope:

Time → Attack Sustain Decay /‾‾‾‾‾‾‾‾‾‾‾\___ Drum hit: sharp attack, quick decay

Extracted envelope (via Hilbert):

Envelope: /‾‾‾‾‾‾‾‾‾‾‾\___ Smooth curve representing amplitude over time

Reversed envelope:

Reversed: ___/‾‾‾‾‾‾‾‾‾‾‾\ Now builds from silence to peak, then quick cutoff

Applied to original sound (not reversed):

Result: Pitch/timbre same direction (forward) Amplitude contour opposite direction (backward) Sound "swells" into its attack, then cuts off Dreamlike, impossible-in-nature quality

Envelope Sharpening

The script offers optional envelope shaping via exponentiation:

Formula: envelope_shaped = envelope^exponent

ExponentEffectUse Case
1.0No change (original envelope)Natural envelope contour
0.8Slight sharpening (default when enabled)Moderate enhancement of swells
0.5Strong sharpening (square root)Dramatic swells, gates-like effect
0.3Extreme sharpeningHarsh gating, abrupt transitions
2.0Smoothing (squaring)Gentler swells, reduced dynamics
3.0Heavy smoothing (cubing)Very gradual swells, compressed feel

Mathematical Effect

Sharpening (exponent < 1):

Smoothing (exponent > 1):

Example with exponent 0.5 (square root):

Original envelope value: 0.25 → sqrt(0.25) = 0.5 (doubled) Original envelope value: 0.5 → sqrt(0.5) = 0.707 (increased) Original envelope value: 0.75 → sqrt(0.75) = 0.866 (slightly increased) Original envelope value: 1.0 → sqrt(1.0) = 1.0 (unchanged) Effect: Quiet parts become louder relative to peaks Creates more uniform amplitude distribution Swells feel more sudden, dramatic

High-Pass Filtering

The envelope is high-pass filtered to reduce low-frequency dominance:

Why necessary:

High-pass filter (default 50 Hz):

Smoothing parameter (default 10 Hz):

Adjusting Filter Parameters

MaterialCutoff (Hz)Smoothing (Hz)Reason
Bass-heavy (EDM, hip-hop)80-10015-20More aggressive filtering to prevent boom
Balanced mix5010Default — works for most material
Sparse, acoustic30-405-10Gentler filtering preserves envelope subtlety
High-frequency (cymbals)50-7010Standard filtering adequate

Processing Steps Breakdown

Complete signal flow:

  1. Original Sound — Input audio
  2. → Spectrum — FFT to frequency domain
  3. → Hilbert Spectrum — 90-degree phase shift
  4. → Hilbert Sound — Inverse FFT to time domain
  5. → Envelope — sqrt(original² + hilbert²)
  6. → Scaled Envelope — Peak normalization
  7. → Shaped Envelope — Optional exponentiation
  8. → Filtered Envelope — High-pass filter
  9. → Reversed Original — Time-reverse input sound
  10. → Reversed with Envelope — Multiply reversed sound by forward envelope
  11. → Final Sound — Reverse back to forward time
  12. → Normalized Output — Final peak scaling
Historical Context: The Hilbert transform was developed by David Hilbert in early 1900s for mathematical analysis. Applied to signal processing in 1940s-50s (radar, communications). Gabor (1946) used analytic signal concept for time-frequency analysis. In music: Trevor Wishart's "Audible Design" (1994) explored envelope manipulations. Curtis Roads' "Microsound" (2001) detailed granular techniques using Hilbert envelopes. Modern applications: speech processing (extracting formants), medical imaging (MRI), seismic analysis, and experimental electronic music. This script makes mathematically sophisticated envelope extraction accessible in Praat for creative audio work — what required custom C/Fortran code in 1980s now runs as simple script.

Parameters

Core Settings

ParameterTypeDefaultDescription
fast_fourierbooleannoUse FFT (fast) vs DFT (precise but slow)
apply_envelope_sharpeningbooleannoEnable envelope shaping via exponentiation
sharpening_exponentpositive0.8Exponent for envelope shaping (<1 sharper, >1 smoother)
highpass_cutoffpositive50High-pass filter cutoff frequency (Hz)
highpass_smoothingpositive10Filter smoothing/rolloff (Hz)
scale_peakpositive0.99Peak normalization level
play_after_processingbooleanyesAuto-play result when complete
show_info_reportbooleanyesDisplay processing info in info window
keep_intermediate_objectsbooleannoKeep intermediate objects for inspection

Parameter Details

fast_fourier

Options: no (DFT, default) or yes (FFT)

Why default is "no" (DFT):

When to use FFT (yes):

Performance comparison @ 1 minute 44.1kHz:

apply_envelope_sharpening

Options: no (off, default) or yes (enabled)

Disable (no): Natural envelope contour preserved

Enable (yes): Envelope shaped by exponentiation

When to enable:

When to disable:

sharpening_exponent

Range: 0.1-10.0 (practical: 0.3-3.0)

Default: 0.8 (moderate sharpening)

Common values:

Effect inactive if apply_envelope_sharpening disabled.

highpass_cutoff

Range: 10-200 Hz (practical: 30-100 Hz)

Default: 50 Hz

Purpose: Remove low-frequency components from envelope itself

Adjust lower (30-40 Hz):

Adjust higher (70-100 Hz):

highpass_smoothing

Range: 1-50 Hz (practical: 5-20 Hz)

Default: 10 Hz

Lower values (5 Hz): Sharp filter cutoff, more aggressive

Higher values (20 Hz): Gentle rolloff, more transparent

Recommendation: Keep default 10 Hz unless specific need

scale_peak

Range: 0.1-1.0 (practical: 0.9-0.99)

Default: 0.99

Purpose: Final output normalization

0.99: Maximum loudness with tiny headroom

0.95: Moderate safety margin

0.9: Conservative, guaranteed no clipping

play_after_processing

Options: yes (default) or no

Enable: Immediate audition after long processing wait

Disable: No playback — useful for batch work

show_info_report

Options: yes (default) or no

Enable: Display processing summary in Praat info window

Disable: Silent processing

Info report contains: Original filename, output name, duration, confirmation of processing complete

keep_intermediate_objects

Options: