【问题标题】:sin(x) autocorrelation function pythonsin(x) 自相关函数 python
【发布时间】:2020-09-18 11:48:02
【问题描述】:

我有一个时间序列数据,我想显示自相关函数。 (我们知道正弦函数的自相关是余弦函数)

我采用以下几种方法来做到这一点

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

x = np.arange(0,30,0.1)  #interval=0.1, 300 samples
y = np.sin(x)
y_cor = np.correlate(y,y,'full')  
lags = np.arange(-x[-1],x[-1]+0.1,0.1)

#sin(x)
plt.figure()
plt.plot(x,y)

#autocorrelation(numpy)
plt.figure()
plt.plot(lags,y_cor)
plt.xlabel('Lag')
plt.ylabel('autocorrelation')

#matplotlib
plt.figure()
plt.acorr(y,maxlags=y.size-1)

#statsmodels
plt.figure()
plot_acf(y,lags=y.size-1)

plt.show()

但是,结果是衰减余弦函数,而不是纯 cos(x)。 我已经看到一些答案说这是因为在计算自相关时包在 x 区域之外填充了零,但是如何解决这个问题以获得纯 cos(x)?

【问题讨论】:

    标签: python autocorrelation


    【解决方案1】:

    这是因为您使用的自相关函数是有偏的。。无偏估计应用Bartlett window(三角形窗口)来尝试消除偏差。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多