Template Fitting using lsqcurvefit

2 views (last 30 days)
Noah
Noah on 6 Nov 2013
Commented: Alan Weiss on 12 Nov 2013
So what I am trying to do it fit a tempalte with 3000 data points to an experimental data set. I am using lsqcurvefit to do this. I need to get three parameters back, one adjusts my amplitude, one shifts the matrix right or left, the other adds a baseline to my data. Getting lsqcurvefit to solve for the amplitude and baseline is simple, but having it solve for the shift is not as easy. My function uses circshift to move the tempalte right or left. The problem with lsqcurvefit is that I cannot figure out how to make it adjust the second value it is searching for to an integer. I am trying to pass it this,
stepDiff=[1e-3 1 1e-3];
opts = optimset('Algorithm', 'levenberg-marquardt','FinDiffRelStep',stepDiff);
for my options. I want to be able to have the 1st and 3rd variable be able to be non-integers, but the second one constrained to be an integer value. Any thoughts would be greatly appreciated.
Thank you.

Accepted Answer

Alan Weiss
Alan Weiss on 7 Nov 2013
Unfortunately, Optimization Toolbox solvers (except for bintprog) are for continuous variables, and do not work with integer constraints.
Perhaps you can perform an iterative solution, looping through possible shift values and optimizing the continuous variables with lsqcurvefit.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Noah
Noah on 7 Nov 2013
Thanks. I have come to that conclusion from the massive amounts of reading I have done. I actually tried doing that, but looked for more answers figuring there was a way haha.
So after trying this method it will find solutions, but how do I get it to output the iteration number that solved the lsqcurvefit? If the function iterates through 3000 possible shifts, how can I get it to tell me which one of those iterations was the "best shift" fit?
Alan Weiss
Alan Weiss on 12 Nov 2013
I guess you should look at the resulting residuals, and choose the shift that gives the smallest residual norm (indicating the best fit). Most likely, you should look at more than one fit with small residual norm, because you might see something that looks better in some way with one of the small-norm solutions.
Alan Weiss
MATLAB mathematical toolbox documentation

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!