Skip to content

Commit 9268e85

Browse files
Fix transition bandwidth reported in 'filter too short' error (#11406) (#14005)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ddcefca commit 9268e85

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

doc/changes/dev/14005.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`_.

mne/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _firwin_design(N, freq, gain, window, sfreq):
440440
if this_N > N:
441441
raise ValueError(
442442
f"The requested filter length {N} is too short for the requested "
443-
f"{transition * sfreq / 2.0:0.2f} Hz transition band, which "
443+
f"{transition * sfreq:0.2f} Hz transition band, which "
444444
f"requires {this_N} samples"
445445
)
446446
# Construct a lowpass

mne/tests/test_filter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,11 @@ def test_smart_pad(dc, sfreq):
11341134
x_want = np.r_[np.zeros_like(x), x_want, np.zeros_like(x)]
11351135
x_pad = _smart_pad(x, (len(x) * 2,) * 2, "reflect_limited")
11361136
assert_allclose(x_pad, x_want, atol=0.1, err_msg="reflect_limited with zeros")
1137+
1138+
1139+
def test_filter_too_short_error_reports_correct_transition(raw):
1140+
"""The 'too short' filter error must report the true transition band (gh-11406)."""
1141+
# filter_length far too short for a 1 Hz transition band; the error must
1142+
# report 1.00 Hz (the requested l_trans_bandwidth), not half that.
1143+
with pytest.raises(ValueError, match="1.00 Hz transition band"):
1144+
raw.filter(l_freq=10, h_freq=None, l_trans_bandwidth=1.0, filter_length="11ms")

0 commit comments

Comments
 (0)