-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathloadXmlAnnotations.m
56 lines (49 loc) · 2.48 KB
/
loadXmlAnnotations.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%LOADSHHSANNOTATIONS load annotations from a xml file. xml structure should follow
% shhs xml files. This is, events should be annotated following the structure
% CMPStudyConfig.ScoredEvents.ScoredEvent
% filename complete file name (with path)
% annotations struct with a field for each event type. Field names are the
% ones used in the xml files, without white spaces.
%% The code below is based on the methods described in the following reference(s):
%
% [1] - I. Fernández-Varela, D. Alvarez-Estevez, E. Hernández-Pereira, V. Moret-Bonillo,
% "A simple and robust method for the automatic scoring of EEG arousals in
% polysomnographic recordings", Computers in Biology and Medicine, vol. 87, pp. 77-86, 2017
%
% [2] - D. Alvarez-Estevez, I. Fernández-Varela, "Large-scale validation of an automatic EEG arousal detection
% algorithm using different heterogeneous databases", Sleep Medicine, vol. 57, pp. 6-14, 2019
%
% Copyright (C) 2017-2019 Isaac Fernández-Varela
% Copyright (C) 2017-2019 Diego Alvarez-Estevez
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%% You should have received a copy of the GNU General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
function [annotations, hypnogram] = loadXmlAnnotations(file)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
annotations = [];
xml = xml_parseany(file);
totalEvents = length(xml.ScoredEvents.ScoredEvent);
for i = 1:totalEvents
currentEvent = xml.ScoredEvents.ScoredEvent(i);
name = regexprep(currentEvent.Name, '[ ()]', '');
if isfield(annotations, name)
last = length(annotations.(name));
else
last = 0;
end
annotations.(name)(last + 1).start = currentEvent.Start;
annotations.(name)(last + 1).duration = currentEvent.Duration;
end
hypnogram = zeros(length(xml.SleepStages.SleepStage), 1);
for i = 1:length(xml.SleepStages.SleepStage)
hypnogram(i) = xml.SleepStages.SleepStage{i};
end
end