fitting a difference spectrum

General forum for EasySpin: questions, how to's, etc.
Post Reply
bchica
Newbie
Posts: 5
Joined: Mon Apr 08, 2019 1:44 pm

fitting a difference spectrum

Post by bchica »

Hello,
Is it possible to use the esfit fitting function in EasySpin to fit a difference epr spectrum? i generated a difference spectrum because subtracting two spectra shows a transition from one state to another and eliminates interference from overlapping signals that do not change. it should be the same as fitting S=1/2 two spin systems, just that the spectra for one of the spin systems should be multiplied by -1. I have attached an experimental spectrum along with a simulation that gets the parameters pretty close, although a better fit could definitely be achieved with the fitting algorithm

here is the matlab code I used. diff_240 is the experimental data:

%%
P_plus.S = 1/2;
P_plus.g = [1.814 1.95 2.054];
P_plus.gStrain = [.018,.0125,.013];

Exp.mwFreq = 9.374244;
Exp.Range = [255 415];
[B,pplus] = pepper(P_plus,Exp);

P_plus_star.S = 1/2;
P_plus_star.g = [1.892 2.006];
P_plus_star.gStrain = [.021,.01];

P_plus.weight = .09;
P_plus_star.weight = .022;

[B,pplusstar] = pepper(P_plus_star,Exp);

figure(1);
plot(B,pplus- pplusstar,B,diff_240);
figure(2);
plot(B,pplus- pplusstar-diff_240);
%%

Best

Bryant Chica

Screen Shot 2021-01-11 at 5.33.36 PM.png
Screen Shot 2021-01-11 at 5.33.36 PM.png (53.16 KiB) Viewed 2410 times
Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: fitting a difference spectrum

Post by Stefan Stoll »

You can write a custom simulation function that simulates the two spectra and returns the difference spectrum. Then use esfit with this custom simulation function. See https://easyspin.org/easyspin/documenta ... omfunction

bchica
Newbie
Posts: 5
Joined: Mon Apr 08, 2019 1:44 pm

Re: fitting a difference spectrum

Post by bchica »

Thank you Dr Stoll!

I have written the following code and confirmed that my custom simulation function returns the difference spectrum. When I run it the esfit user interface pops up with my data (contained in the variable diff_240) and it all seems normal. when I hit "Start" in the esfit dialog box however i get the following error:

"
Error using esfit
Error using
LiveEditorEvaluationHelperESectionEval395efceb>diff_sim
Too many input arguments.

Error in esfit_simplex

Error in esfit

Error while evaluating UIControl Callback.
"

This is the code I am using:

P_plus.S = 1/2;
P_plus.g = [1.814, 1.95, 2.054];
P_plus.gStrain = [0.018, 0.0125, 0.013];
P_plus.weight = 0.09;

P_plus_star.S = 1/2;
P_plus_star.g = [1.892 2.006];
P_plus_star.gStrain = [0.0235, 0.01];
P_plus_star.weight = 0.022;

Exp.mwFreq = 9.374244;
Exp.Range = [255 415];

Vary_P_plus.g = [0.05, 0.05, 0.05];
Vary_P_plus.gStrain = [0.005, 0.005, 0.005];
Vary_P_plus.weight = 0.09;

Vary_P_plus_star.g = [0.05, 0.05];
Vary_P_plus_star.gStrain = [0.005, 0.005];
Vary_P_plus_star.weight = 0.005;

esfit(@diff_sim, diff_240, {P_plus,P_plus_star}, {Vary_P_plus, Vary_P_plus_star}, Exp);

function y = diff_sim(Sys,Exp);
[x,y1] = pepper(Sys(1),Exp);
[x,y2] = pepper(Sys(2),Exp);
y = y1 - y2

end

Thank you for your help,

Bryant Chica

Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: fitting a difference spectrum

Post by Stefan Stoll »

I think you need to define your function with three input argument: function y = diff_sim(Sys,Exp,Opt)

bchica
Newbie
Posts: 5
Joined: Mon Apr 08, 2019 1:44 pm

Re: fitting a difference spectrum

Post by bchica »

Yes, that was the issue! Now the code is working! thank you!

Cheers,

Bryant

Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: fitting a difference spectrum

Post by Stefan Stoll »

Great!

Post Reply