Hilbert Transform for Drums — User Guide
Hilbert-transform envelope extraction and envelope-driven transient shaping for mono or stereo Sound objects.
What this does
Hilbert Transform for Drums derives a discrete Hilbert transform from the complex Fourier spectrum and uses it either directly as a 90° phase-shifted signal or together with the original waveform to form an analytic-signal magnitude envelope. That envelope can then drive transient contrast or gate-like amplitude shaping.
For a signal x and its Hilbert transform H{x}, the envelope is:
envelope = sqrt(x^2 + H{x}^2)
The envelope is optionally smoothed, normalized to a maximum of 1, and floored at 0.001 for stable multiplication and exponentiation. The script does not perform onset detection, peak picking, or a conventional dynamics-compressor analysis.
Quick start
- Select exactly one mono or stereo Sound object in Praat.
- Run
Hilbert Transform for Drums.praat. - Choose a preset, or use Custom and select an output mode.
- For transient work, adjust transient_amount and envelope_smoothing_ms.
- Set dry_wet_mix. Leave scale_peak = 0 when natural output level should be preserved.
- Run the script. The result is created as a new Sound object; the selected source is not modified.
Output modes
| Mode | Operation | Result |
|---|---|---|
| Transient Enhanced | output = input × envelope^(transient_amount - 1) | Changes attack/sustain contrast using the normalized envelope. |
| Envelope Shaped | output = input × envelope | Gate-like shaping: stronger-envelope regions are retained more strongly; lower-envelope regions are attenuated. |
| Hilbert (90deg shift) | Rotates the positive-frequency complex spectrum by −90°; DC and the Nyquist bin, when present, are set to zero. | The discrete Hilbert-transform signal itself. No envelope or smoothing stage is used. |
| Normalized Envelope | sqrt(x^2 + H{x}^2), optional smoothing, then channel-wise normalization. | A non-negative modulation/analysis contour rather than conventional audio-program material. |
Transient amount
The normalized envelope is approximately in the range 0.001–1. In Transient Enhanced mode, transient_amount = 1 leaves the waveform unchanged before dry/wet mixing. Values above 1 attenuate lower-envelope portions more strongly and therefore increase attack/sustain contrast. Values below 1 apply a negative exponent, raising lower-envelope portions relative to peaks and therefore reducing attack/sustain contrast. This is how the Soft Attack preset works: it does not simply turn transient peaks down; it reduces their contrast relative to the surrounding signal.
Presets
| Preset | Mode | Transient amount | Smoothing | Behavior |
|---|---|---|---|---|
| Custom | User setting | User setting | User setting | Leaves the form values under direct control. |
| Drum Punch | Transient Enhanced | 2.0 | 2 ms | Increases attack/sustain contrast. |
| Soft Attack | Transient Enhanced | 0.5 | 10 ms | Reduces attack/sustain contrast by lifting lower-envelope portions relative to peaks. |
| Phase Shift | Hilbert (90deg shift) | — | Not used | Outputs the Hilbert-transformed signal. |
| Gate Effect | Envelope Shaped | — | 1 ms | Multiplies the source by its normalized envelope for strong envelope-dependent attenuation. |
Presets override only the mode, transient amount, and smoothing values shown above. They do not override dry_wet_mix, scale_peak, visualization, or playback settings.
Parameters
| Parameter | Default | Description |
|---|---|---|
| Preset | Custom | Selects a prepared combination or leaves the remaining controls unchanged. |
| Output_mode | Transient Enhanced | Selects transient shaping, envelope shaping, Hilbert output, or normalized envelope output. |
| transient_amount | 1.5 | Used only in Transient Enhanced mode. Internally clamped to a minimum of 0.1. |
| envelope_smoothing_ms | 5 ms | Controls envelope low-pass smoothing in all envelope-based modes. Values below 0.1 ms are clamped to 0.1 ms. Not used by Hilbert-only mode. |
| dry_wet_mix | 1.0 | 0 = dry, 1 = processed. Values are clamped to 0–1. Intermediate values linearly mix the processed result with the original channel(s). |
| scale_peak | 0 | 0 preserves the natural output level. A value above 0 peak-normalizes the final result to that target after dry/wet mixing. |
| draw_visualization | yes | Draws the AudioTools diagnostic page. |
| play_after_processing | yes | Plays the final Sound object after processing. |
Signal behavior
Hilbert construction
The selected channel is transformed with Praat's full-length Fourier spectrum. The complex spectrum is rotated so that, for stored positive-frequency bins, the new real part comes from the original imaginary part and the new imaginary part is the negative original real part. DC is removed; for an even-length Sound, the Nyquist bin is also removed before inverse transformation.
Envelope smoothing
When smoothing is used, the normalized-magnitude precursor is low-pass filtered with Praat's Hann-band filter from 0 Hz to approximately 1000 / envelope_smoothing_ms Hz, with a transition width equal to 20% of that cutoff. If the requested cutoff reaches or exceeds Nyquist, this smoothing filter is skipped.
Mono and stereo
Mono and stereo inputs are supported; inputs with more than two channels are rejected. Stereo channels are processed independently and recombined in their original order. In Normalized Envelope mode, each stereo envelope is normalized independently to its own maximum, so the envelope output should not be interpreted as preserving the original inter-channel level ratio.
Dry/wet and level
With dry_wet_mix = 0, the Hilbert/envelope calculation is skipped and the source is copied directly. If scale_peak = 0, this is a true dry copy apart from the new object name. If scale_peak > 0, the requested final normalization is still applied even on a fully dry result.
Time and sampling
The final Sound preserves the source sample rate, duration, channel count, and original start time (xmin). Internally, Spectrum-to-Sound synthesis uses a zero-based time domain; the script restores the source start time before naming and returning the output.
No random process is used in the audio algorithm. A random internal identifier is generated only to keep temporary Praat object names unique; it does not affect the samples.
Visualization
When enabled, the script creates an 8-inch AudioTools diagnostic page. Visualization uses temporary mono display copies; the stored audio output is not folded to mono.
- Input waveform and output waveform.
- Input and processed-output spectrograms, up to the lower of 8 kHz or Nyquist.
- First 50 ms detail (or the complete sound if shorter), with input and output overlaid on one shared amplitude scale.
- Summary panel with mode, preset, channel count, sample rate, transient/smoothing settings, wet percentage, and peak-normalization status.
For sources whose time domain does not start at 0, only the temporary visualization copies are shifted to a zero-based display axis. The final Sound retains the original xmin.
Outputs
| Mode | Object suffix |
|---|---|
| Transient Enhanced | _TransientEnhanced |
| Envelope Shaped | _EnvelopeShaped |
| Hilbert (90deg shift) | _Hilbert90 |
| Normalized Envelope | _NormalizedEnvelope |
The complete output name is <originalName>_<modeSuffix>. Temporary processing and visualization objects are removed before completion.
Further Reading
- Oppenheim, A. V., & Schafer, R. W. (2010). Discrete-Time Signal Processing, 3rd ed. Pearson/Prentice Hall. See the treatment of discrete-time Fourier analysis and Hilbert-transform systems.
- Boersma, P., & Weenink, D. Praat Manual: Sound: To Spectrum... — Fourier-transform convention, complex-spectrum storage, Nyquist handling, and Spectrum-to-Sound reconstruction.