Skip to content

A notch for mains hum

Mains hum (60 Hz, or 50 Hz in Europe) and its harmonics sit right inside the LFP band, so a low-pass cannot remove them. A notch takes out one frequency and leaves the rest: one per line (here 60 Hz and its third harmonic, 180 Hz). The synthetic recording knows its hum, so the result can be checked against the recording without it.

import numpy as np
import dspk
from plating import signals
s = signals.synthetic()
Q = 30.0 # width: the notch spans about freq / Q Hz
out = dspk.ops.filter.notch(s.data, s.sample_rate, 60.0, Q)
out = dspk.ops.filter.notch(out, s.sample_rate, 180.0, Q)
# How much of the hum is left: residual against the recording without hum
truth = s.without("hum")
left = np.std(out - truth) / np.std(s.components["hum"])
print(f"hum left after two notches: {100 * left:.1f} % of its RMS")

Two notches take the hum out, nothing else

Two notches take the hum out, nothing else.

The whole script is playground/02_filtering/03_notch.py. Run it with uv run python playground/02_filtering/03_notch.py.