使用 Mathematica 对离散数据进行连续傅里叶变换?
我有一些周期性数据,但数据量不是的倍数 期间。我如何傅里叶分析这些数据?示例:
% 让我们创建一些数据进行测试:
data = Table[N[753+919*Sin[x/623-125]], {x,1,25000}]
% 我现在收到此数据,但不知道它来自 上面的公式。我试图仅根据“数据”重建公式。
% 查看傅立叶级数的前几个非常数项:
ListPlot[Table[Abs[Fourier[data]][[x]], {x,2,20}], PlotJoined->True,
PlotRange->All]
显示预期峰值为 6(因为周期数确实是 25000/(623*2*Pi) 或大约 6.38663,尽管我们不知道这一点)。
% 现在,我如何取回 6.38663?一种方法是将数据与 Cos[x] 的任意倍数。
convolve[n_] := Sum[data[[x]]*Cos[n*x], {x,1,25000}]
% 并绘制 n=6 附近的“卷积”:
Plot[convolve[n],{n,5,7}, PlotRange->All]
我们看到大致在预期位置出现峰值。
% 我们尝试 FindMaximum:
FindMaximum[convolve[n],{n,5,7}]
但结果无用且不准确:
FindMaximum::fmmp:
Machine precision is insufficient to achieve the requested accuracy or
precision.
Out[119]= {98.9285, {n -> 5.17881}}
因为该函数非常不稳定。
% 通过细化我们的区间(使用图上的视觉分析),我们 最终找到一个 convolve[] 不会摆动太多的区间:
Plot[convolve[n],{n,6.2831,6.2833}, PlotRange->All]
和 FindMaximum 有效:
FindMaximum[convolve[n],{n,6.2831,6.2833}] // FortranForm
List(1.984759605826571e7,List(Rule(n,6.2831853071787975)))
% 但是,这个过程很丑陋,需要人工干预,并且 计算 convolve[] 确实很慢。有更好的方法吗?
% 看看数据的傅里叶级数,我能以某种方式推测出 “真实”周期数是 6.38663?当然,实际结果 将是 6.283185,因为我的数据更适合(因为我只是 在有限数量的点上采样)。
I have some periodic data, but the amount of data is not a multiple of
the period. How can I Fourier analyze this data? Example:
% Let's create some data for testing:
data = Table[N[753+919*Sin[x/623-125]], {x,1,25000}]
% I now receive this data, but have no idea that it came from the
formula above. I'm trying to reconstruct the formula just from 'data'.
% Looking at the first few non-constant terms of the Fourier series:
ListPlot[Table[Abs[Fourier[data]][[x]], {x,2,20}], PlotJoined->True,
PlotRange->All]
shows an expected spike at 6 (since the number of periods is really
25000/(623*2*Pi) or about 6.38663, though we don't know this).
% Now, how do I get back 6.38663? One way is to "convolve" the data with
arbitrary multiples of Cos[x].
convolve[n_] := Sum[data[[x]]*Cos[n*x], {x,1,25000}]
% And graph the "convolution" near n=6:
Plot[convolve[n],{n,5,7}, PlotRange->All]
we see a spike roughly where expected.
% We try FindMaximum:
FindMaximum[convolve[n],{n,5,7}]
but the result is useless and inaccurate:
FindMaximum::fmmp:
Machine precision is insufficient to achieve the requested accuracy or
precision.
Out[119]= {98.9285, {n -> 5.17881}}
because the function is very wiggly.
% By refining our interval (using visual analysis on the plots), we
finally find an interval where convolve[] doesn't wiggle too much:
Plot[convolve[n],{n,6.2831,6.2833}, PlotRange->All]
and FindMaximum works:
FindMaximum[convolve[n],{n,6.2831,6.2833}] // FortranForm
List(1.984759605826571e7,List(Rule(n,6.2831853071787975)))
% However, this process is ugly, requires human intervention, and
computing convolve[] is REALLY slow. Is there a better way to do this?
% Looking at the Fourier series of the data, can I somehow divine the
"true" number of periods is 6.38663? Of course, the actual result
would be 6.283185, since my data fits that better (because I'm only
sampling at a finite number of points).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于 Mathematica 的傅立叶函数/应用/频率识别帮助:
检查版本 7
返回 6.37072
Based on Mathematica help for the Fourier function / Applications / Frequency Identification:
Checked on version 7
returns 6.37072
使用自相关查找周期长度以获得估计值:
智能搜索远离 d=0 的第一个最大值可能是您可以从可用数据中获得的最佳估计?
Look for the period length using autocorrelation to get an estimate:
A smart search for the first maximum away from d=0 may be the best estimate you can get form the available data?
虽然上面不一定完全回答我的问题,但我发现了
有点了不起。
早些时候,我尝试使用
FindFit[]
和Method ->; NMinimize
(即应该能够提供更好的全局拟合),但这效果不佳,
可能是因为您无法给出 FindFit[] 智能起始值。
我收到的错误让我烦恼,但似乎无关紧要。
Although the above doesn't necessarily fully answer my question, I found it
somewhat remarkable.
Earlier, I'd tried using
FindFit[]
withMethod -> NMinimize
(which issupposed to give a better global fit), but that didn't work well,
possibly because you can't give
FindFit[]
intelligent starting values.The error I get bugs me but appears to be irrelevant.