diff --git a/doc/changes/dev/14005.bugfix.rst b/doc/changes/dev/14005.bugfix.rst new file mode 100644 index 00000000000..fa862c5f3fb --- /dev/null +++ b/doc/changes/dev/14005.bugfix.rst @@ -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`_. diff --git a/mne/filter.py b/mne/filter.py index f8f4abf6499..2ea091c2c87 100644 --- a/mne/filter.py +++ b/mne/filter.py @@ -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 diff --git a/mne/tests/test_filter.py b/mne/tests/test_filter.py index 02239c8545d..76b3634ba75 100644 --- a/mne/tests/test_filter.py +++ b/mne/tests/test_filter.py @@ -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 ( @@ -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")