Modification of esfit() function

A place to report and discuss potential bugs
Post Reply
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Modification of esfit() function

Post by katarkon »

I have found a strange behaviour of esfit() function with multicomponent fitting. It looks that simulation function is called for each spin system separately but the weight coefficient Sys.weight must be treated inside the simulation function. I think that follow construction is used into esfit() function:

Code: Select all

y=simfunction(Sys{1},Exp,Opt)+simfunction(Sys{2},Exp,Opt)+simfunction(Sys{3},Exp,Opt)+...
I propose to modify the function esfit() to call the simulation in multicomponent manner, if it is not too hard, of course. I.e. using follow calling:

Code: Select all

y=simfunction({Sys1,Sys2,...},Exp,Opt)
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Modification of esfit() function

Post by Stefan Stoll »

This will not result in observable changes, so it is unclear why this is needed. Do you have a use case where this makes a difference?
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Modification of esfit() function

Post by katarkon »

It should provide the simplest way to fit the experimental parameters by custom simulation function. Now it is impossible without some tricks.
viewtopic.php?f=3&t=371
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Modification of esfit() function

Post by Stefan Stoll »

Please post a short script of what you would like to do which is not possible now.
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Modification of esfit() function

Post by katarkon »

OK, let's vary MW frequency. The function esfit() does not allow varying of Exp parameters (although it would be nice), so we have to use custom simulation function:

Code: Select all

function y = mysim(Sys,Exp,Opt);
if isfield(Sys,'mwFreq'),Exp.mwFreq = Sys.mwFreq; end
y = garlic(Sys,Exp,Opt);
This will be working only for single component spectrum:

Code: Select all

Sys.mwFreq = 9.65;
Sys.g=2;
Vary.mwFreq = 0.05;
Exp.Range =[...];
esfit('mysim',data,Sys,Vary,Exp);
For two components we'll obtain separate MW frequency for each one:

Code: Select all

Sys1.mwFreq = 9.65;
Sys1.g=2;
Vary1.mwFreq = 0.05;
Sys2.mwFreq = 9.65;
Sys2.g=2.05;
Vary2.mwFreq = 0.05;
Exp.Range =[...];
esfit('mysim',data,{Sys1,Sys2},{Vary1,Vary2},Exp);
There are no ways to keep Sys1.mwFreq and Sys2.mwFreq equal during fitting.
If calling of the simulation function from esfit() will be changed as I propose, it will be possible to make correct frequency fitting:

Code: Select all

function y = mysim(Sys,Exp,Opt);
Sys1=Sys{1};
Sys2=Sys{2};
if isfield(Sys1,'mwFreq'),Exp.mwFreq = Sys1.mwFreq; end
y = garlic(Sys1,Exp,Opt)+garlic(Sys2,Exp,Opt);
The varying of MW frequency is required because Bruker EMX spectrometer writes its value only for last spectrum in sequence. The frequency drift due to fine tune is ignored.
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Modification of esfit() function

Post by Stefan Stoll »

That makes sense. We will add this to our list of improvements.
Post Reply