Here is the code:
Code: Select all
% Fitting easyspin functions using lsqcurvefit
clear;
% open file, if you use open file:
% [StrFile,StrDir,FilterIndex] = uigetfile('*.spe','Open file','c:\Users\Dusan\Documents\EPRmerenja\Marija ZoranSap');
% StrFullPath = [StrDir StrFile];
% open file, if you use direct link from HD
StrFullPath = 'c:\Users\Dusan\Documents\EPRmerenja\Marija ZoranSap\Pani.spe'; % your path here!
[B,I,param]=eprload(StrFullPath);
% File can be found at https://www.dropbox.com/s/7h4rzln5r20egzw/Pani.spe?dl=0
I=(I-I(1))*100/param.Gain;
% Initial values
Ip = 40000; g0p = 2.001; DBp = 0.3; Cp = 0;
initial = [Ip, g0p, DBp, Cp];
LB = [10 2.0000 0.01 -1000]; UB = [400000 2.005 1 1000];
% Fitting Easyspin single Lor line
FitES = lsqcurvefit(@fEasyspinForumLor, initial, B, I,LB,UB);
IinitialES = fEasyspinForumLor(initial,B);
IFittedES = fEasyspinForumLor(FitES,B);
% Fitting with Lorentzian
FitLor = lsqcurvefit(@fLorForum, initial, B, I,LB,UB);
IinitialLor = fLorForum(initial,B);
IFittedLor = fLorForum(FitLor,B);
% Plot experimental, initial and fitted curve
figure;
plot(B,I,'c','linewidth',5,'DisplayName','Exp'); hold on;
plot(B,IinitialES,'b--','linewidth',4,'DisplayName','ES init.'); hold on;
plot(B,IFittedES,'b','linewidth',3,'DisplayName','ES fitted'); hold on;
plot(B,IinitialLor,'r--','linewidth',3,'DisplayName','Lor init.'); hold on;
plot(B,IFittedLor,'r','linewidth',2,'DisplayName','Lor fitted'); % hold on;
legend('show');
grid on;
and the functions are here:
Lorentzian:
Code: Select all
% Lorentzian plus constant
function y = fLorForum(cc,x)
frek = 9.361;
B0 = mhz2mt(frek *1000) * gfree / cc(2); % from g to B
y=-(2*(cc(1)/pi)*cc(3)*(x-B0))./(cc(3)^2 + (x-B0).^2).^2 + cc(4); % derivative Lor, version with int ~ I only.
% Identical to easysin version according to documentation.
end
and this is Lorentzian made using Easyspin:
Code: Select all
%Easyspin Lorentzian
function y = fEasyspinForumLor(c,x)
Exp.mwFreq = 9.361; % frequency
% gg = (mhz2mt(frek *1000) / c(2)) * gfree; % ovo prebacuje B u g
Exp.Range = [x(1) x(end)];
Exp.nPoints = length(x);
Sys.g = c(2);
Sys.lw = [0 c(3)*2];
[xP,yP1] = pepper(Sys,Exp);
y = c(1) * 1.807713 * yP1 / 1000 +c(4);
y = y.';
end
The experimental file is here:
https://www.dropbox.com/s/7h4rzln5r20egzw/Pani.spe?dl=0
There is factor 1.8077 / 1000 that has to be used to obtain same intensity for Easyspin Lorentzian to compare to Lorentzian line.
if you fit this spectrum you got fit that is no good as the one obtained with explicit Lorentzian line?!? The same initial values are used.