Least Square Minimization (Levenberg-Marquant method) of damped oscillation curves

Hi,
My goal is to fit my experimental data (attached) with the following equation with Levenberg Marquant method :
A*exp(-c*t)*sin(2*pi*f*t+phi), where A is the amplitude, t is time, c is the damping coefficient and f the frequency and phi the phase coefficient.
As my skills are weak in least square minimzation in Matlab, thanks in advance for your help,
Louise.

 Accepted Answer

You can use lsqcurvefit with the 'levenberg-marquardt' Algorithm setting

4 Comments

t = [1:1:51];
fun = @(x,t) x(1)*exp(-x(2)*t)*sin(2*pi*x(3)*t+x(4));
[Amax,Lmax] = max(S);
x0 = [Amax,Lmax];
x = lsqcurvefit(fun,x0,t,S)
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
lb = [];
ub = [];
x = lsqcurvefit(fun,x0,t,S,lb,ub,options)
plot(t,S,'ko',t,fun(x,t),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
Thanks for your advice. Here is my Matlab code, with S, the signal generated by my experimental data.
However, my code works when my function is x(1)x(1)*exp(-x(2)*t) but doesn't work when I add the sin composent.
The error message is :
Error in @(x,t)x(1)*exp(-x(2)*t)*sin(2*pi*x(3)*t+x(4))
Error in lsqcurvefit (line 199)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.
This works a bit better. I don't know if I trust the model enough to expect a better fit.
fun = @(x,t) x(1)*exp(-x(2)*t).*sin(2*pi*x(3)*t+x(4))+x(5);
x0 = [max(S),1,0.1,1,mean(S)];
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
lb = [0,0,0,-1,-inf];
ub = [inf,inf,inf,1,+inf];
x = lsqcurvefit(fun,x0,t,S,lb,ub,options)
plot(t,S,'ko',t,fun(x,t),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')

Sign in to comment.

More Answers (0)

Categories

Asked:

on 2 Dec 2019

Edited:

on 2 Dec 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!