Skip to content

Fix spectrum_fit frequency detection and removal - #14310

Open
larsoner wants to merge 1 commit into
mne-tools:mainfrom
larsoner:spectrum
Open

larsoner wants to merge 1 commit into
mne-tools:mainfrom
larsoner:spectrum

Conversation

@larsoner

Copy link
Copy Markdown
Member

I've rarely had satisfying results with spectrum_fit, and I finally dug into why. When the line freq was exactly on a freq bin (e.g., 1000 Hz data and 60.000 Hz line noise) things were at least okay. but if it was slightly off, like 60.05 line noise, it would fail to detect properly. If it did detect properly, it would fail to remove properly because of bugs in how we removed using adjacent bins. We should have refined the frequency estimate after finding there was a significant peak.

This code adapts some nitime code for deciding which components to choose, and refines the frequencies using a chirp z-transform (rather than zero-padding that nitime uses, which is a less clean / complete way to achieve a similar effect).

Updated tutorial image:

image

On main the 60 Hz harmonics are over-removed:

image

@payamsash I'd suggest running spectrum_fit mode on your data to see if it detects frequencies at 25 Hz etc. It would strongly suggest that these are subharmonics of the 50 Hz line noise (could be due to aliasing or something else).

Code changes drafted using Claude Fable 5.1 and reviewed / iterated on by me.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant