[SciPy-Dev] API suggestions wanted for an enhancement to scipy.signal.filtfilt

Ralf Gommers ralf.gommers at gmail.com
Fri Jan 31 09:42:34 EST 2014


On Sat, Jan 25, 2014 at 9:24 PM, Warren Weckesser <
warren.weckesser at gmail.com> wrote:

> Hey all,
>
> I'm adding an option to `scipy.signal.filtfilt` that uses Gustaffson's
> method [1] to handle the edges of the data.  In this method, initial
> conditions for the forward and backward passes of `lfilter` are chosen such
> that applying the filter first in the forward direction and then backward
> gives the same result as applying the filter backward and then forward.
> There is no padding applied to the edges.
>
> Gustaffson's method has one optional parameter.  It is the estimate of the
> length of the impulse response of the filter (i.e. anything after this
> length is supposed to be negligible and is ignored).  If it is not given,
> no truncation of the impulse response is done.
>
> The current signature of `filtfilt` is
>
>     def filtfilt(b, a, x, axis=-1, padtype='odd', padlen=None)
>
> (See
> http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html
> )
>
> The arguments `padtype` and `padlen` control the type ('odd', 'even',
> 'constant' or None) and length of the padding.
>
> Any suggestions for modifying the signature in a backwards-compatible
> way?  Here are a few options I've considered:
>
> (1)  Specify the use of Gustaffson's method with `padtype='gust'`, and
> specify the estimate of the impulse response length using `padlen`.  (I
> don't like this version--there is no padding performed by Gustaffson's
> method; using `padlen` for the impulse response length is just wrong.)
>
>
> (2)  Specify the use of Gustaffson's method with `padtype='gust'`, and
> specify the estimate of the impulse response with a new argument `irlen`.
> (A bit better than (1); I could live with using `padtype` to specify the
> method, even though it isn't actually padding the data.)  New signature:
>
>     def filtfilt(b, a, x, axis=-1, padtype='odd', padlen=None, irlen=None)
>
>
> (3) A new argument `method` specifies the method.  It accepts either
> `'gust'` or `'pad'`.  If the method is `'gust'`, the argument `irlen`
> specifies the impulse response length (and `padtype` and `padlen` are
> ignored).  If the method is `'pad'`, `padtype` specifies the type of
> padding, `padlen` specifies the padding length (and `irlen` is ignored).
> The new signature would be:
>
>     def filtfilt(b, a, x, axis=-1, padtype='odd', padlen=None,
> method='pad', irlen=None)
>
>
> (4) Don't touch `filtfilt`.  Create a new function with the signature:
>
>     def filtfilt_gust(b, a, x, axis=-1, irlen=None)
>
>
> Any suggestions?  Any other APIs that would be preferable?
>

My preference would be (3) or (2), in that order.

Ralf


>
> Warren
>
>
>     [1] F. Gustaffson. Determining the initial states in forward-backward
>     filtering. Transactions on Signal Processing, 46(4):988-992, 1996.
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20140131/bb46b2fd/attachment.html>


More information about the SciPy-Dev mailing list