Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
a-hurst opened this issue May 7, 2021 · 6 comments
Open
Labels
MNE-Python requires interaction with MNE-Python
Milestone

Comments

@a-hurst
Copy link
Collaborator

a-hurst commented May 7, 2021

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!

@a-hurst
Copy link
Collaborator Author

a-hurst commented May 8, 2021

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?

@sappelhoff
Copy link
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)

@sappelhoff sappelhoff added the MNE-Python requires interaction with MNE-Python label May 18, 2021
@sappelhoff sappelhoff added this to the 0.5.0 milestone Jun 3, 2021
@sappelhoff
Copy link
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 ...

@a-hurst
Copy link
Collaborator Author

a-hurst commented Jun 3, 2021

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.

@sappelhoff
Copy link
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.

@a-hurst
Copy link
Collaborator Author

a-hurst commented Jun 30, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MNE-Python requires interaction with MNE-Python
Projects
None yet
Development

No branches or pull requests

2 participants