The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Piecewise Fitting Gauss Lorentz
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

5rooms

4 Posts

Posted - 03/14/2018 :  12:09:15 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi everyone,

I have a question regarding the piecewise fitting of a curve. My peak has to be fitted with a Gaussian profile for values smaller than the maximum and with a Lorentz function bigger than the maximum. I used the tutorial

https://www.originlab.com/doc/Tutorials/UDF-Quote-BuiltInFunc
(as quoted in https://my.originlab.com/forum/topic.asp?TOPIC_ID=19647)

to create such a fitting function (I did exactly as described in the tutorial and just changed the second nlf_Gauss to nlf_Lorentz). It works in principle, but the resulting fitting function is no steady (see attached screenshot). How can I fix this problem?



Thank you very much!


Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2017G (64-bit) SR2
Operating System: Windows 7 64 bit

AmandaLu

439 Posts

Posted - 03/15/2018 :  02:41:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If you want the two segments connect smoothly, you will need to make the two functions connect at center point (xc, yc). That is,
yc1 = yc2,
in which
yc1 = A1/(w*sqrt(pi/(4*ln(2)))),
yc2 = 2*A2/(w*pi)

So we have
A2 = A1*sqrt(ln(2)*pi)
Then you can modify the function as follow:
Parameters:
y0,xc,w1,w2,A1
Function body:
double A2 = A1*sqrt(ln(2)*pi);
y = x<xc? nlf_Gauss(x, y0, xc, w1, A1) : nlf_Lorentz(x, y0, xc, w2, A2);


The fitting result should be something like:


Thanks,
Amanda
OriginLab Technical Service

Edited by - AmandaLu on 03/15/2018 02:42:04 AM
Go to Top of Page

5rooms

4 Posts

Posted - 03/15/2018 :  05:58:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Amanda,

thank you very much for your fast and helpful support. I changed the function as you recommended, but the Gaussian and the Lorentz profile still don't connect smoothly even though the position of the maximum is way better now.



I attached a screenshot of the function editor



Just for your information: don't worry about the bad fit between 15000 and 25000, this is something I will take care of later.

Thanks

Andreas
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 03/15/2018 :  4:11:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andreas,

Maybe you can take more straightforward way to share the height of the peak - by using the amplitude
version of Gaussian, GaussAmp(x,y0,xc,w1,A), and defining the similar version of Lorentz, that is:
LorentzAmp(x,y0,xc,w2,A) = y0+(A*w2^2)/(4*(x-xc)^2+w2^2)
I tried, and it seems working:



I hope this helps.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 03/15/2018 5:14:31 PM
Go to Top of Page

AmandaLu

439 Posts

Posted - 03/16/2018 :  04:23:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andreas,

Sorry my derivation was wrong. To make yc1 = yc2, the relationship of A2 and A1 should be

A2 = A1*w2*sqrt(pi/2)/w1

Please modify your function body accordingly.

Thanks,
Amanda
OriginLab Technical Service
Go to Top of Page

5rooms

4 Posts

Posted - 03/16/2018 :  06:12:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much for your great support, the function works perfectly now!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000