function [QRS_result,correct_detected,detect_position,numb_pred, numb_ground, numb_diff]= on_off_QRS (QRS, window)

QRS_P = find (QRS(:,1)==1); % position of on/off QRS point in the predicted signal
QRS_G = find (QRS(:,2)==1); % position of on/off QRS point in the ground truth
QRS_result = zeros(length (QRS_P),length (window)); %correctly detected points  
detect_position = zeros(length (QRS_G),length (window));% detected position in the ground truth

for h = 1:length (window)
    exc = window (h);
    for i = 1:length (QRS_P) 
        for j = 1:length (QRS_G)

            check = sum (QRS_P (i) == ((QRS_G(j)-exc):(QRS_G(j)+exc)));

            if check == 1
               QRS_result(i,h) = 1; % in prediction
               detect_position (j,h)= detect_position (j,h)+1; % in ground truth
               break
            end
        end
    end
end

if sum(detect_position) == 0 % in cas bad morfologii
   detect_position= zeros (size (QRS_G));
end

correct_detected = sum (QRS_result);
QRS_result = [QRS_P, QRS_result];
detect_position = [QRS_G, detect_position];

numb_pred = length(QRS_P);
numb_ground = length(QRS_G);
numb_diff = length(QRS_P) - length(QRS_G); 

end

