[Numpy-discussion] help to speed up the python code

David Cournapeau david@ar.media.kyoto-u.ac...
Fri Oct 31 00:33:43 CDT 2008


frank wang wrote:
> Hi, Bob,
>  
> The problem is that I want to resample my data with another sampling
> rate. the two rates is very close. I use the formula:
>  
> s(t)=sum(a_k*sinc(t-kTs)).
>  
> the new sampling rate is Ts', so I have
> s(nTs')=sum(a_k*sinc(nTs'-kTs)). The sum index k is over the (-P, P),
> Centered at n. The n is start from zero. THe code is using two for
> loops and it is slow. The length of s(nTs) is very long, so it takes
> quite long time to do it.

If you want to do high quality resampling, you may want to look at the
samplerate scikits. It uses sinc interpolation for resampling (the
scikits is just a wrapper around SRC: http://www.mega-nerd.com/SRC/, if
you want more details on the implementation)

The documentation is really light unfortunately, but there is an example:

http://www.ar.media.kyoto-u.ac.jp/members/david/softwares/samplerate/index.html

The implementation of SRC is in C, and you can choose between 3 modes
for quality (plus other interpolations like linear, but those are ill
suited for anything serious if you can afford the computational cost),

cheers,

David


More information about the Numpy-discussion mailing list