function validMask = ValidMaskGen(ecgSig, RPeaks_pruned, vid)

maskDiff = diff(vid);

validMask = vid;

if(sum(abs(maskDiff))>0)
    nid = find(maskDiff<0);
    pid = find(maskDiff>0);
    
    for i = 1:length(nid)
        stId = nid(i);
        endId = pid(i);
        mask = zeros(size(ecgSig));
        mask(stId:endId) = 1;
        maskedData = mask.*RPeaks_pruned;
        if(sum(maskedData)<2);
            validMask(stId:endId) = 1;
        end
    end
end





