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.

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

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

  1. Select exactly one Sound object in Praat.
  2. Run Electrical_Hum_Removal.praat.
  3. For an unknown mains frequency, start with Auto-detect (mild).
  4. If you know the recording contains 50 Hz or 60 Hz hum, choose the corresponding fixed preset or detection mode.
  5. Use Dry_wet_mix as the cancellation depth: 0 leaves the sound unchanged; 1 subtracts the full fitted component.
  6. Leave Output_level_mode at natural level unless you want a safety ceiling or explicit peak normalization.
  7. Click OK. The processed Sound remains selected and can optionally be played immediately.
Important: Auto-detection is deliberately conservative. If it does not find convincing harmonic mains hum, the default behavior is to return the input unchanged. Fixed 50 Hz and Fixed 60 Hz modes intentionally bypass that decision and cancel the requested harmonic series.

Presets

PresetDetectionHarmonicsCancellation depth
CustomUses the current form settingsUser settingUser setting
Auto-detect (mild)Automatic mains detection670%
50 Hz European (strong)Fixed 50 Hz10100%
60 Hz American (strong)Fixed 60 Hz10100%
Studio Recording (subtle)Automatic mains detection550%
Field Recording (aggressive)Automatic mains detection12100%

Preset values override the corresponding detection mode, harmonic count, and cancellation-depth settings.

Parameters

ParameterDefaultMeaning
PresetCustomSelects one of the prepared operating profiles above.
Detection_modeAuto-detect harmonic mains humAutomatic detection, or a fixed 50 Hz / 60 Hz base frequency.
If_no_hum_foundReturn the input unchangedIn Auto mode: bypass, cancel at the best candidate anyway, or stop with a message when the evidence is insufficient.
Max_harmonic8Highest integer harmonic requested for cancellation. Harmonics at or above 85% of Nyquist are skipped.
Dry_wet_mix1.0Cancellation depth. 0 is an exact bypass; 1 subtracts the full fitted sinusoidal component. Intermediate values leave a controlled residual.
Output_level_modeNone (natural level)Leave the result at its natural level, apply an attenuation-only safety ceiling, or peak-normalize to the target level.
Peak_level0.95Target used by Safety ceiling and Peak normalize.
Draw_visualizationOnDraws the diagnostic Picture summary.
Play_resultOnPlays 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.

Limitation: coherent cancellation assumes the hum is reasonably stationary. If its amplitude or phase changes substantially over time, the fitted model may remove only the stable component. Also, a perfectly steady musical tone or harmonic series exactly aligned with 50 Hz or 60 Hz can resemble mains hum spectrally; use Auto mode conservatively when such material is present.

Visualization

The Picture window provides a diagnostic view of what the processor measured and changed:

The visualization is diagnostic only; it does not change the audio.

Output behavior