互相关在 scipy、python 中给出不正确的结果

发布于 2025-01-14 11:36:40 字数 521 浏览 2 评论 0原文

我有一个带有数字的向量 x ,然后创建一个移位副本并执行互相关,但我发现相关性最高的滞后为 0。我尝试对向量执行相同的操作具有相同大小的正态分布数字,然后它就可以工作。我还注意到,如果我只使用向量的一小部分,它也可以工作......

def align_time_series(a, b):
    mode="full"
    correlation = signal.correlate(a, b, mode=mode)
    lags = correlation_lags(a.size, b.size, mode=mode)
    lags_corr = pd.Series(correlation, lags)
    lags_corr.plot()
    print(lags_corr.idxmax())
    plt.axvline(lags_corr.idxmax())
    plt.show()

y = x[2000:]
align_time_series(x, y)
# => best lag is 0?

I have a vector x with numbers and then I create a shifted copy and perform cross correlation, but yet I get that the lag with highest correlation is 0. I've tried to do the same with a vector with normally distributed numbers of the same size and then it works. I've also noticed that if I just use a smaller part of the vector it also works...

def align_time_series(a, b):
    mode="full"
    correlation = signal.correlate(a, b, mode=mode)
    lags = correlation_lags(a.size, b.size, mode=mode)
    lags_corr = pd.Series(correlation, lags)
    lags_corr.plot()
    print(lags_corr.idxmax())
    plt.axvline(lags_corr.idxmax())
    plt.show()

y = x[2000:]
align_time_series(x, y)
# => best lag is 0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文