Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/14627.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`mne.filter.create_filter` and :meth:`mne.io.Raw.filter` raising a ``ValueError`` for high-pass and band-stop filters with ``phase="minimum"`` and ``fir_design="firwin2"`` when the filter length is even, by :newcontrib:`Sohail Shaikh`.
1 change: 1 addition & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
.. _Simon M. Hofmann: https://github.com/SHEscher
.. _Simon-Shlomo Poil: https://github.com/simon-shlomo
.. _Sina Esmaeili: https://github.com/snesmaeili
.. _Sohail Shaikh: https://github.com/sohailshk
.. _Soham Mitra: https://github.com/SohamXYZDev
.. _Sondre Foslien: https://github.com/sondrfos
.. _Sophie Herbst: https://github.com/SophieHerbst
Expand Down
2 changes: 1 addition & 1 deletion mne/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _check_zero_phase_length(N, phase, gain_nyq=0):
if N % 2 == 0:
if phase == "zero":
raise RuntimeError(f'filter_length must be odd if phase="zero", got {N}')
elif phase == "zero-double" and gain_nyq == 1:
elif phase in ("zero-double", "minimum") and gain_nyq == 1:
N += 1
return N

Expand Down
18 changes: 18 additions & 0 deletions mne/tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,24 @@ def test_filter_minimum_phase_bug():
assert not (dB_min_half < -30).all()


@pytest.mark.parametrize("filter_length", (3000, "3s"))
def test_filter_minimum_phase_firwin2_highpass(filter_length):
"""Test minimum-phase firwin2 high-pass with an even filter length."""
h = create_filter(
None,
1000.0,
10.0,
None,
filter_length=filter_length,
phase="minimum",
fir_design="firwin2",
)
assert h.size % 2 == 1
w, H = freqz(h, worN=2000, fs=1000.0)
assert_allclose(np.abs(H[-1]), 1.0, atol=1e-2)
assert np.abs(H[0]) < 1e-2


@pytest.mark.parametrize("dc", (0, 100))
@pytest.mark.parametrize("sfreq", (1000.0, 999.0))
def test_smart_pad(dc, sfreq):
Expand Down