function [classifyResult,QRS,ecg,AFEv,RR,qrs_amp_raw,QRSa,ATEv,OrgIdx,OriginCount,IrrEv,PACEv] = challengeECGpp(ecg,QRS)
classifyResult = 0; % default output normal rhythm
fs=300;
[PPlocs,QQlocs,RRlocs,SSlocs,TTlocs,UUlocs,PPvals,QQvals,RRvals,SSvals,TTvals,UUvals,PRinterval,QRSinterval,QTinterval,meanBeats,TTPlocs,TQinterval]=findPQRSTintervalsNewA(ecg,QRS);
x=ecg;
vecc=[];
xx=zeros(length(x),1);
for k=1:length(PPlocs)-1
    xq=PPlocs(k):PPlocs(k+1)-1;
    xz=[PPlocs(k),PPlocs(k+1)-1];
    v=[meanBeats(k),meanBeats(k+1)];
    vq = interp1(xz,v,xq,'linear');
    vecc=[vecc,vq];
end
xx(PPlocs(1):PPlocs(1)-1+length(vecc))=vecc;
% mean(xx)
zz=x-xx;
ecg=zz;
[QRS,diffo]=findBestQRSnewPD(ecg);
% QRS11=findBestQRSnew(ecg);
% QRS11
QRS(QRS>length(ecg))=[];
if isempty(QRS)==0
    qrs_amp_raw=ecg(QRS);
else
    qrs_amp_raw=0;
end
QRSa=QRS;
AFEv=0;OriginCount=0;IrrEv=0;PACEv=0;
ATEv=0;OrgIdx=0;
% length(QRS)
if length(QRS)<6
    RR=diff(QRS')/fs;
    AFEv =0;ATEv=0;OrgIdx=0;
    IrrEv=0;PACEv=0;OriginCount=0;
else
    RR=diff(QRS')/fs;
    [AFEv,ATEv,OrgIdx,OriginCount,IrrEv,PACEv] = comput_AFEv(RR);
    if AFEv>1
        classifyResult = 1;
    end
end