Repository navigation
Conversation
|
Thanks for the PR. I looked into this in more detail, and I'd like to keep the 10 s default. I simulated your scenario (64 channels, 20 minutes, line drifting from 60.00 to 59.97 Hz, plus a neighboring tone) and measured the error against the known clean signal. In that scenario, 10 s gives the lowest error, and the error roughly doubles each time the window is halved:
Drift barely matters because the frequency is re-estimated in every window. Within a 10 s window, a drift of 0.03 Hz over 20 minutes amounts to only about 0.00025 Hz. Shorter windows, however, have fewer samples per fitted component, so more broadband activity near the line frequencies is removed along with the line. Shorter windows do help when the line frequency or amplitude changes within a few seconds, but that isn't the case in this scenario, and I don't think we have evidence that it's typical for real recordings. |
|
Thanks for taking the time to test this against the known clean signal. Your results make sense, and I agree that they don't support changing the default to 5 s. I wanted to share a small browser-based lab I built while working on this algorithm: [EEG line-noise removal demo](https://mikech76.github.io/mne-python/) One useful feature is that you can change the window length and overlap yourself (for example, compare 5 s and 10 s windows) and rerun the filter on the same recording. The updated signal and spectrum are displayed immediately, making it easy to explore how different settings affect line-noise removal and nearby signal components. I also posted some implementation details and numerical comparisons with mnextend here: [MNE Forum: Line-noise removal in the browser](https://mne.discourse.group/t/line-noise-removal-in-the-browser-a-demo-and-how-close-it-is-to-mnextend/12061) The idea isn't to argue for a 5 s default, but to provide a convenient way to experiment with the window-length trade-off on different recordings. Perhaps it could be useful for exploring this behavior. |
This changes the default
window_lengthofremove_line_noise()from 10 s to 5 s.Why. A shorter window follows line-frequency drift better. On a 64-channel, 20-minute recording with a line that drifts from 60.00 to 59.97 Hz, the residual line power with a neighbouring tone was:
Why 5 s and not 3 s. 3 s is fine on that recording, but it makes two of the existing tracking tests fail:
test_tracking_matches_fit_at_true_frequency_with_nearby_signalsandtest_wandering_frequency_is_trackedboth compare against a fit at the true frequency and need the longer window for that precision. Those tests now passwindow_length=10explicitly, so they keep testing what they were written to test, and 5 s is the shortest default that keeps them passing without changes to their assertions.Why not shorter than 2 s. Below roughly 2 s the filter stops separating the line from real activity next to it. With a 5 µV tone 0.6 Hz away, a 0.5 s window keeps only 14 % of the tone and a 1 s window 46 %, while 2 s keeps 100 %. The new test covers exactly this: it checks that the line is largely removed and that the neighbouring tone keeps its amplitude.
Changes
window_lengthdefault 10 s -> 5 s, and the docstring now says why the default is not shorter.test_default_window_preserves_a_tone_next_to_the_line.window_length=10so their comparison stays meaningful.### 🌀 Changed.ruff check,ruff format --checkandpytest -W error tests/test_line_noise.pyall pass locally (39 tests).