MATLAB使用拟合函数从2> n> 8项进行傅立叶曲线拟合,其中它优化了n个系数:
f = fit(xs,ys,'fourier8');
coeffs = coeffvalues(ft1);
(曲线拟合工具也只有n = 8)为了我的曲线拟合和数据分析的目的,我需要开发一个程序来提取傅里叶系数并对用户输入的数量进行最佳拟合。基于公式的更优拟拟的n项:
其中n是谐波数,w是基频,a0,an和bn是傅里叶系数。我写了一些“头脑风暴”功能,但我不确定如何在MATLAB中将它们作为函数实际编写。如果它有任何帮助,我将提供我想要的数据点,以及我的头脑风暴功能:
% knowns:
freq = 50; %Hz
T = 0.02; %s
w = (2*pi)/T;
a0 = 5.9449 % Taken from 8-harmonic Fourier fit of data (estimate)
for n=1:N
sumf = a0 + a(N)*cos(N*x*w) + b(N)*sin(N*x*w);
end
xs =
-1.0410 -1.0264 -1.0114 -0.9700 -0.9399 -0.8571 -0.8571 -0.7848 -0.7923 -0.7420 -0.7347 -0.6941 -0.7017 -0.6570 -0.6645 -0.6339 -0.6339 -0.5533 -0.5533 -0.5142 -0.5142 -0.4708 -0.4708 -0.4396 -0.4320 -0.3438 -0.3436 -0.2813 -0.2813 -0.2222 -0.2148 -0.1678 -0.1678 -0.1325 -0.1325 -0.0870 -0.0870 -0.0496 -0.0421 0.0041 0.0041 0.0628 0.0779 0.1093 0.1093 0.1464 0.1464 0.1850 0.2000 0.2294 0.2519 0.2672 0.2672 0.3047 0.3047 0.3489 0.3489 0.3811 0.3811 0.4240 0.4240 0.4557 0.4632 0.5073 0.5073 0.5302 0.5302 0.5599 0.5599 0.6206 0.6206 0.6876 0.6876 0.7187 0.7338 0.7701 0.7850 0.7924 0.7924 0.8912 0.8912 0.9363 0.9437 0.9584 0.9659 1.0198 1.0198 1.0561 1.0561 1.1027 1.1102 1.1466 1.1466 1.1765 1.2368 1.2368 1.2818 1.3192 1.4021 1.4097 1.4248 1.4696 1.4696 1.4771 1.5152 1.5152 1.5602 1.5980 1.5980 1.6431 1.6883 1.8082 1.8383 1.8458 1.8834 1.9136 1.9136 1.9737 1.9737 1.9888
ys =
29.3103 -8.6207 -6.8966 294.8276 294.8276 -298.2759 -294.8276 74.1379 75.8621 -113.7931 -129.3103 106.8966 101.7241 72.4138 72.4138 113.7931 113.7931 -53.4483 -53.4483 65.5172 65.5172 -67.2414 -67.2414 22.4138 24.1379 -134.4828 -122.4138 51.7241 51.7241 -32.7586 -41.3793 112.0690 112.0690 -75.8621 -75.8621 -39.6552 -41.3793 -58.6207 -58.6207 24.1379 27.5862 -87.9310 -84.4828 18.9655 18.9655 -17.2414 -17.2414 65.5172 60.3448 3.4483 3.4483 24.1379 18.9655 12.0690 12.0690 -58.6207 -58.6207 115.5172 115.5172 -65.5172 -65.5172 67.2414 65.5172 -18.9655 -18.9655 6.8966 6.8966 -18.9655 -18.9655 20.6897 20.6897 -27.5862 -27.5862 55.1724 55.1724 -48.2759 -53.4483 -68.9655 -68.9655 18.9655 18.9655 15.5172 8.6207 -18.9655 -20.6897 79.3103 79.3103 -20.6897 -20.6897 93.1034 93.1034 -0.0000 -0.0000 -17.2414 -5.1724 -5.1724 -8.6207 -31.0345 -10.3448 -8.6207 -3.4483 -25.8621 -24.1379 -25.8621 15.5172 15.5172 -0.0000 20.6897 20.6897 17.2414 25.8621 -6.8966 -1.7241 -1.7241 -5.1724 5.1724 5.1724 -0.0000 -0.0000 3.4483
提前感谢您提供的任何帮助,真诚地,研究实习生会尴尬地向同事寻求帮助。