Resample a numpy array

前端 未结 5 1256
梦如初夏
梦如初夏 2020-12-14 03:06

It\'s easy to resample an array like

 a = numpy.array([1,2,3,4,5,6,7,8,9,10])

with an integer resampling factor. For instance, wi

5条回答
  •  不思量自难忘°
    2020-12-14 03:38

    Since you mention this being data from an audio .WAV file, you might look at scipy.signal.resample.

    Resample x to num samples using Fourier method along the given axis.

    The resampled signal starts at the same value as x but is sampled with a spacing of len(x) / num * (spacing of x). Because a Fourier method is used, the signal is assumed to be periodic.

    Your linear array a is not a good one to test this on, since it isn't periodic in appearance. But consider sin data:

    x=np.arange(10)
    y=np.sin(x)
    y1, x1 =signal.resample(y,15,x)  # 10 pts resampled at 15
    

    compare these with either

    y1-np.sin(x1) # or
    plot(x, y, x1, y1)
    

提交回复
热议问题