简体   繁体   English

在R中滑动FFT

[英]Sliding FFT in R

Is there a function or package in R for calculating the Sliding FFT of a sample? R中是否有用于计算样本滑动FFT的函数或包? By this I mean that given the output of fft(x[n:m]) , calculate fft(x[1+(n:m)]) efficiently. 我的意思是给定fft(x[n:m])的输出,高效地计算fft(x[1+(n:m)])

Ideally I'd find both an online version (where I don't have access to the full time series at the beginning, or it's too big to fit in memory, and I'm not going to try to save the whole running FFT in memory either) and a batch version (where I give it the whole sample x and tell it the running window width w , resulting in a complex matrix of dimension c(w,length(x)/w) ). 理想情况下,我会找到两个在线版本(一开始我无法访问完整的时间序列,或者太大而无法容纳在内存中,并且我不会尝试将整个运行的FFT保存在内存)和批处理版本(我将整个样本x都给了它,并告诉它运行的窗口宽度w ,导致尺寸为c(w,length(x)/w)的复杂矩阵)。

An example of such an algorithm is presented here (but I've never tried implementing it in any language yet): 这里提供了这种算法的示例(但我从未尝试过以任何语言实现它):

http://cnx.org/content/m12029/latest/ http://cnx.org/content/m12029/latest/

If no such thingy exists already in R, that doesn't look too hard to implement I guess. 如果R中不存在这样的东西,我想这看起来很难实现。

As usually happens when I post something here, I kept working on it and came up with a solution: 通常,当我在此处发布内容时,我会继续努力并提出解决方案:

fft.up <- function(x1, xn, prev) {
  b <- length(prev)
  vec <- exp(2i*pi*seq.int(0,b-1)/b)
  (prev - x1 + xn) * vec
}

# Test it out
x <- runif(6)
all.equal(fft.up(x[1], x[6], fft(x[1:5])), fft(x[2:6]))
# [1] TRUE

Still interested to know if some library offers this, because then it might offer other handy things too. 仍然很想知道某个图书馆是否提供此功能,因为那样的话它可能还会提供其他方便的功能。 =) But for now my problem's solved. =)但现在我的问题解决了。

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

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