Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

BUG: signal: filtfilt did not handle the axis keyword correctly. #181

Closed
wants to merge 1 commit into from

2 participants

@WarrenWeckesser
Collaborator

Fix for ticket #1620.

@rgommers
Owner

Looks good Warren, pushed as commit 5536a8a.

@rgommers rgommers closed this
@jnothman jnothman referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 scipy/signal/signaltools.py
@@ -1530,12 +1530,12 @@ def filtfilt(b, a, x, axis=-1, padtype='odd', padlen=None):
x0 = axis_slice(ext, stop=1, axis=axis)
# Forward filter.
- (y, zf) = lfilter(b, a, ext, zi=zi * x0)
+ (y, zf) = lfilter(b, a, ext, axis=axis, zi=zi * x0)
# Backward filter.
# Create y0 so zi*y0 broadcasts appropriately.
y0 = axis_slice(y, start=-1, axis=axis)
- (y, zf) = lfilter(b, a, axis_reverse(y, axis=axis), zi=zi * y0)
+ (y, zf) = lfilter(b, a, axis_reverse(y, axis=axis), axis=axis, zi=zi * y0)
# Reverse y.
y = axis_reverse(y, axis=axis)
View
15 scipy/signal/tests/test_signaltools.py
@@ -593,6 +593,21 @@ def test_sine(self):
err = np.abs(y2d - xlow).max()
assert_(err < 1e-4)
+ # Use the previous result to check the use of the axis keyword.
+ # (Regression test for ticket #1620)
+ y2dt = filtfilt(b, a, x2d.T, padlen=n, axis=0)
+ assert_equal(y2d, y2dt.T)
+
+ def test_axis(self):
+ """Test the 'axis' keyword on a 3D array."""
+ x = np.arange(10.0 * 11.0 * 12.0).reshape(10, 11, 12)
+ b, a = butter(3, 0.125)
+ y0 = filtfilt(b, a, x, padlen=0, axis=0)
+ y1 = filtfilt(b, a, np.swapaxes(x, 0, 1), padlen=0, axis=1)
+ assert_array_equal(y0, np.swapaxes(y1, 0, 1))
+ y2 = filtfilt(b, a, np.swapaxes(x, 0, 2), padlen=0, axis=2)
+ assert_array_equal(y0, np.swapaxes(y2, 0, 2))
+
class TestDecimate:
Something went wrong with that request. Please try again.