Contents

function [] = Display_Spikes(I,wav,Isum,FWHMdat,I_LP_Cut,ffilt,pk,pkw,SpectrumOfInterest,Imin)
if numel(findobj('Tag','Maxima Count'))>0 %Prevents multiple figures
    close(findobj('Tag','Maxima Count'))
end
figure('Name','Maxima Count','Tag','Maxima Count');
[ymax1,imax1,~,~] = extrema(I(:,SpectrumOfInterest));

first upper Subplot (4,1,1 = full with, top position)

subplot(4,1,1);
plot(wav,Isum);

line([FWHMdat.wavl FWHMdat.wavl],[0 max(Isum)],'Color','r'); %These lines mark the FWHM area
line([FWHMdat.wavr FWHMdat.wavr],[0 max(Isum)],'Color','r');
line([FWHMdat.wavr FWHMdat.wavl],[max(Isum)/2 max(Isum)/2],'Color','r');
ylabel('Averaged shots');
xlim([min(wav) max(wav)]);

V=axis;     %returns scaling values(4) for current plot /R
ylim([0 V(4)]);
text(double(V(2)),double(V(4)),sprintf('FWHM = %.3f nm = %.0e sec^-^1 (%.2f%%)  ',FWHMdat.FWHM,FWHMdat.FWHM_f,100*FWHMdat.bandwidth),...
    'HorizontalAlignment','right','VerticalAlignment','top','FontSize',10);

writes EW and rmsw into the figure, if already defined

if exist('rmsw','var') && exist('rmsws','var')
text(double(V(1)),double(V(4)),sprintf(' rms(average) = %.4fnm\n average(rms) = %.4fnm',rmsw,mean(rmsws)),...
    'HorizontalAlignment','left','VerticalAlignment','top','FontSize',10);
end
if exist('Ew','var')
text(double(V(2)),double(V(4)),sprintf('\n Wavelength expected value= %.3fnm ',Ew),...
    'HorizontalAlignment','right','VerticalAlignment','top','FontSize',10);
end
clear V

second upper subplot

subplot(4,1,2);
plot(wav,I(:,SpectrumOfInterest),wav(imax1),ymax1,'*');
ylabel('Single shot');
xlim([min(wav) max(wav)]);
ylim([0 max(I(:,SpectrumOfInterest))*1.1]);
V=axis;
text(double(V(2)),double(V(4)),sprintf('event #%.0f ',SpectrumOfInterest),...
    'HorizontalAlignment','right','VerticalAlignment','top','FontSize',10);
clear V

counts maxima of the line of interest

[ymax2,imax2,~,~] = extrema(I_LP_Cut(:,SpectrumOfInterest));

imax2w=imax2(wav(imax2)<wav(FWHMdat.nr) & wav(imax2)>wav(FWHMdat.nl)); %maxima indexes in FWHM
ymax2w=ymax2(wav(imax2)<wav(FWHMdat.nr) & wav(imax2)>wav(FWHMdat.nl)); %maxima values in FWHM

second lowest Subplot (4,1,3 = full width, 3/4 lowest position

subplot(4,1,3);
   plot(wav,I_LP_Cut(:,SpectrumOfInterest),wav(imax2),ymax2,'*');
   hold all
   plot(wav(imax2w),ymax2w,'r+');
   hold off
   ylabel('Single shot (filtered)');
   xlabel('Wavelength, nm');
   xlim([min(wav) max(wav)]);


%   V=axis;
   %ylim([0 V(4)]);
   ylim([0 max(I(:,SpectrumOfInterest))*1.1]);
%   clear V
   hold off

   NPPUF=mean(pkw)/FWHMdat.FWHM_f; %number of pearks per unit frequency

   V=axis;
   text(double(V(2)),double(V(4)),sprintf('The number of FWHM peaks per unit \nfrequency is = %.3e sec ',NPPUF),...
       'HorizontalAlignment','right','VerticalAlignment','top','FontSize',10);
   text(double(V(1)),double(V(4)),sprintf(' Filter options:\n Imin = %.2f\n ffilt= %.0f',Imin,ffilt),...
       'HorizontalAlignment','left','VerticalAlignment','top','FontSize',10);
   clear V

   TfromNPPUF=NPPUF*2*pi/0.641;


   disp(['The number of peaks per unitfrequency is ',num2str(NPPUF),'1/s', ', corresponding to T=',num2str(TfromNPPUF),'s']);

lowest subplot

   subplot(4,1,4);
   plot(pk,'.');
   hold on
   plot(average_over_N(pk),'LineWidth',2,'Color','red')

   ylabel('No of maxima');
   xlabel('Event number');
   line([0 size(pk,2)], [mean(pk) mean(pk)],'color', 'g');
   xlim([0 size(pk,2)]);



V=axis;
text(double(V(2)),double(V(4)),sprintf('Mean No of maxima = %.1f (within a FWHM= %.1f) ',mean(pk),mean(pkw)),...
    'HorizontalAlignment','right','VerticalAlignment','top','FontSize',10);
clear V
end