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

File: <base>/sources/Henriques/codeMatlab/mmMissingValues.m (2,564 bytes)
% _________________________________________________________________________
% иииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииии
% PREDICTION OF ACUTE HYPOTENSIVE EPISODES USING NEURAL NETWORK MULTIMODELS
% _________________________________________________________________________
% иииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииии
%        Copyright (C) 2009 
%          : Jorge Henriques ...  <jh@dei.uc.pt>, 
%          : Teresa Rocha    ...  <teresa@sun.isec.pt>
%        This software is released under the terms of the GNU 
%        General Public License (http://www.gnu.org/copyleft/gpl.html)
% иииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииии
% mmMissingValues.m
%__________________________________________________________________________
% иииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииии
%  Deal with missing values
%       - Interpolation of missing values
%__________________________________________________________________________
% иииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииииии


function yout=mmMissingValues( data)
 
npoint=5;
TOL   =5;  % two consecutive measurements shuld be less than TOL


%------------------------------- for each signal
y=data; 
%----------------------
i99=find(y<=-49.99);
y(i99)=0.0;

if length(i99)>0
    if i99(end)>590 & i99(end)<595   %.. last values - sometime there are problems with missing values
         y(i99(end):end) = filtfilt( 0.2, [1 -0.8], y(i99(end):end) );
    end
end
i200=find(y>=199);
y(i200)=0.0; 

    
%----------------------
ydif=diff(y);
for i=2:length(ydif)
    if (abs(ydif(i))> TOL);
        y(i)=y(i-1);
    end
end

%----------------------
yaux=y;
N=length(y);
segmento=[];
i=1;
%.................................
while i<N
    if y(i)==0
        inicio=i;
        while y(i)==0 & i<N
            i=i+1;
        end
        fim=i;
        segmento=[segmento;inicio fim];
        %----------------------------------- interpolation
        idleft =max(1,inicio-npoint);
        idright=min(N,fim+npoint);
        yleft  =mean(y(idleft:inicio));
        yright =mean(y(fim:idright));
        p      = polyfit([inicio fim],[yleft yright],1);
        yaux(inicio:fim) = polyval( p, inicio:fim);

        % figure(1)
        % [inicio fim]
        % plot(1:length(y),y,'g',[inicio:fim],y(inicio:fim),'r.',[inicio:fim],yaux(inicio:fim),'b.')
        % pause
    end
    i=i+1;
end
yout=yaux;