[SciPy-User] Usage of scipy.signal.resample
Wed Aug 26 09:44:16 CDT 2009
Received from Ivo Maljevic on Wed, Aug 26, 2009 at 10:11:29AM EDT:
> 2009/8/26 <email@example.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.
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.
More information about the SciPy-User