0

我正在做一个时间序列分析,我试图找到我的时间序列的周期性。我已经完成了以下代码并找到了图表(见附件):

    # Periodicity of the two trajectories
from statsmodels import api as sm
# convert dataframe to array
np_df= np.asarray(df['Combined'], dtype=float)
# remove mean to create signal oscillating around 0
np_df= np_df- np.mean(np_df)
#get the autocorrelation coefficient
acf= sm.tsa.acf(np_df, nlags=len(np_df))

plt.figure(figsize = (10, 8))
lag = np.arange(len(np_df)) / 2. / 24.
plt.plot(lag, acf)
plt.xlim((0, 120))
plt.xlabel('Lags (days)')
plt.ylabel('Autocorrelation')

来自上面代码的照片

plt.figure(figsize = (10, 8))
plt.plot(lag, acf)
plt.xlim((0, 22))
plt.xlabel('Lags (days)')
plt.ylabel('Autocorrelation')

上面代码的图2

使用 fft pack 查找周期性

from scipy import fftpack
ft_df= fftpack.fft(np_df, axis=0)
freq= fftpack.fftfreq(np_df.shape[0], time[1]-time[0])
periods= 1/freq
plt.figure()
plt.plot(periods, abs(ft_df)*1e-3, 'o')
plt.xlim(0,22)
plt.xlabel('Period')
plt.ylabel('Power ($cdot10^3$)')
plt.show()

图 3

我的问题是我认为周期性,我能解释的是1,也许是2.5?我的方法和解释是否正确?

提前致谢!

4

1 回答 1

0

我不是信号分析方面的专业人士,所以对此持保留态度......

您的自相关表明 15 滞后(ish)是您的高度相关。所以这将是你最好的估计。也就是说,信号要么是周期性的,要么不是周期性的。如果它是周期性的,我希望在一些滞后时看到 1.0 的自相关,而不是 0.85 左右。也许有一些噪音或什么的。

我不太确定你在做什么fftfreq,也许其他人可以在那里帮忙。

于 2020-03-13T04:51:03.177 回答