I am fitting a curve to some instrument data. The data is a pulse with a particular functional form, which starts from and returns to a constant (with noise) baseline level before and after the pulse.
I find that if I fit the whole dataset, I get one set of fitted parameters for the pulse, but if I crop out the part of the data containing the pulse and fit only that, I get a different set of fitted parameters. In both cases the fit looks good and the parameters are reasonable, but not equivalent at all.
Does this represent a problem in my fit function or methodology in particular? Or is this something which is generally possible and expected?
If the problem isn't with my fit function in particular, then how might I improve my fitting method to make the results correct, and invariant w.r.t. the amount of baseline samples present in the data set?
I am using lsqcurvefit() in Matlab, with an error function that provides an analytical Jacobian, so the optimizer being used under the hood is a Trust-Region method. I'm not completely familiar with this algorithm, but as far as I know it is in the same category as BFGS or other quasi-Newton methods, with some additional magic to improve robustness and efficiency. I get similar results with other solvers (eg. Conjugate Gradient).