[SciPy-user] What is missing in scipy to be a top notch environment for signal processing (lpc and co) ?

A. M. Archibald peridot.faceted at gmail.com
Sun Nov 19 23:43:25 EST 2006


On 19/11/06, David Cournapeau <david at ar.media.kyoto-u.ac.jp> wrote:

>     I've just finished my second big conversion of matlab -> python code
> (~5000 lines of matlab code), and I think there are some "holes" in
> scipy, which would be really useful to fill in. I believe they are
> general enough so I am not the only one missing them. Here are some
> functions I missed
[...]
>     4: functions capable of running the same algorithm on some strides
> of an array.

Much of this can be done with numpy's indexing, but it sounds like you
want something slightly more particular.

> More detailed:
[...]
>     4 I am not sure about this one. A concrete example: if I want to
> compute the autocorrelation of some frames of a signal, the obvious
> thing is to use a loop. This is expensive. If I had a matrix which each
> column is a frame, and an autocorrelation function capable of running an
> algorithm on each column, this would be much faster. Incidentally,
> Matlab offers a function buffer, which builds a matrix which each column
> is a frame, with options for overlapping and border cases. The doc says
> "Y = BUFFER(X,N) partitions signal vector X into nonoverlapping data
> segments (frames) of length N.  Each data frame occupies one column in
> the output matrix, resulting in a matrix with N rows." I don't know how,
> if at all possible, to generalize that to the numpy array.

A quick-and-dirty function to do this can be written in a few lines:
if you want non-overlapping slices, just pad and then use reshape. If
you want overlapping slices, pad and reshape the nonoverlapping parts
then use one of the stacking functions to stick the overlaps on the
ends.

If you want to avoid unnecessary copies (which is reasonable, and
mostly possible modulo a numpy quirk), and if you want reasonable
handling of corner cases, and of segmentation of arbitrary axes of
arbitrarily-dimensioned arrays, the function starts to expand, but is
still reasonable. I've attached a version.

It does sound like a useful sort of function that we might want to
include in scipy (or numpy, really, it has no dependence on any fancy
libraries).

A. M. Archibald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: segmentaxis.py
Type: text/x-python
Size: 4806 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20061119/292f81e3/attachment.py>


More information about the SciPy-User mailing list