我正在尝试在 R 中复制下图:(改编自http://link.springer.com/article/10.1007/PL00011669)
该图的基本概念是显示 DFT 的前几个分量,在时域中绘制,然后在时域中显示仅使用这些分量 (X') 相对于原始数据 (X) 的重构波。我想稍微修改上图,使显示的所有线条都覆盖在一个图上。
我一直在尝试用一些以 60 Hz 采样的真实数据来调整这个数字。例如:
## 3 second sample where: time is in seconds and var is the variable of interest
temp = data.frame(time=seq(from=0,to=3,by=1/60),
var = c(0.054,0.054,0.054,0.072,0.072,0.072,0.072,0.09,0.09,0.108,0.126,0.126,
0.126,0.126,0.126,0.144,0.144,0.144,0.144,0.144,0.162,0.162,0.144,0.126,
0.126,0.108,0.144,0.162,0.18,0.162,0.126,0.126,0.108,0.108,0.126,0.144,
0.162,0.144,0.144,0.144,0.144,0.162,0.162,0.126,0.108,0.09,0.09,0.072,
0.054,0.054,0.054,0.036,0.036,0.018,0.018,0.018,0.018,0,0.018,0,
0,0,-0.018,0,0,0,-0.018,0,-0.018,-0.018,0,-0.018,
-0.018,-0.018,-0.018,-0.036,-0.036,-0.054,-0.054,-0.072,-0.072,-0.072,-0.072,-0.072,
-0.09,-0.09,-0.108,-0.126,-0.126,-0.126,-0.144,-0.144,-0.144,-0.162,-0.162,-0.18,
-0.162,-0.162,-0.162,-0.162,-0.144,-0.144,-0.144,-0.126,-0.126,-0.108,-0.108,-0.09,
-0.072,-0.054,-0.036,-0.018,0,0,0,0,0.018,0.018,0.036,0.054,
0.054,0.054,0.054,0.054,0.054,0.054,0.054,0.054,0.054,0.072,0.054,0.072,
0.072,0.072,0.072,0.072,0.072,0.054,0.054,0.054,0.036,0.036,0.036,0.036,
0.036,0.054,0.054,0.072,0.09,0.072,0.036,0.036,0.018,0.018,0.018,0.018,
0.036,0.036,0.036,0.036,0.018,0,-0.018,-0.018,-0.018,-0.018,-0.018,0,
-0.018,-0.036,-0.036,-0.018,-0.018,-0.018,-0.036,0,0,-0.018,-0.018,-0.018,-0.018))
##plot the original data
ggplot(temp, aes(x=time, y=var))+geom_line()
我相信我可以用它fft()
来最终实现这个目标,但是从输出fft()
到我的目标的飞跃有点不清楚。
我意识到这个问题有点类似于:如何计算来自实值输入的 fft() 输出的幅度和相位角?但我对上述特定数据的实际代码更感兴趣。
请注意,我对时间序列分析相对较新,因此您可以将 fft() 的输出放在上下文中提供的任何清晰度,或者您可以推荐的任何可以有效完成此任务的包,将不胜感激。
谢谢