-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinitialSetupEDFx.m
71 lines (60 loc) · 2.34 KB
/
initialSetupEDFx.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function initialSetupEDFx( varargin )
%initialSetupEDFx Convenience function to download all EDF and related data
% initialSetupEDFx(destination_dir) downloads EDF data and annotations
% from PhysioNet in the destination directory, converts the data to
% Matlab file formats and extracts the hypnogram from the annotations
% file.
% initialSetupEDFx(destination_dir, src_dir) copies all EDF and related
% data from the source test directory to the destination directory
% extracting the data and hypnogram files.
% initialSetupEDFx() downloads data from PhysioNet and uses the current
% directory as the destionation directory.
% Check if arguments entered by the user
if ~isempty(varargin)
% Check if more than one argument entered by the user
if length(varargin) > 2
error('Unknown arguments - the function takes in only two optional arguments')
elseif length(varargin) == 2
destination_dir = varargin{1};
if exist(destination_dir, 'dir') == 0
fprintf('Destination directory does not exist. Creating a new directory\n\n');
mkdir(destination_dir)
end
src_dir = varargin{2};
if exist(destination_dir, 'dir') == 0
error('Source directory with data does not exist. Please check the source path.')
end
else
% Create a directory if it doesn't exist
destination_dir = varargin{1};
if exist(destination_dir, 'dir') == 0
fprintf('Destination directory does not exist. Creating a new directory\n\n');
mkdir(destination_dir)
end
end
else
% Use current directory as the download directory
destination_dir = pwd;
end
addpath(pwd);
% Download EDFx Data
if length(varargin) == 2
downloadEDFxData(destination_dir, src_dir);
else
downloadEDFxData(destination_dir);
end
% Download hypnogram + annotations
if length(varargin) == 2
downloadEDFxAnnotations(destination_dir, src_dir);
else
downloadEDFxAnnotations(destination_dir);
end
% Convert xls Data to use for later
lights_off_times = convertXLSData(destination_dir);
% Convert EDFx Data To Matlab Format
test_dirs = dir(fullfile(destination_dir, '*S*'));
test_dirs = test_dirs([test_dirs.isdir]);
for i=1:length(test_dirs)
convertEDFxToMat(fullfile(destination_dir, test_dirs(i).name), lights_off_times(test_dirs(i).name));
end
end