简体   繁体   English

R中的快速傅里叶变换

[英]Fast Fourier Transform in R

I have a dataset with the number of hourly visits an animal made during a period of 12 months. 我有一个数据集,其中包含12个月内动物的每小时访问次数。 I want to use the Fast Fourier Transform to examine cyclical patterns and periodicity. 我想使用快速傅立叶变换来检查周期性模式和周期性。 In the past, I have used Statistica for this this; 在过去,我使用Statistica就是为了这个; however, I would like to use R to get a plot of the spectral density vs. period. 但是,我想用R来得到光谱密度与周期的关系图。 Is there an easy way to do this in R? 在R中有一个简单的方法吗? I would like to identify 12 and 24 hr peak in activity if possible. 如果可能的话,我想确定12和24小时的活动高峰。

You may consider the following functions. 您可以考虑以下功能。

  • periodogram from TSA package immediately plots a periodogram. periodogramTSA包立即绘制周期图。
  • periodogram from GeneCycle returns a list of frequencies and estimated power spectral densities. 来自GeneCycle periodogram返回频率列表和估计的功率谱密度。 It is a wrapper function for stats::spectrum with some special options set. 它是stats::spectrum的包装函数,设置了一些特殊选项。
  • spectrum from stats allows you to choose the method used to estimate the spectral density: either periodogram or using autoregressive process. 来自stats spectrum允许您选择用于估计频谱密度的方法:周期图或使用自回归过程。
  • cpgram from stats plots a cumulative periodogram along with a confidence interval. 来自stats cpgram绘制累积周期图以及置信区间。

See, eg, ?cpgram or ?spectrum for all the details and keep in mind that it is, eg, TSA::periodogram and GeneCycle::periodogram when names of the functions coincide. 有关所有细节,请参见例如?cpgram?spectrum ,并记住,当函数名称重合时,它是例如TSA::periodogram GeneCycle::periodogramGeneCycle::periodogram

There are also plenty of examples and tutorials online on how to use those functions. 关于如何使用这些功能,还有大量关于在线的示例和教程。 See here for the usage of fft and here for an even more extensive tutorial. 这里为使用fft这里的一个更广泛的教程。

Also, as you probably already know, a given time series must be detrended. 此外,正如您可能已经知道的那样,必须取消给定的时间序列。 Hence, use, eg, diff(x) instead of x . 因此,使用例如diff(x)而不是x And finally, the length of your time series must be divisible by 12 as to be able to identify 12 and 24 hours frequencies, it can be achieved by, eg, x[-(1:(length(x) %% 12))] , where x is a detrended time series. 最后,你的时间序列的长度必须可被12整除,以便能够识别12和24小时的频率,它可以通过例如x[-(1:(length(x) %% 12))] ,其中x是趋势时间序列。

Use spectrum to do a spectral density analysis; 使用spectrum进行谱密度分析; also fft for the base fast Fourier transform. 也用于基础快速傅里叶变换的fft

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

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