Skip to content

Example: Lorentzian model

Leandro Acquaroli edited this page Nov 1, 2019 · 3 revisions

The example here will use a custom-built Lorentzian shape line with one and two modes and fit them using the FitCurveModel tool.

The complete code can be found here.

Load modules

using Plots, LaTeXStrings
pyplot()
using ThinFilmsTools

X-axis length

Let's define now the x-axis span:

x = -10:0.01:10
len_x = length(x)

Lorentzian: 1 peak

seed1 = [[0.0], # offset
         [15.0, 0.0, 0.5]] # peak

Generate data

We generate some data using the Lorentzian model. For this, we use the same function to model, with some parameters:

y_data = Utils.lorentzian(x, seed1) .+ randn(len_x)

Optimise

We run the optimiser and plot the results:

sol = FitCurveModel(:lorentzian, x, y_data, seed1)
plot(FitSpectrum(), x, y_data, sol.ymodel)
gui()

Fit Lorentzian single peak

Lorentzian: 2 peaks

Now let's try the same thing, but with one more peak:

seed2 = [[0.0], # offset
         [15.0, -1.0, 0.5], # first peak
         [30.0, 1.0, 0.5]] # second peak
y_data = Utils.lorentzian(x, seed2) .+ randn(len_x)
sol = FitCurveModel(:lorentzian, x, y_data, seed2)
plot(FitSpectrum(), x, y_data, sol.ymodel)
gui()

Fit Lorentzian double peak

Clone this wiki locally