
clearvars
load_Path = 'MgB2\ESR Maps\';

%% Input select filename

    [fname,pname] = uigetfile('*.mat','Load file',load_Path); 
    file=[pname fname];                             

    fname = fname(1:end-4);
    
%% Load information and data 
 
load(file,'M','CenterF_GHz','Ftot','Width_MHz');

%% Obtain frequency information

vmid = CenterF_GHz; %GHz
vspan = Width_MHz; %MHz
vstep = (Ftot(2)-Ftot(1))*1e3; %MHz 
v0 = Ftot(1)*1e3;

ESRMatrix = M;
[h,w,v] = size(M);
clear M; clear CenterF_GHz; clear Width_MHz; clear Ftot; 

for indaxev = 1:v
    v_MHz (indaxev) = v0 + (indaxev-1)*vstep;
end

%% Plot one ESR spectrum

ix = 70; % in pixels
iy = 70; % in pixels    

spectre = squeeze(ESRMatrix(iy,ix,:))/max(1,mean(squeeze(ESRMatrix(iy,ix,1:10))));
    
fig = figure();

plot(v_MHz,spectre,'Color','Blue')
ax = gca;
%ylim([0.981 1.012])
%ax.YTick=[0.985;0.995;1.005];
xlim([v_MHz(1) v_MHz(v)])
ax.XAxisLocation = 'bottom';
ax.TickDir = 'out';
xlabel('\nu (MHz)');
ylabel('Renormalized Luminescence (au)','VerticalAlignment','bottom','HorizontalAlignment','center');   


