function label = challenge(recordName)

label = 'N';

[tm,ecg,fsOrg,siginfo]=rdmat(recordName);

td = find(tm<=1);
fsOrg = length(td)-1;
fs = 300;

% === Get ECG signal ===
[ecgSig, ecgSig_org] = getECGsig_normalized(ecg, fsOrg);

[Rpeaks, ann_res, res] = getECG_Rpeaks(ecgSig);

[zI_ecg, zLoc_ecg, erId_ecg, errLoc_ecg] = err_zrs(res, 5);

vid = zLoc_ecg.*errLoc_ecg;
%% Mask correction
validMask = ValidMaskGen(ecgSig, Rpeaks, vid);
VM = validMask.*zLoc_ecg;
% %%
%% Check signal direction and morphology

lead_direction = getLeadDirection(ecgSig, ann_res);
ecgSig = lead_direction*ecgSig;

%     %% AFIB detection


%%  Other signal detection based on PVCs

[RpeaksPVC, PVCbeatVec] = locatePVCbeats(ecgSig, Rpeaks.*VM);

load PVC_mat.mat
dpval = 0;
testBeat = median(PVCbeatVec,2)/norm(median(PVCbeatVec,2));
if(length(testBeat)>0)
    dpV = testBeat'*PVC_mat;
    [dpval, dpind] = max(dpV);
    if(dpval>0.999)
        label = 'O';
        return
    end
    
end


if(sum(vid)<0.4*length(vid))
    label = '~'
    return
end


% %% Other signal detection based on QRS durtation

[ChunkBeatVecOTHR] = genOTHRchunks(ecgSig, Rpeaks, VM);
QRSwidthSig = zeros(size(ChunkBeatVecOTHR));
if(numel(ChunkBeatVecOTHR>0))
    [QRSwidthSig, QRSwidth] = genQRSwidth(ChunkBeatVecOTHR);
end
if(QRSwidth>19)
    if(QRSwidth>40)
        label = '~'
        return
    else
        label = 'O';
        return
    end
end

% TRpeaks = Rpeaks;%.*validMask;
% tachFil = ones(1500,1);
%
% RR_rateTach = conv(TRpeaks, tachFil, 'valid');
%
% RRmeanTach = mean(RR_rateTach);
%
% if(RRmeanTach>16)
%     label = 'O';
%     return
% end
%
% TachCheck = ones(size(RR_rateTach));
%
% TachCheck(RR_rateTach>8.5)= -1;
%
% if(sum(abs(diff(TachCheck)/2))>10)
%     isTach= 1;
% else
%     isTach = 0;
% end
% %% Regularity Check
%
% Reg = unique(RR_rateTach);
%
% if(length(Reg)<3)
%     Regularity = 1;
% else
%     Regularity = 0;
% end

%% Bradycardia

BRpeaks = Rpeaks;
if(numel(zI_ecg)>0)
    BRpeaks(zI_ecg) = 1;
end
bradFil = ones(1500,1);

RR_rateBrad = conv(BRpeaks, bradFil, 'valid');
BradCheck = ones(size(RR_rateBrad));
BradCheck(RR_rateBrad<3.3)= -1;

RRmeanBrad = mean(RR_rateBrad);

if(sum(abs(diff(BradCheck)/2))>5)
    isBrad= 1;
    label = 'O';
    return
else
    isBrad = 0;
end


TRpeaks = Rpeaks;%.*validMask;
tachFil = ones(1500,1);

RR_rateTach = conv(TRpeaks, tachFil, 'valid');


if(nnz(Rpeaks.*vid)<10)
    label = '~';
    return
end

 RpeaksVM = Rpeaks.*VM;
 %NC = 30;
 SC = 8;
 
 if(sum(RpeaksVM)<9)
    label = '~'
    return
end
  
    [ChunkStack] = genChunksTest(ecgSig, RpeaksVM, SC);
    
    if(numel(ChunkStack)==0)
        label = '~';
        return
    end
    load('Full_CNN_params_numFil_2_filDim_100.mat')
    
    [cost, grad, preds] = cnnCost_MC(opttheta,ChunkStack,[],numClasses,...
        filterDimX,filterDimY,numFilters,poolDim,'True');
    
    
    for id = 1:4
        tmp = find(preds==id);
        count(id) = length(tmp);
    end
    
    data = count'/length(preds);
    
    load('predLab.mat');
    pred_labels = predLab(data, ei, opt_params)
     
%     testLab = mode(preds);
%     
     lab = ['N', 'A', 'O', '~'];
     label = lab(pred_labels);


end
