Predicting Acute Hypotensive Episodes: The PhysioNet/Computing in Cardiology Challenge 2009 1.0.0

File: <base>/sources/Jousset/f_load_ABPs_test.m (3,463 bytes)
function [ABP, HR, P] = f_load_ABPs_test(record)
%/* f_load_ABPs_test.m
%         load numerical low resolution signals
%         Copyright (C) 2009  Florian Jousset <florian.jousset at epfl.ch>
%         This software is released under the terms of the GNU General
%         Public License (http://www.gnu.org/copyleft/gpl.html).
%      */
%  
% [ABP, HR, P] = F_LOAD_ABPS_TEST(RECORD, VARARGIN)
% 
% Assume the database is in a subfolder 'mimic2db' and that each record has
% its own folder named '1**an', '2**bn', etc...
%
% INPUT
%   record          record ID
%                   '201an' or '201bn' or 'a4****nb'
%
% OUTPUT
%   ABP.S           Systolic Arterial Blood Pressure
%   ABP.D           Diastolic Arterial Blood Pressure
%   ABP.M           Mean Arterial Blood Pressure
%   HR              Heart Rate
%   P               Pulse

%% Build file names
databasePath = [pwd '\mimic2db\'];
HeaderFileName = [databasePath record(1:4) '\' record '.hea'];
DataFileName = [databasePath record(1:4) '\' record '.dat'];

% Open Header File
fidHead = fopen(HeaderFileName,'r');
% Check
if fidHead == -1
    disp(['Error open file ' HeaderFileName]);
end
    
%% Load Header
for j=1:100
    tmp = fgets(fidHead);
    if tmp == -1
        break
    end
    infos{j,1} = tmp;
end
fclose(fidHead);

delimiter = find(isspace(infos{1}));
% Nb signals, first line, after the file name
Nb = str2num(infos{1}(delimiter(1)+1:delimiter(2)-1));

% Sampling Frequency
Fs = str2double(infos{1}(delimiter(2)+1:delimiter(3)-1));

% Length signals
L = str2num(infos{1}(delimiter(3)+1:delimiter(4)-1));

% gain and signal's labels
for j=1:Nb
    parenthesis = [];
    delimiter = find(isspace(infos{j+1}));
    slash = strfind(infos{j+1}, '/');
    parenthesis1 = strfind(infos{j+1}, '(');
    parenthesis2 = strfind(infos{j+1}, ')');
    if isempty(parenthesis1)
        gain(j) = str2double(infos{j+1}(delimiter(2)+1:slash-1));
        baseline(j) = 0;
    else
        gain(j) = str2double(infos{j+1}(delimiter(2)+1:parenthesis1-1));
        baseline(j) = str2double(infos{j+1}(parenthesis1+1:parenthesis2-1));
    end
    format(j) = str2double(infos{j+1}(delimiter(1)+1:delimiter(1)+2));
    label{j} = infos{j+1}(delimiter(8)+1:end);
    % remove any space in the label
    label{j}(isspace(label{j})) = [];
end

idMABP = [];
idSABP = [];
idDABP = [];
idHR = []; HR = []; % Heart Rate, not always present
idP = []; P = []; % Pulse, not always present
for j=1:Nb
    switch label{j}
        case 'ABPMean'
            idMABP = j;
        case 'ABPSys'
            idSABP = j;
        case 'ABPDias'
            idDABP = j;
        case 'HR'
            idHR = j;
        case 'PULSE'
            idP = j;
    end
end

%% LOAD DATA
% Open Data File if needed
fidData = fopen(DataFileName,'r');
% Check
if fidData == -1
    disp(['Error open file ' DataFileName]);    
end
% read the signals, 16 bits (usually) - not working with 212 format!
formatStr = ['int' num2str(format(1))];
data = fread(fidData, [Nb L], formatStr)';
% Close Data File
fclose(fidData);

% remove baseline and rescale
ABP.S = (data(:,idSABP)-baseline(idSABP))./gain(idSABP);
ABP.D = (data(:,idDABP)-baseline(idDABP))./gain(idDABP);
ABP.M = (data(:,idMABP)-baseline(idMABP))./gain(idMABP);
HR = (data(:,idHR)-baseline(idHR))./gain(idHR);
P = (data(:,idP)-baseline(idP)./gain(idP));

% set outliers to 0, min saturated
ABP.M(ABP.M<0) = 0;
ABP.S(ABP.S<0) = 0;
ABP.D(ABP.D<0) = 0;
HR(HR<0) = 0;
P(P<0) = 0;