|
a |
|
b/data preprocessing_Matlab/loadEcgSig.m |
|
|
1 |
function [tm,ecgsig,ann,Fs,sizeEcgSig,timeEcgSig] = loadEcgSig(Name) |
|
|
2 |
% USAGE: [tm,ecgsig,ann,Fs,sizeEcgSig,timeEcgSig] = loadEcgSig('../data/200m') |
|
|
3 |
% This function reads a pair of files (RECORDm.mat and RECORDm.info) generated |
|
|
4 |
% by 'wfdb2mat' from a PhysioBank record, baseline-corrects and scales the time |
|
|
5 |
% series contained in the .mat file, returning time, amplitude and frequency. |
|
|
6 |
% The baseline-corrected and scaled time series are the rows of matrix 'val', and each |
|
|
7 |
% column contains simultaneous samples of each time series. |
|
|
8 |
% 'wfdb2mat' is part of the open-source WFDB Software Package available at |
|
|
9 |
% http://physionet.org/physiotools/wfdb.shtml |
|
|
10 |
% If you have installed a working copy of 'wfdb2mat', run a shell command |
|
|
11 |
% such as wfdb2mat -r 100s -f 0 -t 10 >100sm.info |
|
|
12 |
% to create a pair of files ('100sm.mat', '100sm.info') that can be read |
|
|
13 |
% by this function. |
|
|
14 |
% The files needed by this function can also be produced by the |
|
|
15 |
% PhysioBank ATM, at http://physionet.org/cgi-bin/ATM |
|
|
16 |
|
|
|
17 |
% Adapted from |
|
|
18 |
% loadEcgSignal.m O. Abdala 16 March 2009 |
|
|
19 |
% James Hislop 27 January 2014 version 1.1 |
|
|
20 |
|
|
|
21 |
% Last version |
|
|
22 |
% loadEcgSignal.m D. Kawasaki 15 June 2017 |
|
|
23 |
% Davi Kawasaki 15 June 2017 version 1.0 |
|
|
24 |
|
|
|
25 |
infoName = strcat(Name, '.info'); |
|
|
26 |
matName = strcat(Name, '.mat'); |
|
|
27 |
load(matName); |
|
|
28 |
ecgsig = val; |
|
|
29 |
fid = fopen(infoName, 'rt'); |
|
|
30 |
fgetl(fid); |
|
|
31 |
fgetl(fid); |
|
|
32 |
fgetl(fid); |
|
|
33 |
[freqint] = sscanf(fgetl(fid), 'Sampling frequency: %f Hz Sampling interval: %f sec'); |
|
|
34 |
Fs = freqint(1); |
|
|
35 |
interval = freqint(2); |
|
|
36 |
fgetl(fid); |
|
|
37 |
|
|
|
38 |
for i = 1:size(ecgsig, 1) |
|
|
39 |
[row(i), signal(i), gain(i), base(i), units(i)]=strread(fgetl(fid),'%d%s%f%f%s','delimiter','\t'); |
|
|
40 |
end |
|
|
41 |
|
|
|
42 |
fclose(fid); |
|
|
43 |
ecgsig(ecgsig==-32768) = NaN; |
|
|
44 |
|
|
|
45 |
for i = 1:size(ecgsig, 1) |
|
|
46 |
ecgsig(i, :) = (ecgsig(i, :) - base(i)) / gain(i); |
|
|
47 |
end |
|
|
48 |
N = size(ecgsig, 2); |
|
|
49 |
tm1 = 1/Fs:1/Fs:N/Fs; |
|
|
50 |
tm = (1:size(ecgsig, 2)) * interval; |
|
|
51 |
sizeEcgSig = size(ecgsig, 2); |
|
|
52 |
timeEcgSig = sizeEcgSig*interval; |
|
|
53 |
%plot(tm', val'); |
|
|
54 |
|
|
|
55 |
%for i = 1:length(signal) |
|
|
56 |
% labels{i} = strcat(signal{i}, ' (', units{i}, ')'); |
|
|
57 |
%end |
|
|
58 |
|
|
|
59 |
%legend(labels); |
|
|
60 |
%xlabel('Time (sec)'); |
|
|
61 |
% grid on |
|
|
62 |
|
|
|
63 |
% load annotations |
|
|
64 |
|
|
|
65 |
annotationName = strcat(Name, '.txt'); |
|
|
66 |
fid = fopen(annotationName, 'rt'); |
|
|
67 |
% was annotationsEcg = textscan(fid, '%d:%f %d %*c %*d %*d %*d %s', 'HeaderLines', 1, 'CollectOutput', 1); |
|
|
68 |
ann = textscan(fid, '%d:%f %d %c %d %d %d %s', 'HeaderLines', 1, 'CollectOutput', 1); |
|
|
69 |
fclose(fid); |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
end |