%% Federico Lombardi

clear
%% Import file
filename = '004_CPMG_RT.DTA';
[time,spc] = eprload(filename);
spc = real(spc);
time = time - 448;
Number_of_pulses = 20;
tau = 440;
[t, intensity] = CPMG_integrator_peaks(time, spc, tau, Number_of_pulses);
t = t(3:end);
intensity = intensity(3:end);
intensity = intensity - mean(spc(end-20,end));
B = [t intensity];
plot(time,spc)
hold on
plot(t,intensity)
filename1 = [filename(1:end-4) '.tsv'];
fileID = fopen(filename1,'w');
fprintf(fileID,'%1s\t%15s\n','t','Echo Intensity');
fprintf(fileID,'%2s\t%2s\n','ns','');
fprintf(fileID,'%20s\t%3s\n','DFB1 DTOL RT', num2str(tau));
fclose(fileID);
dlmwrite(filename1, B,'delimiter','\t','-append');

