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
%% 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')