Home > Back-end >  MATLAB lsqcurvefit gives a line instead of a sinusoid
MATLAB lsqcurvefit gives a line instead of a sinusoid

Time:08-17

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];
           
  • Related