StollLab / EasySpin

MATLAB toolbox for Electron Paramagnetic Resonance (EPR) spectroscopy
http://easyspin.org
MIT License
48 stars 25 forks source link

Spectral differences with tiny g shifts hit accuracy limit #278

Closed stestoll closed 1 year ago

stestoll commented 1 year ago

When taking the difference of two spectra that differ minimally in their g values, the difference depends on the number of points. If the number of points is too small, the result is incorrect. As Exp.nPoints is increased, the correctness improves, though not monotonically.

clc, clear, clf

lwGL = [1 1];
SysA.g = 2.0001;
SysB.g = 2.0000;
SysA.lw = lwGL;
SysB.lw = lwGL;

Exp.mwFreq = 9.5;
Exp.Range = [320 360];
Exp.Harmonic = 0;

N = [200 500 1000 2000 5000 10000 20000 100000];

resfields(SysA,Exp)
resfields(SysB,Exp)

hold on
for k = 1:numel(N)
  Exp.nPoints = N(k);
  [B_,spcA] = pepper(SysA,Exp);
  [B_,spcB] = pepper(SysB,Exp);
  B{k} = B_;
  spcdiff{k} = spcA-spcB;
  plot(B_,spcdiff{k})
end
stestoll commented 1 year ago

The reason for this is that EasySpin first constructs the stick spectrum. In this case, the stick spectra are delta peaks. For the small g change and the low field resolution, the delta peaks for the two spectra end up in the same bin. The difference of the two spectra now reveals only the difference in intensities (which depend on g), but not the change in resonance field.

The only way to improve accuracy here is to directly bin the lineshape instead of a delta peak.

micb25 commented 1 year ago

Thank you very much for pointing out this issue. For our research, we are unfortunately dealing with tiny changes in g (1e-6 to 1e-5) which obviously requires a huge number of grid points in the simulations. I took your example and modified it a little bit (see below) to further investigate the necessary grid size (Exp.nPoints) for a given value of Δg. Besides your recommendation to increase the number of grid points, there is also a significant difference in the results depending on an odd/even number of grid points used (I guess also due to the binning). Lastly, I can reproduce the identical spectra in every test run, which supports the idea that the issue is mainly based on the binning and can be solved by taking a huge number of grid points into account when dealing with small changes in g.

Simulations

Screenshot_20230116_142647

Code

clc, clear, clf

lwGL = [10 10];
deltaG = [1.0e-4 1.0e-5 1.0e-6];
SysB.g = 2.0;
SysA.lw = lwGL;
SysB.lw = lwGL;

Exp.mwFreq = 9.5;
Exp.Range = [320 360];
Exp.Harmonic = 0;

N = [1000 10000 100000 1000000 10000000];

tiledlayout(numel(deltaG), 2);
for g = 1:numel(deltaG)
  SysA.g = 2.0 + deltaG(g);  
for p = 1:2
  nexttile(p + (g-1)*2); hold on
  lgd = legend; legend show;
  lgd.Title.String = sprintf("dg = %.0e", deltaG(g));
for k = 1:numel(N)
  Exp.nPoints = N(k) + (p-1);
  [B_,spcA] = pepper(SysA,Exp);
  [B_,spcB] = pepper(SysB,Exp);
  plotlabel = char(sprintf("nPoints = %i", Exp.nPoints));
  plot(B_,spcA-spcB,'DisplayName', plotlabel)
  display(Exp.nPoints);
end
end
end
stestoll commented 1 year ago

pepper uses delta peak binning only for isotropic powder spectra with isotropic width and for single-crystal spectra with isotropic width. It could probably just use the width info to bin lineshapes directly. This would resolve this issue.

stestoll commented 1 year ago

This is not an issue for garlic , since delta-peak binning can be switched off using Opt.AccumMethod .

stestoll commented 1 year ago

Commit 2cfb173 fixes this issue. Now, pepper does not use delta-peak binning anymore if any linewidth is given. It's now possible to obtain accurate spectral differences without using a large number of field points.