-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunisensEcg2Csv4Kubios.m
75 lines (54 loc) · 1.95 KB
/
unisensEcg2Csv4Kubios.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
72
73
74
75
function unisensEcg2Csv4Kubios(path)
%unisensEcg2Csv4Kubios convert unisens dataset with an ecg entry to a csv file that can be imported by KubiosHRV
%
% Example:
% unisensEcg2Csv4Kubios('path\to\your\unisens\Dataset')
%
% The file kubios.csv will be added to the dataset folder
% Copyright 2018 movisens GmbH, Germany
addUnisensJar();
if nargin~=1
error('unisensTools:missingArugments','Wrong number of Arguments.\nUsage:\unisensEcg2Csv4Kubios(''path_to_unisens_bin_dataset\'') ');
end
BLOCK_SIZE=1000000;
TARGET_UNIT = 'mV';
%open unisens dataset
jUnisensFactory = org.unisens.UnisensFactoryBuilder.createFactory();
jUnisens = jUnisensFactory.createUnisens(path);
jEcgEntry = jUnisens.getEntry('ecg.bin');
if isempty(jEcgEntry)
jEcgEntry = jUnisens.getEntry('ecg.csv');
end
if isempty(jEcgEntry)
error('unisensTools:entryNotFound','Unisens dataset does not contain an ECG entry.');
end
kubiosCsvFile = [path filesep 'kubios.csv'];
dt=1.0/jEcgEntry.getSampleRate();
scalingFactor = unitPrefix2Factor(char(jEcgEntry.getUnit())) / unitPrefix2Factor(TARGET_UNIT);
if exist(kubiosCsvFile, 'file') == 2
delete(kubiosCsvFile);
end
fileId = fopen(kubiosCsvFile,'w');
fprintf(fileId,'t [ms]\tECG [mV]\n');
t=0;
position = 0;
total = jEcgEntry.getCount();
while (position < total)
if (total - position > BLOCK_SIZE)
count = BLOCK_SIZE;
else
count = total - position;
end
data = jEcgEntry.readScaled(position, count);
%build time column
tArray = t + (0:dt:dt*count);
for i=1:count
fprintf(fileId,'%.3f\t%.3f\n',tArray(i)*1000,data(i,1)*scalingFactor);
end
position = position + count;
t = t + dt*count;
end
fclose(fileId);
%unisens speichern
jUnisens.closeAll();
end