我有大约1000个不同的时间序列,对于每一个,我想自动确定时间序列中是否有任何季节性
假设存在季节性,很容易通过FFT或PSD确定周期性
但是,如何根据FFT或PSD自动确定信号中是否存在季节性或周期性
def psd_time_series(y):
yAC = np.correlate(Y-np.mean(Y), Y-np.mean(Y), mode='full')
yAC = yAC/np.max(yAC) # not necessary, but scales large values
fft_yAC= np.fft.fft(yAC)
freqs = np.arange(0,len(fft_yAC))/len(fft_yAC)
psd = 10*np.log10(np.abs(fft_yAC)/max(np.abs(fft_yAC))
return psd,freqs
def determine_if_seasonal(psd):
### part I need help with
def detect_seasonality(y):
psd,freqs = psd_time_series(y)
seasonality = ... #### do some check of PSD to determine if seasonal
if seasonality:
periodicity = round(1/freqs[psd.argsort()[::-1]][0])
else:
periodicity = None
return periodicity
根据时间序列的FFT或PSD自动确定单个尖峰或高斯噪声不具有季节性的方法是什么?PSD大小的阈值是否有经验法则?山峰的突出程度?山峰的高度?
例如,单个尖峰的PSD图可能如下所示
单尖峰的FFT
或者高斯噪声的PSD看起来像
高斯噪声的FFT分析
或者,具有周期性的实际信号的PSD可能看起来像
同一信号的FFT
欣赏任何意见或见解
这个答案附带了一个免责声明:我已经15年没有做过这种类型的时间序列分析了,因此我非常生锈。我非常欢迎任何更正,因为我是凭记忆工作的,可能忘记了一些事情。希望它能给你一些想法,如果你的数据允许的话,我认为你会想做这样的事情,你可以改进方法。(如果是,请回复或编辑答案!)
正如我在上面的评论中提到的,如果您可以将数据集分成多个部分,那么您就可以开始获得数据集中不同频率的能量的置信限。当然,这意味着您需要很长的数据集,这些数据集可能可用,也可能不可用,这取决于您所做的工作。但就像任何统计技术一样,如果你没有很多数据,你很难对你的发现有信心。我将继续描述我将如何确定有一个信号,你可以反转它,找到哪里有而不是一个信号
我要做的第一件事是将数据集分解为多个部分。你能把它分成多少部分取决于你的数据集相对于你试图找到的信号的周期性(或者在你的例子中没有找到)有多长。要获得更多的分段,可以做的一件事是重叠它们,但为了节省能量,需要使用适当的窗口进行过滤。在下面的代码中,我假设有50%的重叠,并应用Hanning window。我真的忘记了不同窗口和重叠的细节,所以我很抱歉,我不能提供更多关于为什么我选择这个窗口重叠的信息
希望您能从数据集中得出您的背景状态的分布或期望值。也许它只是一个白噪声地板,或者更复杂的红移或蓝移。功率谱的背景电平应提供噪声电平的信息,因为功率谱能量与噪声有关,如
首先,让我们来看看叠加在一起的噪声和噪声的功率谱。2 * noise**2 / (fs * L)
,其中fs
是采样频率,L
是窗口长度。如果我没记错的话,就像我说的,我很生疏很明显,信号穿过了噪音,但我认为我们可以想出比“用眼睛盯着它”更好的办法。在下面的代码中,我只看我的“数据集”的每个频率上高于噪声分布和相应比例的点数。从噪波中提取值有50%的几率使值大于噪波,因此 你希望你的信号大大高于50%。(另一方面,如果该值小于50%,则表明信号在噪声地板下方,这将很有趣。)有more advanced approaches,我没有在这里讨论,但我认为会给出相同的结果
我认为有人可以用这些方法来说明在不同频率下哪里有振荡,哪里没有振荡,这应该可以解决你们关于数据集季节性的问题
可以使用自相关函数或部分自相关函数。你将得到每一个滞后(周期)大小的系数,它将测量信号与延迟版本的相似性。确保使用的滞后时间大于某些周期(>;5),并且如果所有系数都小于阈值(比如说,0.5,但我找不到任何理论方法来支持此决定),则信号没有季节性
这是一个信号处理问题,但您可能希望计算功率谱密度,这可以使用scipy.signal轻松完成,然后为总功率设置合理的阈值以分配周期
类似的问题(不是我的问题)有一个更长的答案here
相关问题 更多 >
编程相关推荐