如何使用 MATLAB 定义将傅里叶级数拟合到离散数据之前的周期?

How can I define the period before fitting a Fourier series to discrete data using MATLAB?

我正在使用 MATLAB 的拟合函数:

fourier_series=(x,y,'fourier8');

将 8 阶傅里叶级数拟合到一组离散数据 (x,y)。我需要傅里叶级数的周期为 2*pi。但是我不知道如何解决这个问题,以便在我调用函数时它适合系列到我需要的时间段。任何建议将不胜感激。谢谢。

问题背景: 我正在分析骑车人踩踏板的视频捕捉数据,这些数据随着时间的推移输出为 3D space 中的关节位置云。关节位置在每个踏板行程中都会略有变化。因此,我希望将傅立叶级数拟合到这些关节位置和关节角度作为曲柄臂角度的函数,以找到骑车人的 "average" 位置。因此,傅里叶级数的周期需要限制为 2*pi,因为 "average" 位置必须 return 到曲柄臂角度为零时的相同位置(即上止点,TDC)并且曲柄臂角度为 2*pi(即曲柄臂旋转一圈后的 TDC)。

目前 MATLAB 正在选择略大于 2*pi 的周期,这意味着当我使用傅里叶级数计算骑车人的位置时,骑车人的位置会随着连续踏板行程的相同曲柄臂角度而变化。

在特定时期强制使用 fit 函数的最佳方法是通过 fittype 求助于自定义方程模型。另一个选项(将引发警告)是将参数 w 的下限和上限固定为相同的值,并将 select 固定为求解方法 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');