I post here the Levenberg-Marquardt algorithm for fitting sinus function in C++.
The sinusiodal function is one of the basic non-linear functions. The sinusoidal function is frequently used in optics in interferometry or electronics. To know the low-level algorithm for fitting sinusoidal function can be very useful in X-ray Talbot interferometry or grating interferometry. Here, I post Levenberg–Marquardt algorithm for fitting simple sinusoidal function. The study material and detail explanation of algorithm is posted by Technical University of Denmark by Madsen, Nielsen and Tingleff on the web-page http://www2.imm.dtu.dk/pubdb/edoc/imm3215.pdf. The presented algorithm fits amplitude, phase and offset of sinusoidal function. The Levenberg-Marquardt algorithm posted here uses Eigen C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. The most important part of the Levenberg-Marquardt algorithm is calculation of Jacobian matrix J(:,:), which conatins derivation of sinusoidal function (x(0)*sin(t+x(1))+x(2)) according to the fitting parameters. Here, x(0) is the amplitude, x(1) is the phase and x(2) is the offset.