function [goodbeats,badbeats,outliers] = AnnotationConversion(annotations)
% [goodbeats,badbeats,outliers] = AnnotationConversion(annotations)
%
%   OVERVIEW:   Convert annotations to a logical array, with all Normal
%               beats (labeled "N") returning as 1 and abnormal beats (not
%               labeled "N") returning as 0.
%
%   INPUT:      annotations - a charactor array containing the annotations
%               of heart beats, generated by GE MARS and then read by
%               read_qrs.m
%
%   OUTPUT:     all outputs are returned in cell array format
%               goodbeats - "N" beats
%               badbeats  - the logical inverse of goodbeats
%               outliers  - an array of points to be discarded when
%                           pre-processing the RR interval data. 
%                           This includes not only  bad beats, but the
%                           beats immediately following bad beats
%
%   DEPENDENCIES & LIBRARIES:
%       HRV_toolbox https://github.com/cliffordlab/hrv_toolbox
%       WFDB Matlab toolbox https://github.com/ikarosilva/wfdb-app-toolbox
%       WFDB Toolbox https://physionet.org/physiotools/wfdb.shtml
%	REPO:       
%       https://github.com/cliffordlab/PhysioNet-Cardiovascular-Signal-Toolbox
%   ORIGINAL SOURCE AND AUTHORS:     
%       Main script written by Adriana N. Vest
%       Dependent scripts written by various authors 
%       (see functions for details)       
%	COPYRIGHT (C) 2016 
%   LICENSE:    
%       This software is offered freely and without warranty under 
%       the GNU (v3 or later) public license. See license file for
%       more information
%%
goodbeats= strcmp(cellstr(annotations),'N');   % find good beats
badbeats = ~goodbeats;                 % badbeats is logical inverse of  
                                       % good beats
outliers = false(length(badbeats),1);  % initialize vector to be use to 
                                       % eliminate bad beats

% removing beats after non-N beats 
for i = 1:length(badbeats)
    if badbeats(i)
        outliers(i) = 1;
        outliers(i+1) = 1;
    end
        
end

% remove extra points that may have been introduced at the end of the file
if (length(outliers) > length(badbeats)) 
    z = length(outliers);
    outliers(z) = [];
end

end % end function