Page 1 of 1

Simulated Spectrum Output

Posted: Wed Sep 09, 2015 9:13 pm
by TonyChem
Hi All

I am just starting to use ES to simulate my EPR spectra. There is a question that may sound stupid but is in need of your help. Once I complete the fitting, I don't how to proceed to output the simuated spectrum. I tried the following code but it did not work and what I recieved is the raw experimental data.

= esfit('pepper', spc, Sys, Vary, Exp, SimOpt, FitOpt);
data = [B(:) spc(:)];
save('simdata.txt','data','-ascii');

Can anyone advise me how to sort out this problem. Many thanks.

Tony

Re: Simulated Spectrum Output

Posted: Thu Sep 10, 2015 3:12 pm
by Stefan Stoll
Unlike EasySpin's simulation functions, esfit does not return the x-axis. You can construct it yourself very easily using your settings in Exp

Code: Select all

Exp.Range = [300 400];   % field range use for sims and esfit

nPoints = numel(spc);    % number of points in spectral data vector
B = linspace(Exp.Range(1),Exp.Range(2),nPoints); % field axis

Re: Simulated Spectrum Output

Posted: Fri Sep 11, 2015 8:22 pm
by TonyChem
Thanks Stefan
I did change the code as you suggested. A new error pops up,

The following error occurred converting from double to struct:
Error using struct
Conversion to struct from double is not possible.

Error in simcode (line 41)
data = [B(:) spc(:)];

what i want to do is to save the simulated spectum into a txt file by using the following codes,
data = [B(:) spc(:)];
save('simdata.txt','data','-ascii');

Can you further advise me what problem this is. Thank you.

Tony

Re: Simulated Spectrum Output

Posted: Sat Sep 12, 2015 5:23 pm
by Matt Krzyaniak
From esfit you have two potential outputs.
If you only have one output argument you'll get your fit paramters such as:

Code: Select all

fitparams = esfit('pepper', spc, Sys, Vary, Exp, SimOpt, FitOpt);
[B,spc] = pepper(fitparams,Exp);
data = [B(:) spc(:)];
save('simdata.txt','data','-ascii');
If you provide two outputs the first one best fit parameters and the second is the best fit spectrum so you'd need to do:

Code: Select all

[fitparams,spc] = esfit('pepper', spc, Sys, Vary, Exp, SimOpt, FitOpt);
nPoints = numel(spc);    % number of points in spectral data vector
B = linspace(Exp.Range(1),Exp.Range(2),nPoints); % field axis
data = [B(:) spc(:)];
save('simdata.txt','data','-ascii');
*edited to address errors.

Re: Simulated Spectrum Output

Posted: Sun Sep 13, 2015 2:00 pm
by TonyChem
thanks for your reply. An error in data = [B(:) spc(:)] remains.
Below is the code i used. Please advise me how to improve. Thank you.

clear

% below is a standard fitting code
[B,spc] = eprload('La.par')
Sys0.S = 1/2;
Sys0.Nucs = '139La, 139La, 139La';

Exp.mwFreq = 9.386; % GHz
Exp.Range = [170 470]; % in mT Field range use for sims and esfit
nPoints = numel(spc); % number of points in spectral data vector
B = linspace(Exp.Range(1),Exp.Range(2),nPoints); % field axis


% Now we set up the least-squares fitting.
% First comes a starting set of parameters (which we
% obtain by copying the spin system from the simulation
% and changing a few values)
Sys0.g = [2.002 2.002 2.002];
Sys0.A = [60 140 170]; % MHz nuclei added using a set of fields 90 150 190
Sys0.lwpp = 1.2; % mT 1.802 [1.8020 2.1593 2.2020 90 200 220]

% Next, we specify which parameter we want to be fitted
% and by how much the fitting algorithm can vary it approximately.
Vary.g = [0.05 0.05 0.05];
Vary.A = [10 20 20];
SimOpt.Method = 'perturb';

% Calling the fitting function
FitOpt.Method = 'simplex int'; % simplex algorithm, integrals of spectra
[spc, fitparams] = esfit('pepper',spc,Sys0,Vary,Exp,SimOpt,FitOpt);
data = [B(:) spc(:)];
save('myfile.txt','data', '-ascii');
plot(B, spc);

Re: Simulated Spectrum Output

Posted: Mon Sep 14, 2015 7:27 am
by Matt Krzyaniak
Oops that was a bunch of wrong stuff on my part, if you glance at the output from esfit you'll see that one of them is a structure the other is just a vector. I flipped around what the outputs actually are, the first output are the best fit parameters while the second is the best fit spectrum.

I edited the above post to fix my error.