Electrical Hum Removal — User Guide
Detects and removes stable 50 Hz or 60 Hz mains hum and its harmonics by estimating coherent sinusoidal components and subtracting them directly from the sound.
What this does
Electrical Hum Removal is designed for stationary power-line hum: a fundamental near 50 Hz or 60 Hz together with integer harmonics such as 100/120 Hz, 150/180 Hz, and so on. It can detect the mains family automatically or work at a fixed 50 Hz or 60 Hz base frequency.
The processor does not apply a broad notch-filter bank. Instead, it estimates the amplitude and phase of the coherent sinusoidal component at each selected harmonic and subtracts that fitted sinusoid from every channel. Frequencies between the harmonic lines are left untouched by the cancellation stage.
This is a restoration tool for stable tonal hum, not a general broadband denoiser. It is most effective when the unwanted hum keeps approximately constant frequency, amplitude, and phase over the analysed portion of the recording.
Quick start
- Select exactly one Sound object in Praat.
- Run
Electrical_Hum_Removal.praat. - For an unknown mains frequency, start with Auto-detect (mild).
- If you know the recording contains 50 Hz or 60 Hz hum, choose the corresponding fixed preset or detection mode.
- Use Dry_wet_mix as the cancellation depth: 0 leaves the sound unchanged; 1 subtracts the full fitted component.
- Leave Output_level_mode at natural level unless you want a safety ceiling or explicit peak normalization.
- Click OK. The processed Sound remains selected and can optionally be played immediately.
Presets
| Preset | Detection | Harmonics | Cancellation depth |
|---|---|---|---|
| Custom | Uses the current form settings | User setting | User setting |
| Auto-detect (mild) | Automatic mains detection | 6 | 70% |
| 50 Hz European (strong) | Fixed 50 Hz | 10 | 100% |
| 60 Hz American (strong) | Fixed 60 Hz | 10 | 100% |
| Studio Recording (subtle) | Automatic mains detection | 5 | 50% |
| Field Recording (aggressive) | Automatic mains detection | 12 | 100% |
Preset values override the corresponding detection mode, harmonic count, and cancellation-depth settings.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
| Preset | Custom | Selects one of the prepared operating profiles above. |
| Detection_mode | Auto-detect harmonic mains hum | Automatic detection, or a fixed 50 Hz / 60 Hz base frequency. |
| If_no_hum_found | Return the input unchanged | In Auto mode: bypass, cancel at the best candidate anyway, or stop with a message when the evidence is insufficient. |
| Max_harmonic | 8 | Highest integer harmonic requested for cancellation. Harmonics at or above 85% of Nyquist are skipped. |
| Dry_wet_mix | 1.0 | Cancellation depth. 0 is an exact bypass; 1 subtracts the full fitted sinusoidal component. Intermediate values leave a controlled residual. |
| Output_level_mode | None (natural level) | Leave the result at its natural level, apply an attenuation-only safety ceiling, or peak-normalize to the target level. |
| Peak_level | 0.95 | Target used by Safety ceiling and Peak normalize. |
| Draw_visualization | On | Draws the diagnostic Picture summary. |
| Play_result | On | Plays the processed Sound after completion. |
How it works
1. Hum-frequency selection
Fixed modes use exactly 50 Hz or 60 Hz. Auto mode analyses up to the first 10 seconds on a real input channel rather than a mono sum; for multichannel material it uses the channel with the highest RMS.
The detector examines a high-resolution, Hann-windowed spectrum and scores a harmonic comb around the 50 Hz and 60 Hz mains regions. A candidate must contain the fundamental and enough active harmonics above both the local spectral baseline and the global floor. The candidate is then refined from the measured harmonic peaks.
Auto mode also checks that the candidate lies close to a standard mains frequency and, on sufficiently long material, that the frequency remains stable across four sub-blocks. For very short files, a convincing candidate is snapped to the nearer 50 Hz or 60 Hz standard rather than trusting an imprecise measured value.
2. Coherent harmonic fitting
For each requested harmonic below 85% of Nyquist, the script fits a cosine/sine pair separately for every audio channel. The fit uses at most 10 seconds and is shortened to an integer number of mains cycles so that the harmonic frequencies align with the spectral analysis grid.
The fitted amplitude and phase are converted into a sinusoidal model and subtracted directly across the Sound. Each channel is estimated and processed independently, while the same base frequency and harmonic series are used across channels.
3. Cancellation depth
Dry_wet_mix is not a conventional dry/wet blend between two complete signals. It scales the amount of the fitted hum model that is subtracted. At 100%, the full estimated coherent component is removed; at lower values, part of that stationary component is deliberately left in place.
4. Output level
None (natural level) applies no global gain. Safety ceiling attenuates only when the resulting peak exceeds Peak_level. Peak normalize always scales a non-silent result so its peak reaches Peak_level.
Visualization
The Picture window provides a diagnostic view of what the processor measured and changed:
- Original spectrum: LTAS up to 1 kHz (or Nyquist if lower), with vertical markers at the fitted cancellation frequencies.
- Processed spectrum: measured before the output-level stage and shown on the same dB scale as the original.
- Waveforms: the first 0.5 seconds of original and processed audio on one shared amplitude scale.
- Cancellation table: harmonic number, fitted frequency, estimated tone level, and cancellation percentage; up to eight entries are shown explicitly.
- Summary strip: base frequency, number of harmonics, fit duration, cancellation depth, peak before/after the level stage, and processing time.
The visualization is diagnostic only; it does not change the audio.
Output behavior
- Input requirement: exactly one Sound object.
- Channels: preserved; every channel is processed independently.
- Sample rate: preserved.
- Duration: preserved.
- Start time: preserved. Processing uses a temporary time-zero copy and restores the original
xminbefore returning the result. - Randomness: none. The same input and settings are deterministic.
- Bypass:
Dry_wet_mix = 0returns an exact copy without cancellation or output-level processing. In Auto mode, “Return the input unchanged” also bypasses the cancellation when no convincing hum is found. - Output name:
<original>_hum_removed_<preset>. - Peak warning: with natural level, a peak above 1.0 is reported because it can clip when saved to integer PCM.