【问题标题】:matlab how is it possible to curve fitting Fourier series to more than 8 part ?matlab如何将傅里叶级数曲线拟合到8个以上的部分?
【发布时间】:2015-03-24 22:25:23
【问题描述】:

如何将傅里叶级数曲线拟合到超过 8 个级数的部分?

我尝试了这个程序,但我得到的系数值不一样,而且拟合不好

    %% Create a Fourier series

    AnCosWnx='A0';
    BnSinWnx='';
    lower=1;
    upper=1;
    startpoint=0;

  for n=1:9



   LCos=AnCosWnx;
   LSin=BnSinWnx;

   ACosWx=strcat('A',num2str(n),'*cos(w*',num2str(n),'*x)');
   AnCosWnx=strcat(LCos,'+',ACosWx);
   BSinWx=strcat('B',num2str(n),'*sin(w*',num2str(n),'*x)');
   BnSinWnx=strcat(LSin,'+',BSinWx);

   Fx=strcat(AnCosWnx,BnSinWnx);


  end

  %% build the fit  function 

   options = fitoptions(Fx);


   lower=zeros(1,2+n*2);
   upper=zeros(1,2+n*2);
   startpoint=zeros(1,2+n*2);

  lower(1:end)=-inf;
   upper(1:end)=inf;
  startpoint(end)=6.17*10^-3;

set(options,'Lower',lower,...
   'Upper',upper...
   ,'StartPoint',startpoint...
   ,'Algorithm','Trust-Region');

%%

 ft = fittype(Fx);


% Fit this model using new data
[fitobject ,gof,output] = fit(sat,dat,ft,options);

%% 创建适合字符串的函数

    cvalues = coeffvalues(fitobject);
    cnames = coeffnames(fitobject);
    output = formula(fitobject);

  for ii=1:1:numel(cvalues)
      cname = cnames{ii};
      cvalue = num2str(cvalues(ii));
      output = strrep(output, cname , cvalue);
 end

%% 将输出字符串转换为函数 foutput= strcat('@(x)',output);

  Fout=  regexprep(Foutput,'\r\n|\n|\r','')
   g=str2func(Fout);
   hold on 
   h_ = plot(sat,g(sat),'r')

【问题讨论】:

    标签: matlab fft curve-fitting


    【解决方案1】:

    根据我的经验,matlab(或任何)曲线拟合算法通常不会在一定复杂度的函数之上工作得很好。您可以使用分段样条曲线,但似乎 periodogram 可能是最好的解决方案。这是一种将傅里叶级数拟合到非均匀数据的技术。 exchange上有一个matlab函数。

    【讨论】:

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