Repository navigation
ENH: add line_bandwidth to ZapLine to subtract only the line band - #148
Merged
Merged
Conversation
The removed components are subtracted only within line_bandwidth Hz of the targeted harmonics, leaving the rest of the spectrum unchanged; ZapLine selects the same components as without it. In adaptive mode the band is applied to the removed signal of the whole recording. The FFT band mask moves to _filtering and is shared with interpolate_spectrum.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #148 +/- ##
==========================================
+ Coverage 85.47% 85.53% +0.05%
==========================================
Files 77 77
Lines 10719 10747 +28
Branches 1888 1891 +3
==========================================
+ Hits 9162 9192 +30
+ Misses 931 929 -2
Partials 626 626
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses item 6 of #137.
ZapLine subtracts the whole time course of each removed component. Those components also carry broadband activity, so subtracting them can raise power away from the line on single channels (up to +4.8 dB in the benchmark below). With
line_bandwidth, only the removed components' part withinline_bandwidthHz of the targeted harmonics is subtracted, and the spectrum outside these bands is unchanged.line_bandwidth=None(default) keeps the current behaviour; the output is bit-identical tomain._filtering.line_band_maskand is shared withinterpolate_spectrum(output unchanged).Benchmark
66 real recordings at their native rate, cropped to 180 s (CTF, MEGIN, 4D/BTi, KIT, EEG, mobile EEG, ECoG; 160 Hz to 6 kHz), and 96 synthetic cases with a known clean signal (8–272 channels, 50/60 Hz, one to many line sources, stable and broadened lines), on the Alliance fir cluster, with
line_bandwidth=1.0:Line-only keeps more than 1 dB more line than the default in 1 (standard) and 2 (adaptive) real recordings, all clinical EEG, at most +1.7 dB. Its SNR is higher in 75/96 (standard) and 77/96 (adaptive) synthetic cases; it is lower for some broadened lines (better in 27/48), whose power extends beyond the band.
On 1,237 clinical EEG recordings (19 channels, 200 Hz, standard mode with at most 3 components), recordings with a channel more than 0.5 dB higher in 1–45 Hz drop from 134 to 0, and line removal at 59–61 Hz is a median 0.02 dB weaker.
Related, not changed here: #149 (ZapLine's period smoother is causal). With
line_bandwidth, it does not change power away from the line.Claude Code was used to implement and benchmark these changes.
🤖 Generated with Claude Code