MATLAB Answers

nonlinear fit with function a*exp((q1+​i*q2)*x)/s​qrt(x)

4 views (last 30 days)
I am trying to do a nonlinear fit of the attached data, which is the blue decaying sine or cosine wave in the attached image.
I want to fit the data into the function of a*exp((q1+i*q2)*x)/sqrt(x), where a, q1 and q2 are real numbers.
I have tried to use lsqnonlin, but could not limit those three fitting variables to be real. And the fitted results do not make sense.
Any help will be much appreciated.
  5 Comments

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 7 May 2021
This seems like you need to take a standard step from the physicsist's complex representation (which admittedly we often use a bit carelessly as a very convenient(!) shorthand). My guess is that you need to do something like this:
% your model-function: the real part of a modified damped oscillating
% exponential:
curve_fcn = @(pars,x) real((pars(1)+1i*pars(2))*exp((pars(3)+1i*pars(4))*x)./sqrt(x));
err_fcn = @(pars,x,y,fcn) sum((y-fcn(pars,x)).^2);
par0 = [-0.1378e-8, -0.0541e-8, 4.1643e+03, 2.3100e7]; % this might have to be adjusted to get a good enough start-guess
parBest = fminsearch(@(pars) err_fcn(pars,x,y,curve_fcn),par0);
subplot(2,1,1)
plot(x,y,x,curve_fcn(parBest,x))
subplot(2,1,2)
plot(x,y-curve_fcn(parBest,x))
You might have to iterate the optimization-step with the parameter estimate parBest as the new input for par0 to get a improved fits.
You might consider a properly weighted sum-of-square optimization instead of the straight-forward sum-of-squares, but in order to do that you'll need estimates of the uncertainties (standard-deviation) of each measurement point.
HTH
  3 Comments
Jiong Yang
Jiong Yang on 10 May 2021
It really helps. Thank you very much!
Now I have a almost perfect fit for the first 4 peaks. I am not too worried about the double peak at the end, as the data is the inverse fourier transform of the fourier transform of the original data.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by