-
Notifications
You must be signed in to change notification settings - Fork 5
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.
using Plots, LaTeXStrings
pyplot()
using ThinFilmsToolsLet's define now the x-axis span:
x = -10:0.01:10
len_x = length(x)seed1 = [[0.0], # offset
[15.0, 0.0, 0.5]] # peakWe 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)We run the optimiser and plot the results:
sol = FitCurveModel(:lorentzian, x, y_data, seed1)
plot(FitSpectrum(), x, y_data, sol.ymodel)
gui()
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()