% Chirp Echo FT EPR-detected NMR
%
% 11/2017 Nino Wili: nino.wili@phys.chem.ethz.ch
% EPR @ ETH Zurich

% Plot of conventional EDNMR spectrum of nitroxide

clear, close all;

%load data with function tailored to our AWG spectrometer
options.plot = 0; % 0 for do not plot by uwb_eval
options.evlen = 2800; % length of evaluation window in points
data=uwb_eval('20170831_1636_fstep_EDNMR',options);

%extract needed data from struct
f_HTA=data.dta_x{1};  %frequency axis of HTA pulse
spc=real(data.dta_ev); %averaged and integrated echo transients

%calculate ednmr spectrum and frequency axis
f_ednmr=f_HTA-data.exp.events{end}.det_frq;
ednmr=1-(spc/max(spc)); ednmr=ednmr/max(ednmr);

%caluclate filtered ednmr_spectrum
ednmr_filt = ifftshift(ifft(ednmr)) ;
window=chebwin(numel(ednmr_filt))';
ednmr_filt=window.*ednmr_filt;

ednmr_filt=(fft(fftshift(ednmr_filt)));

plot(real(ednmr_filt))


%%
%Plot
h=figure(1);
clf;
%plot spectrum
plot(1e3*f_ednmr,ednmr,'k','linewidth',2)
%make nicer
h=niwi_niceplot(h,[15 8]);
box off
hold on
%plot zoom
plot(1e3*f_ednmr,ednmr*6+0.2,'k','linewidth',1)
%plot zoom
plot(1e3*f_ednmr,ednmr_filt*6+0.8,'r','linewidth',1)


%annotations and changes of figure appearance
text(-78,0.7,'x6')
text(-82,1.4,'{\color{red} filtered}')

text(-54,1.95,'$^{1}$H','Horizontalalignment','center','verticalalignment','bottom')
text(52,1.95,'$^{1}$H','Horizontalalignment','center','verticalalignment','bottom')

text(-32,1.5,'$^{14}$N','Horizontalalignment','left','verticalalignment','bottom')
text(23,1.7,'$^{14}$N','Horizontalalignment','left','verticalalignment','bottom')

text(41,1.24,'*','Horizontalalignment','left','verticalalignment','bottom')
text(70,1.15,'*','Horizontalalignment','left','verticalalignment','bottom')

%adjust figure
xlabel('$( \nu_{\\text{HTA}}-\\nu  )$ / MHz')
ylabel('EDNMR Intensity / a.u.')
set(gca,'Ytick',[])
axis([-85 85 -0.04 1.94])
set(findall(h,'-property','Fontsize'),'Fontsize',12); % change fontsize

%Only needed for integration with Latex
% niwi_Plot2LaTex(h,'chirp_ednmr_vs_classical_classical');