%%
clear all
%% load data
A = importdata('Van60.dat','\t',45);
BexpHF = (A.data(17:end,1))*1000;
BexpHF = BexpHF - 10 ;
SexpHF = A.data(17:end,2);
SexpHF=SexpHF/max(SexpHF)-1.242;

SexpHF=smoothdata(SexpHF,'movmedian',5);

%% Simulation parameters
Sys.S = 1/2;
Sys.g = [1.985 1.965 1.9652];
Sys.Nucs = '51V';
Sys.A = [151.6000 453.7908]; 
Sys.lw = 0.83;
Sys.gStrain = 0.0004;
Exp.mwFreq = 210;
Exp.Range = [min(BexpHF) max(BexpHF)];
Exp.Harmonic = 1;
Exp.Temperature = 4;
Exp.CrystalOrientation =[-10*(pi/180) 9*(pi/180) 0];
Exp.nPoints = 2453;
Exp.mwPhase = -95*(pi/180);
[BsimHF,SsimHF] = pepper(Sys,Exp);
SsimHF = SsimHF/max(SsimHF);


Sys.CrystalOrientation = [0 15*(pi/180) 0];
Sys.mwPhase = 125*(pi/180);
% plot
plot(BexpHF, SexpHF, 'b', BsimHF, SsimHF/5, 'r')
xlim([7550 7710])
ylim([-1.1 1.1])

BsimHF2=transpose(BsimHF);
SsimHF2=transpose(SsimHF);

xlabel('Magnetic filed [mT]')
ylabel('Absorption[-]')
title('-') 
legend('Experimental','Simulated')
%% Fitting HF-Data
Vary.lw = 0.1;
Vary.g = [0 0];
Vary.A = [0 0];
Vary.CrystalOrientation = [0 2 0];
Vary.mwPhase= 0.3;
esfit('mymy',SexpHF,Sys,Vary,Exp)