Skip to content

Adaptive line noise removal differs between PyPREP and Matlab PREP #82

Open

Description

@a-hurst

Haven't really dug into it much yet, but I've verified that adaptive line noise removal (a.k.a. CleanLine) differs somehow between PyPREP and Matlab PREP.

This is sort of a weird one, where the MNE notch filter that PyPREP uses seems to be very aggressive and distorts the waveband, whereas the MatPREP version doesn't seem to do much of anything (there's a very subtle difference around the 50Hz and 100Hz bands if you a/b the images). I should probably try different test files though, since average-referencing seems to handle 99% of the line noise distortions in the PSD for this data (is this a feature of CMS/DRL I didn't know about?)

Pre-cleanline data:

cleanline_none

Post-CleanLine data (MatPREP):

cleanline_mat

Post-CleanLine data (PyPREP):

cleanline_mne

Anyway, I think this the final component I hadn't formally tested yet for #58!

Activity

  1. a-hurst commented on May 8, 2021

    @a-hurst
    CollaboratorAuthor

    Oh, another quick note on this before I head to bed: the MatPREP CleanLine method is much slower than the MNE function PyPREP currently uses. Like, for the tiny test file we use in matprep_artifacts (60 seconds, 64 channels at 160 Hz), it takes about 15 seconds to run cleanline. For the same file in PyPREP, it takes about a second. Maybe MatPREP's doing some more demanding math?

  2. sappelhoff commented on May 8, 2021

    @sappelhoff
    Owner

    Yes, the adaptive noise filtering in MNE may be a problem (faulty implementation?), we have noticed that before: see e.g., #18 (comment) and #40 (comment)

  3. added
    MNE-Python
    on May 18, 2021
  4. added this to the 0.5.0 milestone on Jun 3, 2021
  5. sappelhoff commented on Jun 3, 2021

    @sappelhoff
    Owner

    I mark this for the 0.5.0 milestone, as it requires a fix on MNE-Python, and I am not sure how trivial this will be ...

  6. a-hurst commented on Jun 3, 2021

    @a-hurst
    CollaboratorAuthor

    and I am not sure how trivial this will be ...

    Yep, I'm dreading this one whenever I end up getting around to it. A lot more layers and files involved than removeTrend or even NoisyChannels, based on my initial investigation.

  7. sappelhoff commented on Jun 15, 2021

    @sappelhoff
    Owner

    relevant discussion about this: https://mne.discourse.group/t/notch-filter-to-remove-power-line-noise/3193/4?u=sappelhoff

    Also, "zapline" might be a valuable alternative to look into ... not so much for the "MatPREP numerical equivalence" that we'd like, but maybe to go beyond.

  8. a-hurst commented on Jun 30, 2021

    @a-hurst
    CollaboratorAuthor

    Just noting this for future reference, but in working on #73 I noticed that the default cleanline settings differ between MatPREP and PyPREP: for the former, the size of the sliding window it uses is 4 seconds. For PyPREP, it's 10 seconds. Will need to re-test with 4-second windows on the off-chance the numbers actually line up!

  9. modified the milestones: 0.5.0, 0.6.0 on Jul 17, 2025
  10. BabaSanfour commented on Oct 20, 2026

    @BabaSanfour

    Jumping on this, we have recently integrated zapline and zapline+ from mne-denoise into men-bids-pipelines, specially that is faster and more correct than other implementations (see linked issue), it could be an option here if the plan is "to go beyond". Would happily open a PR here.

  11. sappelhoff commented on Oct 20, 2026

    @sappelhoff
    Owner

    Hi there, we had a related discussion in #213 and its crosslinks 🤔not sure what we need or not. Especially as the spectrum_fit method has been recently improved, as it seems from crosslinks above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    MNE-Python

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions