0

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

4

1 回答 1

1

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

您必须指定 的频率psd::pspectrum。假设您的数据被加载为data.frame被调用x

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

谱图

pspectrum函数还有一个更详细的图:

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

在此处输入图像描述

选择

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

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

在此处输入图像描述


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

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

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

our_ts <- ts(data = x[, 2], start = 4, frequency = 100)
out2 <- stats::spectrum(our_ts)
out2$freq[which.max(out2$spec)]
# [1] 0.2777778
于 2021-05-30T08:40:01.187 回答