简体   繁体   English

如何从时间序列中删除频率成分?

[英]How to remove frequency components from time series?

I have the time series below 我有下面的时间序列

在此输入图像描述

I want to check for cycles in order to remove them (as part of the usual pre-processing of time series), so I apply FFT. 我想检查周期以便删除它们(作为通常的时间序列预处理的一部分),所以我应用FFT。

# Number of samplepoints
N = len(y)
# sample spacing
T = 1.0 # 1 day
x = np.linspace(0.0, N*T, N)
yf = scipy.fftpack.fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
components = 2.0/N * np.abs(yf[:N//2])

fig, ax = plt.subplots(1, 1, figsize=(10, 5))
ax.plot(xf, components)

This results in the following plot. 这导致以下图。

在此输入图像描述

I want to remove the four greatest components. 我想删除四个最伟大的组件。 In order to do this I'm implementing the formula below. 为了做到这一点,我正在实施下面的公式。

在此输入图像描述

max_components = sorted(components, reverse=True)[:4]
idx_max_comp = []

for comp in max_components:
    for i in range(len(components)):
        if components[i] == comp:
            idx_max_comp.append(i)
            break

cycle_signal = np.zeros(len(y))
for idx in idxs:
    a, b = (2.0/N) * np.real(yf[idx]), (2.0/N) * np.imag(yf[idx])
    fi = xf[idx]
    cycle_signal += (a * np.cos(2 * np.pi * fi * x)) + (b * np.sin(2 * np.pi * fi * x))

y = y - cycle_signal

But when I apply FFT again it's easy to see it didn't work. 但是当我再次应用FFT时,很容易看出它不起作用。

在此输入图像描述

Why? 为什么?

I think the problem is the following: 我认为问题如下:

T = 1.0 # 1 day

The sampling frequency is defined as the number of samples per second if you have one sample a day your sampling frequency is f = (1/24*60*60) which is approximately 11.57407 uHz (micro-Hertz) and your Nyquist frequency will be at 5.787035 uHz is approximately 2 days. 采样频率定义为每秒采样频率为f =(1/24 * 60 * 60),大约为11.57407 uHz(微赫兹)且奈奎斯特频率为在5.787035 uHz约为2天。 This means that you can't check for occurrences of cycles more frequently than once every two days. 这意味着您不能每两天检查一次周期的发生频率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM