sinx自相关函数python

问题描述

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

我采用了以下几种方法

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

enter image description here

enter image description here

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...