在MATLAB中编写n编号项傅里叶级数的函数?

问题描述 投票:1回答:1

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

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

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

fitoptions('fourier8')

这将创建一个n项傅立叶级数,其中n是项数(有限)。如果这是不可行的,那么如何使用下图中的一般显示公式编写一个创建具有可提取系数的n项傅里叶级数(有限)的程序。注意:边界不会是有效的并且不会被包含在内。 enter image description here

更新:我找到了采用已知系数的代码,但是如何对其进行调整以便在先前未知的情况下主动调整/微调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)
matlab fft curve-fitting
1个回答
1
投票

我很确定你做的事与我在研究中所做的相似。以下代码为n个点和2个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
© www.soinside.com 2019 - 2024. All rights reserved.