[SciPy-User] Usage of scipy.signal.resample

David Cournapeau cournape at gmail.com
Wed Aug 26 14:13:38 EDT 2009


On Wed, Aug 26, 2009 at 12:36 PM, Neal Becker<ndbecker2 at gmail.com> wrote:
> Lev Givon wrote:
>
>> Received from Ivo Maljevic on Wed, Aug 26, 2009 at 10:11:29AM EDT:
>>
>>> 2009/8/26 <markus.proeller at ifm.com>
>>>
>>> >
>>> > Hello,
>>> >
>>> > I have a question concerning the resample function of scipy.
>>> > I have the following code:
>>> >
>>> > from scipy.signal import resample
>>> > >>>x = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> > >>>resample(x,5)
>>> > array([ 2.5       ,  1.26393202,  4.5       ,  5.5       ,
>>> > 8.73606798])
>>> >
>>> > I don't understand the first value of 2.5.
>>> > My scipy version is 0.7.0
>>> >
>>> > Thanks for help,
>>> >
>>> > Markus
>>>
>>> Unless you have a periodic function, I wouldn't rely much on the resample
>>> function. It uses FFT approach, and the basic assumption is that x is
>>> periodic. Without even trying to go into details, my first guess is that
>>> what you see is the consequence
>>> of aliasing.
>>>
>>> A function that uses polyphase filter would do a better job, but it
>>> hasn't been written yet :(
>>> Until that is done, maybe you want to experiment by appending zeros to x,
>>> resampling, and then discarding the last half:
>>>
>>> >>> x=linspace(0,9,10)
>>> >>> xx=r_[x, zeros(10)]
>>> >>> yy=resample(xx,10)
>>> >>> yy
>>> array([ 0.16423509,  1.89281122,  4.1904564 ,  5.66068461,  8.68487231,
>>>         2.33576491, -0.6288792 ,  0.3095436 , -0.16068461,  0.05119566])
>>>
>>>
>>> >>> y=yy[0:5]
>>> >>> y
>>> array([ 0.16423509,  1.89281122,  4.1904564 ,  5.66068461,  8.68487231])
>>>
>>> This is by no means a perfect solution, but I'm just throwing some ideas,
>>> and you can try and see if that is good enough for you.
>>>
>>> Ivo
>>
>> You may also wish to check out the samplerate scikit by David
>> Cournapeau; it provides a Python interface to an eponymous library
>> that provides a more robust sample rate conversion facility than the
>> fft-based function provided by scipy.
>>
>> http://pypi.python.org/pypi/scikits.samplerate
>>
>> L.G.
>
> Thanks for pointing to this.  I am quite interested in this subject.  I
> grabbed the samplerate source - it seems to be a wrapper on libsamplerate.
> I am quite interested in the reference http://www-isl.stanford.edu/~boyd/.
>
> AFAICT, libsamplerate refers to the above article, but IIUC it doesn't
> actually use this technique at all.

Are you refering to the right link ? SRC is based on sinc
interpolation (band-limited interpolation), which is a well known
technique for high quality resampling for audio signals (the same
kinds of techniques are used in synthesizers, for example).

http://ccrma-www.stanford.edu/~jos/resample/

AFAIK, SRC is one of the best resampling implementation for audio
signals, and certainly the best available under an open source license
(GPL).

David



More information about the SciPy-User mailing list