-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfnirsPlotWithBaselineDev.m
68 lines (50 loc) · 2.67 KB
/
fnirsPlotWithBaselineDev.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function fnirsPlotWithBaselineDev(time, HbO, HbR, titleString, con, avgBool, saveOption, subject, directory, folder)
% Authors: Ivy Hill, Iris Li
% Created: July 16th, 2024
% Last edited: Jul 27, 2024 by Iris
%% 1.0 Plots all HbR & HbO data + overlays avg value of each of HbO + HbR baseline
startIdx = find(time == time(and(time >= 0, time < max(diff(time))))); %Finds start index of data / end index of baseline
fig1 = figure('Visible', 'off'); hold on; grid on;
% baseline lines
HbOBaseline = yline(mean(HbO(1:(startIdx-1))), '-', 'Color', [200, 100, 50]/255, 'LineWidth', 1);
HbRBaseline = yline(mean(HbR(1:(startIdx-1))), '-', 'Color', [110, 240, 120]/255, 'LineWidth', 1);
% HbO + HbR values
if avgBool == true % preferred
lineHbO = plot(time(startIdx:end), mean(HbO(:, startIdx:end)), 'r');
lineHbR = plot(time(startIdx:end), mean(HbR(:, startIdx:end)), 'b');
elseif avgBool == false % test - not preferred
lineHbO = plot(time(startIdx:end), HbO(:, startIdx:end), 'r');
lineHbR = plot(time(startIdx:end), HbR(:, startIdx:end), 'b');
end
title(strcat("Entire ", con, " Session: ", titleString, " Hb Data & Baseline"));
legend([HbOBaseline, HbRBaseline, lineHbO(1), lineHbR(1)], {'HbO Baseline', 'HbR Baseline', 'HbO Trial Data (All Chans Avg)', 'HbR Trial Data (All Chans Avg)'}, 'Location', 'best');
xlabel('Time (s)');
ylabel('Relative Concentration (mmol/L)');
% save plots:
if saveOption == "save"
saveas(fig1, fullfile(directory, folder, strcat(subject, '_', con, '_entire_ses_', titleString, 'baseline_HbO-HbR.png')));
close(fig1);
else
set(fig1, 'Visible', 'on');
end
%% 2.0 Plot single values (horiz. lines) of the baselines and the means of HbO and HbR -- may not use
if titleString == "Filtered"
fig2 = figure('Visible', 'off'); hold on; grid on;
% baselines
baselineHbO = yline(mean(HbO(1:(startIdx-1))), '-', 'Color', [200, 100, 50]/255, 'LineWidth', 1);
baselineHbR = yline(mean(HbR(1:(startIdx-1))), '-', 'Color', [110, 240, 120]/255, 'LineWidth', 1);
% HbO and HbR
meanHbO = yline(mean(HbO(:, startIdx:end), 2), 'r');
meanHbR = yline(mean(HbR(:, startIdx:end), 2), 'b');
title(strcat("Entire ", con, " Session: ", titleString, " Hb Data & Baseline"));
legend([baselineHbO, baselineHbR, meanHbO(1), meanHbR(1)], {'HbO Baseline', 'HbR Baseline', 'HbO Trial Data Mean Value', 'HbR Trial Data Mean Value'}, 'Location', 'best');
xlabel('Time (s)');
% save plots:
if saveOption == "save"
saveas(fig2, fullfile(directory, folder, strcat(subject, '_', con, '_entire_ses_', titleString, '_means-baselines_HbO-HbR.png')));
close(fig2);
else
set(fig2, 'Visible', 'on');
end
end
end