作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有 24 个 Y 值,相应的 24 个 Y 值是通过实验测量的,
虽然 t 有值:t=[1,2,3.......24]
我想用傅里叶分析找到 Y 和 t 之间的关系作为一个方程,
我尝试过并做过的是:
我编写了以下 MATLAB 代码:
Y=[10.6534
9.6646
8.7137
8.2863
8.2863
8.7137
9.0000
9.5726
11.0000
12.7137
13.4274
13.2863
13.0000
12.7137
12.5726
13.5726
15.7137
17.4274
18.0000
18.0000
17.4274
15.7137
14.0297
12.4345];
ts=1; % step
t=1:ts:24; % the period is 24
f=[-length(t)/2:length(t)/2-1]/(length(t)*ts); % computing frequency interval
M=abs(fftshift(fft(Y)));
figure;plot(f,M,'LineWidth',1.5);grid % plot of harmonic components
figure;
plot(t,Y,'LineWidth',1.5);grid % plot of original data Y
figure;bar(f,M);grid % plot of harmonic components as bar shape
条形图的结果是:
现在,我想找到代表数据的这些谐波分量的方程式。然后我想用拟合函数找到的数据绘制原始数据Y,两条曲线应该很接近。
我应该使用 cos 还是 sin 还是 -sin 还是 -cos?
换句话说,将这些谐波表示为函数的规则是什么:Y = f (t)
?
最佳答案
使用您的数据 和使用离散正弦变换的 Mathematica 完成的示例。希望你可以推断到 Matlab:
n = 24;
xg = N[Range[n]]/n
fg = l (*your list *)
fp = ListPlot[Transpose[{xg, fg}], PlotRange -> All] (*points plot*)
coef = FourierDST[fg, 1]/Sqrt[n/2]; (*Fourier transform*)
Show[fp, Plot[Sum[coef[[r]]*Sin[Pi r x], {r, n - 1}], {x, -1, 1},
PlotRange -> All]]
系数是:
{16.6411, -4.00062, 5.31557, -1.38863, 2.89762, 0.898562,
1.54402, -0.116046, 1.54847, 0.136079, 1.16729, 0.156489,
0.787476, -0.0879736, 0.747845, 0.00903859, 0.515012, 0.021791,
0.35001, 0.0159676, 0.215619, 0.0122281, 0.0943376, -0.00150218}
更详细的 View :
编辑
但是,由于偶函数似乎更好,我还进行了类型 3 的离散傅立叶余弦变换,效果更好:
在这种情况下,系数是:
{14.7384, -8.93197, 4.56404, -2.85262, 2.42847, -0.249488,
0.565181,-0.848594, 0.958699, -0.468337, 0.660136, -0.317903,
0.390689,-0.457621, 0.427875, -0.260669, 0.278931, -0.166846,
0.18547, -0.102438, 0.111731, -0.0425396, 0.0484102, -0.00559378}
系数和函数的绘图是通过以下方式获得的:
coef = FourierDCT[fg, 3]/Sqrt[n];(*Fourier transform*)
f[x_]:= Sum[coef[[r]]*Cos[Pi (r - 1/2) x], {r, n - 1}]
你需要做一些实验......
关于algorithm - 使用傅立叶分析将函数拟合到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5445499/
我是一名优秀的程序员,十分优秀!