Skip to content

BUG: Cleanup cHPI filtering using smooth interpolation - #14112

Merged
drammock merged 3 commits into
mne-tools:mainfrom
larsoner:chpi
Jul 29, 2026
Merged

BUG: Cleanup cHPI filtering using smooth interpolation#14112
drammock merged 3 commits into
mne-tools:mainfrom
larsoner:chpi

Conversation

@larsoner

Copy link
Copy Markdown
Member

mne.chpi.filter_chpi is designed to match Maxfilter, but it has always had a property that bothered me -- it subtracts windows in fixed chunks, which can lead to slight discontinuities in the data. The effect is minor, but it can be removed by smoothly interpolating between windows. We have the machinery for this in _Interp2, so this PR utilizes it. I consider this a bugfix so no need for deprecation cycle (but it's debatable and I could live with doing one). This is the cHPI-subtraction equivalent of what we now do for head positions themselves in movecomp. Changes drafted with Claude Opus 4.8 but I refined and understand all code.

Comment thread mne/chpi.py
fitting windows before subtraction. ``"hann"`` (default) smoothly interpolates,
avoiding small step discontinuities (and associated broadband spectral
leakage) produced by ``None``, which holds each window's amplitudes constant
over its central ``t_step``. ``"linear"`` interpolation is also supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring doesn't mention cos2 interpolation, but it looks like the code supports that. Was that omission intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's just an alias

@drammock
drammock merged commit a7f712f into mne-tools:main Jul 29, 2026
29 checks passed
@drammock
drammock deleted the chpi branch July 29, 2026 15:58
larsoner added a commit to larsoner/mne-python that referenced this pull request Aug 4, 2026
* upstream/main: (35 commits)
  Fix bug with coreg scaling (mne-tools#14132)
  MAINT: Update code credit (mne-tools#14131)
  Fix bugs with dark mode panels (mne-tools#14109)
  Improve code credit workflow (mne-tools#14120)
  Align _AbstractRenderer.tube with the PyVista implementation (mne-tools#14125)
  Assign instead of compare when marking explicit zeros in spatio_temporal_dist_adjacency (mne-tools#14124)
  MAINT: Update pre-commit hook versions (mne-tools#14122)
  MAINT: Update dependency specifiers (mne-tools#14121)
  fix: correct typo in comment (mne-tools#14117)
  [dependabot]: Bump the actions group with 2 updates (mne-tools#14123)
  Fix` read_raw_eyelink()` failure when recording blocks are empty or starting with empty values (mne-tools#13571)
  ENH: Add `event_key` parameter to `read_raw_egi` for MFF event metadata (mne-tools#14086)
  fix for scipy sparse deprecations (mne-tools#14118)
  Fix notch spectrum fit (mne-tools#14116)
  Speed up notch filter spectrum fit (mne-tools#14114)
  fix MNE-RT links and update roadmap (mne-tools#14096)
  Clarify `docdict["filter_length_notch"]` (mne-tools#14113)
  Refactor test_plot_alignment_basic() (mne-tools#13472)
  BUG: Cleanup cHPI filtering using smooth interpolation (mne-tools#14112)
  Use redirector app (mne-tools#14111)
  ...

# Conflicts:
#	mne/tests/test_filter.py
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.

2 participants