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/14005.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the error message raised when a requested FIR ``filter_length`` is too short, which reported half the actual transition bandwidth, by `Cedric Conday`_.
2 changes: 1 addition & 1 deletion mne/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _firwin_design(N, freq, gain, window, sfreq):
if this_N > N:
raise ValueError(
f"The requested filter length {N} is too short for the requested "
f"{transition * sfreq / 2.0:0.2f} Hz transition band, which "
f"{transition * sfreq:0.2f} Hz transition band, which "
f"requires {this_N} samples"
)
# Construct a lowpass
Expand Down
14 changes: 14 additions & 0 deletions mne/tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from scipy.signal import butter, freqz, sosfreqz
from scipy.signal import resample as sp_resample

import mne
from mne import Epochs, create_info
from mne._fiff.pick import _DATA_CH_TYPES_SPLIT
from mne.filter import (
Expand Down Expand Up @@ -1134,3 +1135,16 @@ def test_smart_pad(dc, sfreq):
x_want = np.r_[np.zeros_like(x), x_want, np.zeros_like(x)]
x_pad = _smart_pad(x, (len(x) * 2,) * 2, "reflect_limited")
assert_allclose(x_pad, x_want, atol=0.1, err_msg="reflect_limited with zeros")


def test_filter_too_short_error_reports_correct_transition():
"""The 'too short' filter error must report the true transition band (gh-11406)."""
sfreq = 1000.0
raw = mne.io.RawArray(
np.random.default_rng(0).standard_normal((1, 4000)),
mne.create_info(1, sfreq, "eeg"),
)
# filter_length far too short for a 1 Hz transition band; the error must
# report 1.00 Hz (the requested l_trans_bandwidth), not half that.
with pytest.raises(ValueError, match="1.00 Hz transition band"):
raw.filter(l_freq=10, h_freq=None, l_trans_bandwidth=1.0, filter_length="11ms")
Loading