Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how is it possible to curve fitting Fourier series to more than 8 series part ?

i try this programmatic but i get not the same coefficient value and the fitting is not so good


C#
%% 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');


   %% convert the output string to function


     Foutput= strcat('@(x)',output);

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900