Global fit of several multicomponent cwEPR spectra with variable weights

General forum for EasySpin: questions, how to's, etc.
Post Reply
msignori
Newbie
Posts: 1
Joined: Tue Jul 30, 2024 10:41 pm

Global fit of several multicomponent cwEPR spectra with variable weights

Post by msignori »

Hello,

I'm trying to perform a global fit on a set of approximately 10 cwEPR spectra of frozen solutions taken over the course of a reaction, where an EPR-silent initial state first converts into a radical species X and subsequently into a second radical species Y.

I hardly managed to fit individual spectra as mixtures of X and Y and reconstruct the overall concentration vs. reaction time. However, I am wondering if it would be possible to globally fit the entire dataset. The aim would be to fit the spin parameters (g, A, etc.—the same values across the entire dataset) globally along with the weights of X and Y (which change for each spectrum in the dataset).

I tried to handle this with a custom function but couldn't manage it. Could you help me with this task? Perhaps I'm missing something obvious.

Best,

Matteo

thanasis
Local Expert
Posts: 253
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Global fit of several multicomponent cwEPR spectra with variable weights

Post by thanasis »

A custom function is indeed the way to go. You will need to make a vector with all the spectra on which you need to minimize the calculated ones. I guess you will also need to introduce a vector of relative weights, whose elements will each be a fitting variable.

Then you feed the spin Hamiltonian and other common variables of the two species and inside the function make a calculation for each.

Your request is similar to this discussion.

Other than that, your code will be needed for more help.

katarkon
Local Expert
Posts: 193
Joined: Mon Jan 12, 2015 4:01 am

Re: Global fit of several multicomponent cwEPR spectra with variable weights

Post by katarkon »

I've solved the similar problem, see the topic viewtopic.php?t=465
The code You need is follow:
function varargout = weightfit(Sys,Exp,Opt)
%
%Wrapper for global weight fitting
%returns concatenated spectrum for all spectra
%for using with esfit() function
%Sys.weight - the array of weights
%Sys.nPoints - the array with number of points for each spectrum (if different, no need if equal)
%
if (nargin<2), Exp = struct; end
if (nargin<3), Opt = struct; end

spc=[];
Sys1=Sys{1}; %decompose cell array
Sys2=Sys{2};
Sys1a=Sys1;
Sys2a=Sys2;

nSpec=size(Sys1.weight,2);

for i=1:nSpec
if isfield(Sys,'nPoints')&&numel(Sys.nPoints)>1,Exp1.nPoints=Sys.nPoints(i);end
if numel(Exp1.Range)>2,Exp1.Range=Exp.Range(i,:);end

if numel(Sys.lw)>1,Sys1.lw=Sys.lw(i);end
Sys1a.weight=Sys1.weight(i);
Sys2a.weight=Sys2.weight(i);
spc1=pepper({Sys1a,Sys2a},Exp,Opt);
spc=cat(2,spc,spc1);

end
% Output
%-------------------------------------------------------------

varargout = {spc};
end

Sys1.weight and Sys2.weight should be arrays with the weights for each spectrum.

Post Reply