Page 1 of 1

Modification of esfit() function

Posted: Mon Jan 09, 2017 3:59 am
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)

Re: Modification of esfit() function

Posted: Mon Jan 09, 2017 12:53 pm
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?

Re: Modification of esfit() function

Posted: Tue Jan 10, 2017 12:47 am
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

Re: Modification of esfit() function

Posted: Tue Jan 10, 2017 9:35 am
by Stefan Stoll
Please post a short script of what you would like to do which is not possible now.

Re: Modification of esfit() function

Posted: Tue Jan 10, 2017 12:10 pm
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.

Re: Modification of esfit() function

Posted: Tue Jan 10, 2017 1:33 pm
by Stefan Stoll
That makes sense. We will add this to our list of improvements.