I'm trying to use lsqcurvefit to fit a sinusoid with some disturbs added:
A=3.75;
omega=2;
phi=2;
t=1:10000;
y=A*sin(omega*t/1000+phi);
noise1=(rand(1,10000)-0.5)*0.2;
noise2=0.1*sin(2*t);
sig_out=A*sin(omega*t/1000+(phi-0.5))+noise1+noise2;
figure;
plot(t,y);
hold on;
plot(t,sig_out);
grid on;
The code above create a random noise, a small oscillation around the value of the theoretical curve, and a phase I've used this code to perform the fitting:
close all;
f=@(x,xdata) x(1)*sin(x(2)*xdata+x(3));
x0=[3.75 2 2];
%definiamo i limiti inferiore e superiore della regressione
lob=ones(1,10000)*x0(1)*1.05*-1;
upb=ones(1,10000)*x0(1)*1.05;
options=optimoptions('lsqcurvefit','Diagnostic','on','MaxIteration',1000000000,'Display','iter-detailed','FunctionTolerance',1e-100,'FiniteDifferenceType','central','StepTolerance',1e-100,'FiniteDifferenceStepSize',100);
[reg,EXITFLAG]=lsqcurvefit(f,x0,t,sig_out,lob,upb,options);
but the output gives me only a straight line centered around 0 with small oscillations.. I've tried different options. What am I missing? Many thanks
