【问题标题】:Writing function for n-numbered term Fourier series in MATLAB?在 MATLAB 中为 n 项傅里叶级数编写函数?
【发布时间】:2018-06-09 06:10:33
【问题描述】:

使用 fit 函数,在 MATLAB 中使用傅里叶拟合可以生成的最大项数为 8:

f = fit(xs,ys,'fourier8')

不幸的是,一个 8 学期的系列并不能满足我的要求。目标是用傅里叶模型拟合数据集并提取系数,并且系数需要尽可能精确以供以后分析。我想知道是否有人知道如何使用以下方法修改预先存在的拟合函数:

fitoptions('fourier8')

这将创建一个 n 项傅立叶级数,其中 n 是项数(有限)。如果这是不可行的,如何编写一个程序,使用下图中的通用公式创建具有可提取系数的 n 项傅立叶级数(有限)注意:绑定不会是 INF,而是会BE n.

更新:我找到了包含已知系数的代码,但是如何调整它以便在 n 编号项的系数事先不知道时主动调整/微调系数?另外,如何找到周期的上限和下限(因为这些是此脚本的输入)?

 a0 = input('a0: ');
 an = input('an: ');
 bn = input('bn: ');
 a = input('lower boundary: ');
 b = input('upper boundary: ');
 t = linspace(a,b,10000); % note: this is just for testing the code
 suma =0;

 for n=1:100 
     ebn = evalin('caller',bn);
     ean = evalin('caller',an);
     suma = suma + (ean.*cos(2.*n.*pi.*t./(b-a)) + ebn.*sin(2.*n.*pi.*t./(b-a)));
 end

 series = a0 + suma;
 plot(t,series)

【问题讨论】:

  • 为什么不使用傅里叶级数中的formula 计算系数?将序列截断为有限和gives LS 意义上的最佳近似
  • @Luis Mendo 抱歉,我的问题不够简洁,而且我包含的公式具有误导性,为了计算必要的系数,该级数应该是有限的。

标签: matlab fft curve-fitting


【解决方案1】:

我很确定您所做的事情与我在研究中所做的事情相似。以下代码为 n 个点和 2 x hmodes+1 生成傅立叶矩阵。马上。你可以调整它。所以求解 Ax=b 给出了这个系数。如果没有,它有点方便。我会注意到这很慢。有更快的 FFT 方法。我认为,如果您在我的问题的答案中查找某个地方,则有一个 python 问题列出了one. 这实际上是相同的研究。我在别的地方修好了。

function FCMat = FCMatGen(pts,hmodes)
% Takes the following inputs
% pts: the number of pts
% hmodes: the numbers of modes
% Returns the followinmn
% The matrix A: npts x hmodes for the Fourier Continuation
% problem
A = dftmtx(2*pts);
A = A(1:pts,:);
Ar = real(A(:,(1:(hmodes+1))));
Ai = imag(A(:,(2:(hmodes+1))));
A = [Ar,Ai];
FCMat = A;
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 2014-11-16
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多