-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotEyeMovementResults.m
135 lines (119 loc) · 5.53 KB
/
plotEyeMovementResults.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function plotEyeMovementResults(time_in_sec_for_plot, V_proc, H_proc, V_det_der, H_det_der, blinks, sacc_vertical, sacc_horizontal, label_sig_ver_sacc, label_sig_hor_sacc, label_sig, thresh_blinks, thresh_sacc_ver, thresh_sacc_hor)
% Plot the results of eye movement analysis
% Inputs:
% time_in_sec_for_plot: Time vector in seconds
% V_proc, H_proc: Vertical and horizontal eye position signals
% V_det_der, H_det_der: Vertical and horizontal velocity signals
% blinks: Matrix of blink start and end indices
% sacc_vertical, sacc_horizontal: Matrices of saccade start and end indices
% label_sig_ver_sacc, label_sig_hor_sacc: Labeled signals for vertical and horizontal movements
% label_sig: Combined labeled signal
% thresh_blinks, thresh_sacc_ver, thresh_sacc_hor: Thresholds for blinks and saccades
% Input validation
if ~isvector(time_in_sec_for_plot) || ~isvector(V_proc) || ~isvector(H_proc) || ...
~isvector(V_det_der) || ~isvector(H_det_der) || ~isvector(label_sig_ver_sacc) || ...
~isvector(label_sig_hor_sacc) || ~isvector(label_sig)
error('Time, signal, derivative, and label inputs must be vectors');
end
if ~ismatrix(blinks) || ~ismatrix(sacc_vertical) || ~ismatrix(sacc_horizontal)
error('blinks, sacc_vertical, and sacc_horizontal must be matrices');
end
if ~isscalar(thresh_blinks) || ~isscalar(thresh_sacc_ver) || ~isscalar(thresh_sacc_hor)
error('Threshold inputs must be scalars');
end
% Figure 1: Vertical signal with blinks, saccades, fixations, label signal, and derivative
figure('Name', 'Vertical Eye Movements', 'NumberTitle', 'off', 'Position', [100, 100, 1200, 800]);
% Vertical signal plot
subplot(3,1,1);
plot(time_in_sec_for_plot, V_proc, 'k', 'DisplayName', 'Signal');
hold on;
% Plot blinks
blinks_plotted = false;
for i = 1:size(blinks, 1)
if ~blinks_plotted
plot(time_in_sec_for_plot(blinks(i,1):blinks(i,3)), V_proc(blinks(i,1):blinks(i,3)), 'r', 'LineWidth', 1, 'DisplayName', 'Blinks');
blinks_plotted = true;
else
plot(time_in_sec_for_plot(blinks(i,1):blinks(i,3)), V_proc(blinks(i,1):blinks(i,3)), 'r', 'LineWidth', 1, 'HandleVisibility', 'off');
end
end
% Plot vertical saccades
saccades_plotted = false;
for i = 1:size(sacc_vertical, 1)
if ~saccades_plotted
plot(time_in_sec_for_plot(sacc_vertical(i,1):sacc_vertical(i,2)), V_proc(sacc_vertical(i,1):sacc_vertical(i,2)), 'g', 'LineWidth', 1, 'DisplayName', 'Saccades');
saccades_plotted = true;
else
plot(time_in_sec_for_plot(sacc_vertical(i,1):sacc_vertical(i,2)), V_proc(sacc_vertical(i,1):sacc_vertical(i,2)), 'g', 'LineWidth', 1, 'HandleVisibility', 'off');
end
end
% Plot blink threshold
yline(thresh_blinks, 'r--', 'DisplayName', 'Blink Threshold');
xlabel('Time (s)');
ylabel('Vertical position');
title('Vertical Eye Movements');
legend('Location', 'best');
% Vertical derivative plot
subplot(3,1,2);
plot(time_in_sec_for_plot(1:end-1), V_det_der, 'k');
hold on;
yline(thresh_sacc_ver, 'g--');
yline(-thresh_sacc_ver, 'g--');
xlabel('Time (s)');
ylabel('Vertical velocity');
title('Vertical Eye Movement Derivative');
legend('Derivative', 'Saccade Threshold');
% Vertical label signal plot
subplot(3,1,3);
plot(time_in_sec_for_plot, label_sig_ver_sacc);
xlabel('Time (s)');
ylabel('Label');
title('Vertical Label Signal');
ylim([0 4]);
yticks(0:3);
yticklabels({'Undefined (0)', 'Fixation (1)', 'Saccade (2)', 'Blink (3)'});
% Figure 2: Horizontal signal with saccades, fixations, label signal, and derivative
figure('Name', 'Horizontal Eye Movements', 'NumberTitle', 'off', 'Position', [100, 100, 1200, 800]);
% Horizontal signal plot
subplot(3,1,1);
plot(time_in_sec_for_plot, H_proc, 'k');
hold on;
% Plot horizontal saccades
for i = 1:size(sacc_horizontal, 1)
x = [time_in_sec_for_plot(sacc_horizontal(i,1)), time_in_sec_for_plot(sacc_horizontal(i,2))];
y = [H_proc(sacc_horizontal(i,1)), H_proc(sacc_horizontal(i,2))];
plot(x, y, 'g', 'LineWidth', 1);
end
xlabel('Time (s)');
ylabel('Horizontal position');
title('Horizontal Eye Movements');
legend('Signal', 'Saccades');
% Horizontal derivative plot
subplot(3,1,2);
plot(time_in_sec_for_plot(1:end-1), H_det_der, 'k');
hold on;
yline(thresh_sacc_hor, 'g--');
yline(-thresh_sacc_hor, 'g--');
xlabel('Time (s)');
ylabel('Horizontal velocity');
title('Horizontal Eye Movement Derivative');
legend('Derivative', 'Saccade Threshold');
% Horizontal label signal plot
subplot(3,1,3);
plot(time_in_sec_for_plot, label_sig_hor_sacc);
xlabel('Time (s)');
ylabel('Label');
title('Horizontal Label Signal');
ylim([0 3]);
yticks(0:2);
yticklabels({'Undefined (0)', 'Fixation (1)', 'Saccade (2)'});
% Figure 3: Combined label signal
figure('Name', 'Combined Eye Movement Labels', 'NumberTitle', 'off');
plot(time_in_sec_for_plot, label_sig);
xlabel('Time (s)');
ylabel('Label');
title('Combined Eye Movement Labels');
ylim([0 4]);
yticks(0:3);
yticklabels({'Undefined (0)', 'Fixation (1)', 'Saccade (2)', 'Blink (3)'});
end