Wednesday, April 16, 2014

Levenberg–Marquardt fitting to complex data and/or with complex parameters

Assuming you have a working LM fitter for real numbers, the clues are on these two pages:

The tricks are:
  • You're trying to fit a curve to the points plotted on the Real/Imaginary plane (like in the second graph below).
  • Handle the data and parameters as real & imaginary, not magnitude & phase.  Even if that isn't the most "natural" way to interpret your data for your problem/field.
  • Split each complex parameter into two.  One for the real and one for the imaginary part.  If your parameters are real only, nothing needs to be done here.
  • Similarly, split the complex data into two parts, doubling the number of data points you have.  Doesn't matter if they are interleaved, or separate.
  • The error function is calculated using one of the formulae from the second URL above.
  • Due to the splitting of the complex data, the partial derivatives are done separately for the real and imaginary parts.  If you are working on a real data point, use just the real part of the partial derivative.  For the imaginary part, do the same.

Examples:
  • Two parameters { 3+4i, 5+6i } become four real parameters, { 3, 4, 5, 6 }.
  • Data points { 1+2i, 8+9i } become the new data series { 1, 2, 8, 9 } or { 1, 8, 2, 9 }.
  • Example of raw and fitted data, fitting an equivalent circuit model to captured EIS (Electrochemical Impedance Spectroscopy) data: