resampled time using scipy.signal.resample

后端 未结 1 1525
天涯浪人
天涯浪人 2020-12-18 03:49

I have a signal that is not sampled equidistant; for further processing it needs to be. I thought that scipy.signal.resample would do it, but I do not understand its behavio

相关标签:
1条回答
  • 2020-12-18 04:16

    Even when you give the x coordinates (which corresponds to the t argument), resample assumes that the sampling is uniform.

    Consider using one of the univariate interpolators in scipy.interpolate.

    For example, this script:

    import numpy as np
    from scipy import interpolate
    import matplotlib.pyplot as plt
    
    x = np.array([0,1,2,3,4,5,6,6.5,7,7.5,8,8.5,9])
    y = np.cos(-x**2/4.0)
    
    f = interpolate.interp1d(x, y)
    
    num = 50
    xx = np.linspace(x[0], x[-1], num)
    yy = f(xx)
    
    plt.plot(x,y, 'bo-')
    plt.plot(xx,yy, 'g.-')
    plt.show()
    

    generates this plot:

    plot

    Check the docstring of interp1d for options to control the interpolation, and also check out the other interpolation classes.

    0 讨论(0)
提交回复
热议问题