Commit 1e245ec3 authored by yileizheng-BU's avatar yileizheng-BU
Browse files

Add Example_RunFuncOffline

Add new folder Example_RunFuncOffline under UniTests, including example scripts of using functions offline and example snirf file
parent 69eeb4f0
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
function PlotData(t, y, hbType, channels)

% Plot always to 
hf = 5; 
try
    close(hf);
catch
end

% y = y*1e6;

figure(hf);
axes;
p = get(gcf, 'position');
set(gcf, 'position', [p(1), p(2), p(3)*1.3, p(4)]);
hold on;
for iHb = 1:length(hbType)
    for iCh = 1:length(channels)
        plot(t, y(:, hbType(iHb), channels(iCh)));
    end
end
xlim([min(t), max(t)]);
hold off;
+62 −0
Original line number Diff line number Diff line
function [y, t] = Raw_to_DeltaConc_Example(filename, hbType, channels)
%
%    Example 1:   Plot channel 1 delta HbO concentration, derived from
%                 acquisition file test.snirf
%
%       cd '<root folder>\Homer3\UnitTests\Example_RunFuncOffline'
%       Raw_to_DeltaConc_Example('./test.snirf');
%    
%    Example 2:   Plot channels 1 and 2 delta HbR concentration, derived 
%                 from acquisition file test.snirf
%
%       cd '<root folder>\Homer3\UnitTests\Example_RunFuncOffline'
%       Raw_to_DeltaConc_Example('./test.snirf', 2, [1,2]);
%    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse args 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Arg 1
[pname, fname] = fileparts(filename);

% Arg 2:  Hb type - {1 -> HbO,  2 -> HbR,  3 -> HbT}
if ~exist('hbType','var') || isempty(hbType)
    hbType   = 1;
end

% Arg 3: 
if ~exist('channels','var') || isempty(channels)
    channels = 1;
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load acquisition file 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
acquired = SnirfClass([pname, '/', fname, '.snirf']);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Call sequence of user functions to get from acquired data 
% to delta concentration 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dod = hmrR_Intensity2OD(acquired.data); 
dod = hmrR_BandpassFilt(dod, 0.01, 0.50);
dc  = hmrR_OD2Conc_new(dod, acquired.probe, [1,1]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract plot data from output of last function 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t = dc.time;
y = dc.GetDataTimeSeries('reshape');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PlotData(t, y, hbType, channels);

+71 −0
Original line number Diff line number Diff line
function [y, t] = Raw_to_HRF_Example(filename, hbType, channels)
%
%    Example 1:   Plot channel 1 HbO HRF, derived from acquisition 
%                 file test.snirf
%
%       cd '<root folder>\Homer3\UnitTests\Example_RunFuncOffline'
%       Raw_to_HRF_Example('./test.snirf');
%    
%    Example 2:   Plot channels 1 and 2 HbT HRF, derived from acquisition file test.snirf
%                 
%       cd '<root folder>\Homer3\UnitTests\Example_RunFuncOffline'
%       Raw_to_HRF_Example('./test.snirf', 3, [1,2]);
%    
%    Example 3:   Plot channel 2 HbO and HbR HRF, derived from acquisition
%                 file test.snirf
%
%       cd '<root folder>\Homer3\UnitTests\Example_RunFuncOffline'
%       Raw_to_HRF_Example('./test.snirf', [1,2], 2);
%    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse args 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arg 1
[pname, fname] = fileparts(filename);
if isempty(pname)
    pname = pwd;
end

% Arg 2:  Hb type - {1 -> HbO,  2 -> HbR,  3 -> HbT}
if ~exist('hbType','var') || isempty(hbType)
    hbType   = 1;
end

% Arg 3: 
if ~exist('channels','var') || isempty(channels)
    channels = 1;
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load acquisition file 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Acquired data (See SNIRF spec for list of acquired data parameters) 
acquired = SnirfClass([pname, '/', fname, '.snirf']);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% String together user functions to get from acquired data 
% to HRF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dod   = hmrR_Intensity2OD(acquired.data); 
dod   = hmrR_BandpassFilt(dod, 0.01, 0.50);
dc    = hmrR_OD2Conc_new(dod, acquired.probe, [1,1]);
dcAvg = hmrR_BlockAvg (dc, acquired.stim, [-2,20]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract plot data from output of last function 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t = dcAvg.time;
y = dcAvg.GetDataTimeSeries('reshape');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PlotData(t, y, hbType, channels);

+6.87 MiB

File added.

No diff preview for this file type.