Conversation
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.
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
nitimecode 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:
On
mainthe 60 Hz harmonics are over-removed:@payamsash I'd suggest running
spectrum_fitmode 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.