function [PeakIndex,BPIndex]=ECGPeak(wave,input,Peakindex,differ,thrm,fs)
if(max(input)-min(input))>15&&max(input)<250 %ÓÐÑªÑ¹µÄÇé¿ö
    BPIndex=BP_test(input,fs);
     if length(BPIndex)<=20&&length(BPIndex)>3
        cobp=[];
        [BPIndex,cobp]=My_Template(BPIndex,input,15,20);
        lenbp=length(cobp);
        tempbp=find(cobp>=0.9);
        tbp=length(tempbp);
        Rebp=tbp/lenbp;
        rr_bp=diff(BPIndex);
        copeak=[];
        lenP=length(Peakindex);
        if lenP<=20&&lenP>2
            [Peakindex,copeak]=My_Template(Peakindex,wave,15,20);
            lenpeak=length(copeak);
            tempecg=find(copeak>=0.55);
            tpeak=length(tempecg);
            Repeak=tpeak/lenpeak;
            rr_ecg=diff(Peakindex);
            [~,best] = min([var(rr_bp) var(rr_ecg)]);
        else
            Repeak=0;
            best=1;
        end
        if Rebp>Repeak||best==1
            PeakIndex=datafusion(wave,BPIndex,differ,thrm);
         else
            BPIndex=[];
            PeakIndex=Peakindex;
        end
     else
         BPIndex=[];
         PeakIndex=Peakindex;
     end
else
     BPIndex=[];
     PeakIndex=Peakindex;
end    
end

          



    
    
    