【问题标题】:How can I define the period before fitting a Fourier series to discrete data using MATLAB?如何在使用 MATLAB 将傅里叶级数拟合到离散数据之前定义周期?
【发布时间】:2015-02-22 11:09:49
【问题描述】:

我正在使用 MATLAB 的 fit 函数:

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

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

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

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

【问题讨论】:

    标签: matlab function fft series


    【解决方案1】:

    在特定时期强制使用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');
    

    【讨论】:

      猜你喜欢
      • 2016-01-26
      • 1970-01-01
      • 2019-03-02
      • 2018-09-30
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多