【问题标题】:resampled time using scipy.signal.resample使用 scipy.signal.resample 重新采样时间
【发布时间】:2014-01-20 06:54:23
【问题描述】:

我有一个不是等距采样的信号;需要进一步处理。我以为 scipy.signal.resample 会这样做,但我不明白它的行为。

信号在y中,对应的时间在x中。 重采样预计在 yy 中,所有相应时间在 xx 中。有谁知道我做错了什么或如何实现我需要的?

此代码不起作用:xx 不是时间:

import numpy as np
from scipy import signal
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)
num=50
z=signal.resample(y, num, x, axis=0, window=None)
yy=z[0]
xx=z[1]
plt.plot(x,y)
plt.plot(xx,yy)
plt.show()

【问题讨论】:

    标签: python numpy scipy resampling


    【解决方案1】:

    即使您给出x 坐标(对应于t 参数),resample 仍假定采样是均匀的。

    考虑使用scipy.interpolate 中的单变量插值器之一。

    例如,这个脚本:

    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()
    

    生成此图:

    查看interp1d 的文档字符串以获取控制插值的选项,并查看其他插值类。

    【讨论】:

    • 感谢您的回复。我尝试了一些在 numpy 中实现的插值技术。时间方面有效,但 .resample 构造的信号要好得多(由于源的性质)。我将搜索 scipy 存储库,看看是否可以找到具有类似于 .resample 的特征的重构。
    • @frits 你最后的结论是什么?我也有同样的问题
    猜你喜欢
    • 2018-12-27
    • 2015-11-07
    • 2020-05-18
    • 2019-10-20
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多