【问题标题】:Amplitude for each day of daily time series每日时间序列中每一天的幅度
【发布时间】:2019-01-11 23:44:48
【问题描述】:

我正在尝试确定时间序列中每一天的幅度。频率是恒定的,序列仅在幅度上变化。我曾尝试使用快速傅里叶变换和 Lombscargle 周期图,但它们返回每个频率的幅度,并且幅度似乎是整个时间序列的平均值。如果我拆分时间序列并为每一天计算一个 fft,我会遇到使波从零开始的问题,并且它返回不正确的值。有谁知道我如何可靠地计算每天的振幅?

以下是一些示例数据:

import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 240, 240) # time
fs = 1/24 # frequency
## Create a time series
series = np.sin(fs * 2 * np.pi * t) 
series = series * np.sin(fs * 1/10 * 2 * np.pi * t) + 25
## Plot
plt.ylabel("Temperature ($^oC$)")
plt.xlabel("Time (hrs)")
plt.plot(t, series)
plt.show()

【问题讨论】:

  • 不清楚每天的幅度是什么意思。您希望得到的图表每天的幅度值是多少?

标签: time-series signal-processing amplitude


【解决方案1】:

如果您需要该系列每天的时间平均值,则无需在拆分数组后计算各部分的 FFT。只需计算每个部分的时间平均值(使用 numpy mean),如下所示:

# compute number of full days in the time series
days = int(np.floor(len(series)*fs))

# truncate the series, keeping full days
# (may not be necessary if total samples is a multiple of fs)
M = int(np.floor(days/fs))
series = series[0:M]
t      = t[0:M]

# compute the average for each day
avg  = np.mean(np.split(series, days), axis=1)
tmid = np.mean(np.split(t, days), axis=1)

# plot the results
plt.ylabel("Temperature ($^oC$)")
plt.xlabel("Time (hrs)")
plt.ylim(24, 26)
plt.bar(tmid, avg, 0.9/fs, color=(0.8,0.8,0.8))
plt.plot(t, series)
plt.show()

您可以类似地计算每个时间段的其他特征。例如,要获取某一天的温度波动幅度,您可以使用以下命令:

reshaped  = np.split(series, days)
minvalue  = np.amin(reshaped, axis=1)
maxvalue  = np.amax(reshaped, axis=1)
variation = maxvalue - minvalue
amplitude = 0.5*variation

plt.ylabel("Temperature ($^oC$)")
plt.xlabel("Time (hrs)")
plt.ylim(24, 26)
plt.bar(tmid, 2*amplitude, 1/fs, minvalue, color=(0.8,0.8,0.8), edgecolor=(0.7,0.7,0.7))
plt.plot(t, series)
plt.show()

【讨论】:

    猜你喜欢
    • 2021-03-22
    • 2012-12-25
    • 1970-01-01
    • 2015-08-10
    • 2018-06-23
    • 2021-09-24
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多