Commit 52495071 authored by Meryem Ayse Yucel's avatar Meryem Ayse Yucel
Browse files

New function for preprocessing

"hmrR_PreprocessIntensity_Negative" function fixes negative values in intensity by either adding an offset to make all
% numbers positive (+eps)(option 1) or just set values <=0 to +eps (option
% 2)

hmrR_Intentsity2OD is now intact.
parent d233ccca
Loading
Loading
Loading
Loading
+0 −24
Original line number Diff line number Diff line
@@ -23,30 +23,6 @@ dod = DataClass().empty();
for ii=1:length(intensity)
    dod(ii) = DataClass();
    d = intensity(ii).GetDataTimeSeries();
    
    % Optional (user prompt): Adding dc offset if intensity (d) has negative values
    if ~isempty(d(d<=0))
        quest = {'Intensity signal has negative values. If you would like to add a dc offset, please click YES. If you would like to proceed with negative values, hit CANCEL.'};
        dlgtitle = 'Warning';
        btn1 = 'YES';
        btn2 = 'CANCEL';
        detbtn = btn1;
        answer = questdlg(quest,dlgtitle,btn1,btn2,detbtn)
        switch answer
            case 'YES'
                for j = 1:size(d,2)
                    foo = d(:,j);
                    if ~isempty(find(foo<0))
                        d(:,j) = foo + abs(min(foo));
                        foo = d(:,j);
                    end
                    if ~isempty(find(foo == 0))
                        d(:,j) = foo + min(foo(foo > 0));
                    end
                end
        end
    end
    
    dm = mean(abs(d),1);
    nTpts = size(d,1);
    dod(ii).SetTime(intensity(ii).GetTime());
+53 −0
Original line number Diff line number Diff line
% SYNTAX:
% intensity = hmrR_PreprocessIntensity_Negative( intensity )
%
% UI NAME:
% hmrR_PreprocessIntensity_Negative
%
% DESCRIPTION:
% Fix negative values in intensity by either adding an offset to make all
% numbers positive (+eps)(option 1) or just set values <=0 to +eps (option
% 2)
%
% INPUT:
% intensity - SNIRF data type where the d matrix is intensity
%
% OUTPUT:
% intensity - SNIRF data type where the d matrix is intensity
%
% USAGE OPTIONS:
% Intensity_to_Intensity: d = hmrR_PreprocessIntensity_Negative(data)
%
function d = hmrR_PreprocessIntensity_Negative( intensity )


for ii=1:length(intensity)
    d = intensity(ii).GetDataTimeSeries();
    
    if ~isempty(d(d<=0))
        quest = {'Intensity signal has negative values.'};
        dlgtitle = 'Warning';
        btn1 = 'OPTION1: Add a dc offset';
        btn2 = 'OPTION2: Set values <=0 to eps';
        btn3 = 'CANCEL';
        detbtn = btn3;
        answer = questdlg(quest,dlgtitle,btn1,btn2,btn3, detbtn);
        switch answer  
            case 'OPTION1: Add a dc offset'
                for j = 1:size(d,2)
                    foo = d(:,j);
                    if ~isempty(find(foo<0))
                        d(:,j) = foo + abs(min(foo)) + eps;
                    end
                end
            case 'OPTION2: Set values <=0 to eps'
                for j = 1:size(d,2)
                    foo = d(:,j);
                    if ~isempty(find(foo<0))
                        d(find(foo<=0),j) = eps;
                    end
                end
        end
    end
    intensity(ii).SetDataTimeSeries(d);
end