Simulated Spectrum Output

General forum for EasySpin: questions, how to's, etc.
Post Reply
TonyChem
Newbie
Posts: 4
Joined: Wed Sep 09, 2015 9:04 pm

Simulated Spectrum Output

Post 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
Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Simulated Spectrum Output

Post 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
TonyChem
Newbie
Posts: 4
Joined: Wed Sep 09, 2015 9:04 pm

Re: Simulated Spectrum Output

Post 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
Matt Krzyaniak
EasySpin Guru
Posts: 153
Joined: Tue Jul 22, 2014 11:01 am
Location: Northwestern University

Re: Simulated Spectrum Output

Post 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.
TonyChem
Newbie
Posts: 4
Joined: Wed Sep 09, 2015 9:04 pm

Re: Simulated Spectrum Output

Post 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);
Last edited by TonyChem on Mon Sep 14, 2015 7:24 pm, edited 1 time in total.
Matt Krzyaniak
EasySpin Guru
Posts: 153
Joined: Tue Jul 22, 2014 11:01 am
Location: Northwestern University

Re: Simulated Spectrum Output

Post 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.
Post Reply