Fit log scale spectrum

General forum for EasySpin: questions, how to's, etc.
Post Reply
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Fit log scale spectrum

Post by thanasis »

Hello,

I have a dataset consisting of a couple of major resonances and several much weaker ones which, however, have an important diagnostic value.

The problem is that, I believe, ES focuses in minimising the error function arising from the major peak, and cannot fit the smaller resonances. They simply do not contribute enough to the error function.

I thought of fitting the log-scale spectrum, so that weaker resonances are accentuated and better taken into account.

I am pretty sure ES doesn't have a built-in function to do this, so I though of doing it with a custom function. However, logs of negative numbers are not defined.
To get around this, I thought of integrating the derivative spectrum, taking the log and differentiating, however the differentiation truncates a point and then it gets ugly trying to reassign intermediate field values to the derivative spectrum.

Could anyone suggest a strategy toward this end?

Thanks!
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Fit log scale spectrum

Post by katarkon »

I think follow code will be better.

Code: Select all

Y=sign(y)*log(abs(y));
I'm afraid however that this will make poor SNR anyway.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit log scale spectrum

Post by thanasis »

Thanks, that's a step in the right direction.

Actually, I needed to calculate logspc=sign(spc).*log(abs(spc)) (with .*). The S/N is not problem, the spectrum was very good to begin with, so even the log has no visible noise.

Now, I invoke logspsc in my esfit call:

Code: Select all

esfit('fit_log',logspc,Sys1,Vary1,Exp,[],FitOpt);
where fit_log is my fitting function.

Within that, I invoke pepper and then do the same treatment to the output:

Code: Select all

function [x,y] = fit_log(Sys1,Exp,Opt);
fullSys = Sys1;
[x,y] = pepper(fullSys,Exp,Opt);
y=sign(y).*log(abs(y));
However, I seem to have problems with Easyspin's calculation of the baseline and/or the calculated spectrum (see image), or there is something I am doing wrong.
Selection_099.jpg
Selection_099.jpg (28.84 KiB) Viewed 2614 times
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Fit log scale spectrum

Post by katarkon »

Yes, it's the second problem. I suggest both exp and sim spectra should not contain values between 0 and 1 (i.e. 0<y<=1). If not, the rescalling before logarithmation is required. I suggest that sign(y)*log(abs(y)) returns zero for y=0, although it should be checked too.
UPD. I suggest that root function of odd order (like cubic root) should be more appropriate.
UPD2. The right solution for log scaling should be as follow Y=sign(y).*log(1+abs(y)). This exclude negative log(y) values and log(0) calculations as well.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit log scale spectrum

Post by thanasis »

Thanks for the updates. I already tried the Y=sign(y).*log(1+abs(y)) approach and will also try an odd order polynomial.

However, for the moment, I still get the regular EPR calculated spectrum.

It seems that the

Code: Select all

[x,y] = pepper(fullSys,Exp,Opt);
y=sign(y).*log(1+abs(y));
declaration in the custom function does not return the modified result to the main script (see screenshot).
Selection_100.jpg
Selection_100.jpg (22.12 KiB) Viewed 2598 times
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit log scale spectrum

Post by thanasis »

I found that I get a nice amplification of the weaker features by a square-root spectrum (i.e. spc = sign(spc).*power(abs(spc),1/2);), like below:
Selection_101.jpg
Selection_101.jpg (14.42 KiB) Viewed 2595 times
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Fit log scale spectrum

Post by katarkon »

I suggest to use Y=nthroot(y,n) where n is odd number (i.e. n=3,5,7,etc) instead. It works correctly with negative values, it isn't necesssary to use tricks like sign() and abs() functions more. Also, required "gain" of weak resonances may be easily adjusted by varying of n.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit log scale spectrum

Post by thanasis »

Indeed, that came in very handy. The 7th root gives a nice balance between weak ans strong features.

Now the issue is to correct the way the scaling is done. I think that the default algorithm doesn't know of the changes to the fitted curve and cannot properly treat it:
Selection_102.jpg
Selection_102.jpg (26.27 KiB) Viewed 2592 times
Post Reply