File:Desommation gaussienne lorentzienne.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 610 × 460 pixels, file size: 59 KB)

Captions

Captions

Non linear regression to fit the curve with the sum of a lorentzian function and a gaussian function.

Summary[edit]

Description
English: Non linear regression to fit the curve with the sum of a lorentzian function and a gaussian function.
Français : Régression non linéaire pour ajuster la courbe avec la somme d'une fonction lorentzienne et d'une fonction gaussienne.
Date
Source Own work
Author Cdang

Scilab source

English: English version by default.
Français : Version française, si les préférences de votre compte sont réglées (voir Special:Preferences).


File gaussian_lorentzian_functions.sci: the function we are working with (library).

// *************
// * Fonctions *
// *************

// Gaussian function centered on 0

function [y] = gauss(A, x)
    // A(1) : peak height
    // A(2) : peak "width"
    y = A(1)*exp(-x.*x/A(2));
endfunction

// Lorentzian function centered on 0

function [y] = lorentz(A, x)
    // A(1) : peak height
    // A(2) : peak "width"
    foo = A(2)*A(2);
    y = foo*A(1)./(foo + 4*x.*x);
endfunction

function [y] = profile(A, x)
    // A(1) : lorentzian peak height
    // A(2) : lorentzian peak "width"
    // A(3) : gaussian peak height
    // A(4) : gaussian peak "width"
    L = A(1:2);
    G = A(3:4);
    y = lorentz(L, x) + gauss(G, x);
endfunction

File gaussian_lorentzian_peak_generator.sce: creates a data set and saves it in the noisy_gaussian_lorentzian_peak.txt file.

chdir("mypath\");

exec("gaussian_lorentzian_functions.sci")

// *************
// * Constants *
// *************

paramlorentz(1) = 5; // height of the lorentzian curve
paramlorentz(2) = 2; // "width" of the lorentzian curve
paramgauss(1) = 10; // height of the gaussian curve
paramgauss(2) = 3; // "width" of the gaussian curve
var=0.5; // variance of the noise normal law

nbpts = 100 // number of points
halfwidth = max(3*paramgauss(2), 3*paramlorentz(2)) // for x range
step = 2*halfwidth/nbpts;

// ******************
// * Initialisation *
// ******************

X = zeros(nbpts,1);
Y = zeros(nbpts,1);

// ****************
// * Main program *
// ****************

// Data generation

i=(1:nbpts)'
X = step*i - halfwidth;
Y = profile([paramlorentz;paramgauss], X) + var*rand(X, "normal");
end

// Saving

csvWrite([X, Y], "noisy_gaussian_lorentzian_peak.txt")

File gauss_lorentz_desummation.sce: process the data to extract the lorentzian and the gaussian components.

// ******************
// * Initialisation *
// ******************

clf;
chdir("mypath\");
exec("gaussian_lorentzian_functions.sci")

// *************
// * Constants *
// *************

Ainit = [1;1;1;1]; // initial parameters of the model function

// *************
// * Functions *
// *************

// Residual function

function [e] = res(A, x, y)
    e = profil(A, x) - y;
endfunction

// ****************
// * Main program *
// ****************

// Data reading

data = csvRead("noisy_gaussian_lorentzian_peak.txt")
X = data(:,1);
Y = data(:,2);

// Data processing

[S, Aopt] = leastsq(list(res, X, Y), Ainit)
Yopt = profil(Aopt, X);
YLopt = lorentz(Aopt(1:2),X);
YGopt = gauss(Aopt(3:4),X);

// Display

plot(X, Yopt, "-r")
plot(X, YLopt, "-c")
plot(X, YGopt, "-g")
plot(X, Y, "+b")

height = max(Y);
xmin = min(X)

xstring(xmin, height*0.95,...
 "lorentzian: Al = "+string(0.01*round(100*Aopt(1)))...
+"; Hl = "+string(0.01*round(100*Aopt(2))))
xstring(xmin, 3*height/4,...
 "gaussian: Ag = "+string(0.01*round(100*Aopt(3)))...
+"; Hg = "+string(0.01*round(100*Aopt(4))))
xstring(xmin, height/2,...
 "variance: S = "+string(0.01*round(100*S)))

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current21:11, 2 May 2019Thumbnail for version as of 21:11, 2 May 2019610 × 460 (59 KB)Cdang (talk | contribs)half variance; rounded values
14:40, 8 November 2012Thumbnail for version as of 14:40, 8 November 2012483 × 364 (57 KB)Cdang (talk | contribs)User created page with UploadWizard

The following page uses this file:

File usage on other wikis

The following other wikis use this file:

Metadata