-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmat2hdf5.m
54 lines (40 loc) · 1.79 KB
/
mat2hdf5.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
% Data root (laptop)
data_root = 'C:\DATA\vbshare\physionet_data'; % Starting path
datafolder = uigetdir(data_root, 'physioNet data folder') ;
data_root = datafolder;
%datafolder = 'C:\DATA\vbshare\bwekg_Data\physioNet\sample2017\validation';
% HDF5 file name
h5file = 'physio.h5';
h5path = [data_root, '\', h5file];
% Get the names of all data files
files = dir([datafolder, '\*.mat']);
fprintf(['Files found: ', num2str(length(files)), '\n']);
%% Load next record
fprintf('Processing files.\n')
for f = 1:length(files)
%f = 1; % Start with the first one
fname = files(f).name;
[p, rname, x] = fileparts(fname);
recordName = [datafolder, '\', rname];
[tm, signal, Fs, siginfo] = rdmat(recordName);
% Prepare ecg data to write in hdf5 file
ecgdata = [signal, transpose(tm)]; % Time and signal columns
size_ecgdata = size(ecgdata);
code = ['SIGNAL'; 'TIME_S'];
dpath_ecgdata = ['/', rname, '/ecgdata'];
% Write ecg data
h5create(h5path, dpath_ecgdata, [size_ecgdata(2), size_ecgdata(1)])
h5write(h5path, dpath_ecgdata, transpose(ecgdata))
% Write column names as attributes
h5writeatt(h5path, dpath_ecgdata, 'colnames', '[signal, time_s]')
h5writeatt(h5path, dpath_ecgdata, 'units', siginfo.Units)
h5writeatt(h5path, dpath_ecgdata, 'baseline', siginfo.Baseline)
h5writeatt(h5path, dpath_ecgdata, 'gain', siginfo.Gain)
h5writeatt(h5path, dpath_ecgdata, 'description', siginfo.Description)
h5writeatt(h5path, dpath_ecgdata, 'fmt', siginfo.fmt)
h5writeatt(h5path, dpath_ecgdata, 'sampling_frequency', Fs)
if (mod(f, 50) == 0)
% Show progress every 500 files
fprintf(['Completed: ', num2str(f), ' / ', num2str(length(files)), '\n'])
end
end