使用傅里叶变换获得频率和相位
Posted
技术标签:
【中文标题】使用傅里叶变换获得频率和相位【英文标题】:Using Fourier Transform to get frequency and phase 【发布时间】:2011-07-11 16:31:12 【问题描述】:假设我有一个周期函数的样本,有什么好的方法可以从中获取频率和相位信息?
特别是,我想得到一个类似的表格
a+b Cos[c x + d]
这是示例的一部分
255,255,255,249,64,0,0,0,0,0,0,0,0,0,0,0,0,233,255,255,255,255,255,255,255,255,255,209,0,0,0,0,0,0,0,0,0,0,0,0,118,255,255,255,255,255,255,255,255,255,255,132,0,0,0,0,0,0,0,0,0,0,0,0,200,255,255,255,255,255,255,255,255,255,239,19,0,0,0,0,0,0,0,0,0,0,0,46,245,255,255,255,255,255,255,255,255,255,186,0
【问题讨论】:
很高兴再次见到您! WRT 你的问题:你为什么要在那里装一个Cos[ ]
?
好吧,只是想弄清楚如何获得信号的相位。它来自书籍扫描中的校准图片
对于频率,您可以进行自相关,然后检测最大值和最小值。如果你在两个边缘修剪你的点,自相关效果会更好。
【参考方案1】:
使用自相关和 FindFit[ ]
(*Your list*)
ListPlot@l
(*trim the list*)
l1 = Drop[l, (First@Position[l, 0])[[1]] - 1];
l2 = Drop[l1, Length@l1 - (Last@Position[l1, 0])[[1]] - 1];
(*autocorrelate*)
ListLinePlot@(ac = ListConvolve[l2, l2, 1, 1])
(*Find Period by taking means of maxs and mins spacings*)
period = Mean@
Join[
Differences@(maxs = Table[If[ac[[i - 1]] < ac[[i]] > ac[[i + 1]], i,
Sequence @@ ], i, 2, Length@ac - 1]),
Differences@(mins = Table[If[ac[[i - 1]] > ac[[i]] < ac[[i + 1]], i,
Sequence @@ ], i, 2, Length@ac - 1])];
(*Show it*)
Show[ListLinePlot[(ac = ListConvolve[l2, l2, 1, 1]),
Epilog ->
Inset[Framed[Style["Mean Period = " <> ToString@N@period, 20],
Background -> LightYellow]]],
Graphics[Join[Arrowheads[-.05, .05], Red,
Sequence @@@ Arrow[#[[1]], Min@ac, #[[2]], Min@ac] & /@
Partition[mins, 2, 1], Blue,
Sequence @@@ Arrow[#[[1]], Max@ac, #[[2]], Max@ac] & /@
Partition[maxs, 2, 1]]]]
(*Now let's fit the Cos[ ] to find the phase*)
model = a + b Cos[x (2 Pi)/period + phase];
ff = FindFit[l, model, a, b, phase, x,
Method -> NMinimize, MaxIterations -> 100];
(*Show results*)
Show[ListPlot[l, PlotRange -> All,
Epilog ->
Inset[Framed[Style["Phase = " <> ToString@N@(phase /. ff), 20],
Background -> LightYellow]]], Plot[model /. ff, x, 1, 100]]
【讨论】:
@Yaro 重要的是你不能一次拟合三角函数,你需要先找到频率。我不记得确切原因,但我以前也遇到过,发现这两个步骤的过程要好得多【参考方案2】:请看FourierDCT
ref page。
您的数据看起来非常像SquareWave
函数。通过人工检查,您的数据似乎适合 SquareWave[0, 255, (x + 5)/23 ]
。
【讨论】:
以上是关于使用傅里叶变换获得频率和相位的主要内容,如果未能解决你的问题,请参考以下文章