我正在使用MATLAB的fit函数:
fourier_series =(x,y,'fourier8');
使8阶傅立叶级数适合一组离散数据(x,y)。我需要傅立叶级数的周期为2 * pi。但是,我不知道如何解决此问题,因此,当我调用该函数时,它适合该系列的所需时间。任何建议将不胜感激。谢谢。
问题的背景:我正在分析骑车人的脚蹬的视频捕获数据,这些数据会随着时间的推移以3D空间中的关节位置的云形式输出。关节位置在每个踏板行程中都会略有变化。因此,我希望将傅立叶级数适合这些关节位置和关节角度,并将其作为曲柄角度的函数,以找到骑车人的“平均”位置。因此,必须将傅里叶级数的周期限制为2 * pi,因为当曲柄角度为零(即上止点,TDC)且曲柄角度为零时,“平均”位置必须返回到同一位置。 2 * pi(即曲柄臂旋转一圈后的TDC)。
当前,MATLAB将周期选择为略大于2 * pi,这意味着当我使用傅里叶级数来计算骑车人的位置时,在连续的踏板行程中,对于相同的曲柄角度,骑车人的位置会发生变化。
fit
在一定时期内强制执行该函数的最佳方法是通过诉诸自定义方程模型fittype
。另一个选择(会发出警告)是将参数的上下限固定w
为相同的值,然后选择作为解决方法LinearLeastSquares
。
通过观察可以得到更清洁的解决方案,因为您已经知道周期,所以拟合问题在参数中是线性的,因此可以采用线性最小二乘法。我将在下面展示这种方法的示例。
%// Build a simple time series with period 2*pi.
t = (0:0.01:4*2*pi)';
y = sawtooth(t);
T = 2*pi;
%// Compute the angular speed and the azimuth.
Omega = 2*pi/T;
alpha = Omega*t;
%// Build the regressor matrix, with n harmonics.
n = 8;
A = ones(length(t), 2*n+1);
for i = 1:n
A(:,[2*i 2*i+1]) = [cos(i*alpha) sin(i*alpha)];
end
%// Solve the linear system.
%// The parameters are sorted as:
%// p = [y0 a1 b1 a2 b2 ...]'
%// being y0 the average of y, a_i the terms multiplying the sines
%// and b_i the terms multiplying the cosines.
p = A\y;
%// Evaluate the Fourier series.
yApprox = A*p;
%// Compare the solution with the data.
figure();
hold on;
plot(t, y, 'b');
plot(t, yApprox, 'r');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句