function [zcorrel,peakn,confint,HalfPeak,HPW,widths1,widths2]=norm_corr(correl,shoulder,signals)
    
%%%Z-Score%%%%%%%
Rshoulder=length(correl{1}(1,:))-shoulder;

for i=1:length(correl)
    for h=1:length(correl)
            SBins(1:shoulder)=correl{i}(h,1:shoulder);
            SBins(shoulder+1:2*shoulder)=correl{i}(h,Rshoulder+1:end);
            SBM=mean(SBins);
            SBSD= std(SBins);
            zcorrel{i}(h,:)=(correl{i}(h,:)-SBM)./SBSD;
            standdev=std(zcorrel{i}(h,:));
            confint{i}(h,1)=0-1.96*standdev/sqrt(length(zcorrel{i}(h,:)));
            confint{i}(h,2)=0+1.96*standdev/sqrt(length(zcorrel{i}(h,:)));

    end
end

%%%peaks%%%
for i=1:length(zcorrel);
    for h=1:length(zcorrel);
    peakzc(i,h)=max(zcorrel{i}(h,:));
    if peakzc(i,h)<confint{i}(h,2)
       peakzc(i,h)=0;
    end
    end
end

%%(normalise for grey scale on grid%%%%%%%%%%%%%%%%%%%%%%

peakn=(peakzc./max(max(peakzc))).*1000;


%HaLf Peak%%%%%%%%%%
for i=1:length(zcorrel);
    for h=1:length(zcorrel);
    HalfPeak(i,h)=peakzc(i,h)/2;
    end
end


HPW=zeros(length(zcorrel),length(zcorrel));
for i=1:length(zcorrel);
    for h=1:length(zcorrel);
        
       a=find(zcorrel{i}(h,:)>HalfPeak(i,h));
       if isempty(a)==0
       widths1(i,h)=a(1);
       widths2(i,h)=a(end);
       HPW(i,h)=(widths2(i,h)-widths1(i,h))+1;
       else
           HPW(i,h)=0;
       end
       
    end
end

filedate=datestr(now,'yyyymmdd_HHMMSS');
cmd=strcat('Export_Data\','ZHalfHeight_',filedate);
for i=1:length(signals)
    rows{i}=signals(i).name
end
    
xlswrite(cmd,peakzc,'ZPeak','B2')
xlswrite(cmd,rows,'ZPeak','B1')
xlswrite(cmd,rows','ZPeak','A2')
xlswrite(cmd,HPW,'ZHPW','B2')
xlswrite(cmd,rows,'ZHPW','B1')
xlswrite(cmd,rows','ZHPW','A2')
