我无法将 R 包 psd 中的 psd 范围扩展到 1.5Hz 的频率

问题描述

我有一个时间序列,我需要使用 R 获取 PSD 值。数据是以非均匀间隔采样的,但我使用 predict 命令进行了样条插值,以在 0.01 秒处对读数进行插值。我可以非常正确地从 spec.pgram 获得幅度值,但它们不是 psd 值。然而,来自 psd 包的 pspectrum 命令的 psd 值仅在 0 到 0.5Hz 之间,而我感兴趣的区域扩展到大约 1.2Hz。时间序列是:here

解决方法

请注意,您的时间点不是等距的。为了回答这个问题,我们假设频率为每秒 12 个样本。

您必须指定 psd::pspectrum 的频率。假设您的数据加载为名为 data.framex

out <- pspectrum(x[,2],x.frqsamp = 12)
plot(out)

pspectrum

pspectrum 函数还有更详细的绘图:

out <- pspectrum(x[,x.frqsamp = 12,plot = TRUE)

enter image description here

替代方案

您也可以使用 stats::spectrum,但它需要您创建一个 ts 对象:

our_ts <- ts(data = x[,start = 0,frequency = 12)
plot(stats::spectrum(our_ts))

enter image description here


编辑:给定新数据集(频率 = 100)

x <- read.csv("test2.csv",header = F)

out <- pspectrum(x[,x.frqsamp = 100)
out$freq[which.max(out$spec)]
# [1] 0.265708

our_ts <- ts(data = x[,start = 4,frequency = 100)
out2 <- stats::spectrum(our_ts)
out2$freq[which.max(out2$spec)]
# [1] 0.2777778