On Thu, Apr 23, 2015 at 5:25 PM, Paul Blelloch <paul.blelloch@ata-e.com> wrote:

I was using the scipy.signal.decimate function and noticed that it seemed to have some unusual edge effects using the default IIR Chebychev filter.  In doing a little research I found a message from 2011 saying that decimate only filtered in one direction, rather than using the filtfilt function to filter both directions in order to get rid of phase shifts.  There was also a message that filtfilt had a bug associated with the way that it handled edge effects.  I was wondering if anything had changed since 2011.  Does decimate still only filter in one direction and are there issues with filtfilt?  Using the default FIR filter (ftype=’fir’) does seem to correct the issue, but that’s a more complex and expensive filter so I was wondering if the default IIR filter was working correctly.

 

I’m comparing the Matlab decimate function that does use filtfilt and seems to handle the edge effects correctly.

 

THANKS, Paul Blelloch




Paul,

The `decimate` function is just a few lines of code.  At the moment, you can find the source code at the end of "signaltools.py": https://github.com/scipy/scipy/blob/master/scipy/signal/signaltools.py#L2501

For the given decimation factor q, `decimate` applies a low-pass filter to remove frequencies higher than 1/q (in normalized frequency units, where 1 is the Nyquist frequency), and then slices the filtered data using a step size of q.

`decimate` does not provide the option to use the forward/backward filter implemented in `filtfilt`.  To decimate using `filtfilt`, you could copy the few relevant lines of code from `decimate`, and replace `lfilter` with `filtfilt`.  Then you would have complete control over the `filtfilt` arguments that control how it handles the edges.  (As a bonus, you would also have complete control over the arguments that control the design of the low-pass filter.)

Warren

 
_______________________________________________
SciPy-User mailing list
SciPy-User@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user