-
Notifications
You must be signed in to change notification settings - Fork 0
/
analize.m
279 lines (253 loc) · 8.05 KB
/
analize.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
% Jorge Rey Martinez 2021 version 2.0
% Inputs
% t = time array
% e = eye velocity array
% h = head velocity array
% s = Boolean, true if register is supresed VVOR false if VVOR
function analize(t,e,h,s)
%Draw figure considering screen size
scrsz = get(groot,'ScreenSize');
if s == 1
figure1 = figure('Name','VORS ANALYSIS','NumberTitle','off','Position',[5 50 scrsz(3)/1.01 scrsz(4)/1.2]);
else
figure1 = figure('Name','VVOR ANALYSIS','NumberTitle','off','Position',[5 50 scrsz(3)/1.01 scrsz(4)/1.2]);
end
figure(figure1);
%%%%%% Numerical data CALCULATIONS section %%%%%%%%%%%%
% Get Desacade eye data
if s == 1
desacE = medfilt1(e,35);
else
desacE = medfilt1(e,30);
end
%get positive/neagtive data
limit = size(t);
posH = [];
posE = [];
negH = [];
negE = [];
for n = 1:limit
if h(n) > 0
posH = vertcat(posH,h(n));
if desacE(n) > 0
posE = vertcat(posE,desacE(n));
else
posE = vertcat(posE,0);
end
end
if h(n) < 0
negH = vertcat(negH,h(n));
if desacE(n) < 0
negE = vertcat(negE,desacE(n));
else
negE = vertcat(negE,0);
end
end
end
prePosPeakE = mean(findpeaks(posE));
preNegPeakE = mean(findpeaks(abs(negE)));
if prePosPeakE > preNegPeakE
peakE = prePosPeakE;
peakH = mean(findpeaks(posH));
else
peakE = -preNegPeakE;
peakH = -mean(findpeaks(abs(negH)));
end
%AUC Gain
aucPosEye = trapz(posE);
aucPosHead = trapz(posH);
aucNegEye = trapz(negE);
aucNegHead = trapz(negH);
gainPos = (aucPosEye/aucPosHead);
gainNeg = (aucNegEye/aucNegHead);
%Eye Head Regression Gain
negB = negH\negE;
posB = posH\posE;
calcNegE = negB*negH;
calcPosE = posB*posH;
%Fourier based Gain calcullation algorithm
headThreshold = 20; % Set minimum head velocity for frequency analysis
[dataEyeR,dataEyeL,dataHeadR,dataHeadL] = splitTest(desacE,h,headThreshold);
[fHeadL,P1HeadL] = fourier(dataHeadL);
[fEyeL,P1EyeL] = fourier(dataEyeL);
[fHeadR,P1HeadR] = fourier(dataHeadR);
[fEyeR,P1EyeR] = fourier(dataEyeR);
[maxHeadPwrR,HeadPwrRIndex] = max(P1HeadR);
[maxHeadPwrL,HeadPwrLIndex] = max(P1HeadL);
maxHeadRFreq = fHeadR(HeadPwrRIndex);
maxHeadLFreq = fHeadL(HeadPwrLIndex);
[preMaxEyeRFreq,maxEyeRFreqIndex]=min(abs(fEyeR-maxHeadRFreq));
[preMaxEyeLFreq,maxEyeLFreqIndex]=min(abs(fEyeL-maxHeadLFreq));
maxEyeRFreq = fEyeR(maxEyeRFreqIndex);
maxEyeLFreq = fEyeL(maxEyeLFreqIndex);
maxEyeRPwr = P1EyeR(maxEyeRFreqIndex);
maxEyeLPwr = P1EyeL(maxEyeLFreqIndex);
leftFouGain = (maxEyeLPwr/maxHeadPwrL);
rightFouGain = (maxEyeRPwr/maxHeadPwrR);
%Analysis of head oscillations variability:
distanciaPicos = 60;
lHeadPeaks = findpeaks(posH,'MinPeakDistance',distanciaPicos);
rHeadPeaks = findpeaks(abs(negH),'MinPeakDistance',distanciaPicos);
velocityTreshold = 25;
lHeadInvalids = lHeadPeaks<velocityTreshold;
rHeadInvalids = rHeadPeaks<velocityTreshold;
lHeadPeaks(lHeadInvalids) = [];
rHeadPeaks(rHeadInvalids) = [];
[lPeakN, ~] = size(lHeadPeaks);
[rPeakN, ~] = size(rHeadPeaks);
[lPR,rPR,saccadePositions] = prScoreVVR(t,e,h,s);
%PR PLOT only available in VVOR tests
if s ~= 1
subplot(3,2,5)
plot(t,h,'b',t,e,'r','LineWidth',1.5)
prTitle = strcat('Saccade Recognition & PR Plot || ', ' LEFT PR:',num2str(lPR),', RIGHT PR: ',num2str(rPR));
title(prTitle)
xlabel('Time in samples')
ylabel('Velocity in deg/sec')
ylim([-400 +400])
%add saccade detection to plot
[sP,~,~] = find(t==saccadePositions);
hold on
plot(t(sP),e(sP),'ko')
hold off
legend ('Head velocity','Eye velocity','Detected Saccade')
end
%%%%% PLOTS SECTION %%%%%
%RAW plot
subplot(3,2,1)
plot(t,h,'b',t,e,'r','LineWidth',1.25)
title('Test Output - RAW data')
xlabel('Time in secs')
ylabel('Velocity in deg/sec')
ylim([-400 +400])
legend ('Head velocity','Eye velocity')
%Desaccaded plot
subplot(3,2,2)
plot(t,h,'b',t,desacE,'r','LineWidth',1.25)
AUCTitle = strcat('Test Output - Desaccaded data || ',' LEFT GAIN: ',num2str(gainPos),' - RIGHT GAIN: ',num2str(gainNeg));
title(AUCTitle)
xlabel('Time in secs')
ylabel('Velocity in deg/sec')
ylim([-400 +400])
legend ('Head velocity','Eye velocity')
%XY ploy & regresion line
subplot(3,2,6)
hold on
if isOctave
scatter(negH,negE,'c','.');
scatter(posH,posE,'b','.');
else
scatter(negH,negE,'.b');
scatter(posH,posE,'.','MarkerEdgeColor',[0 .7 .7]);
end
XYTitle = strcat('Head vs Eye plot - Desaccaded data ||',' LEFT GAIN: ',num2str(posB),' - RIGHT GAIN: ',num2str(negB));
title(XYTitle)
xlabel('Head Velocity in deg/sec')
ylabel('Eye Velocity in deg/sec')
plot(negH,calcNegE,posH,calcPosE,'LineWidth',5)
if s == 1
plot(negH,negH,'r',posH,posH,'r','LineWidth',1.5)
legend ('Negative data','Positive data','Negative regresion','Positive regresion','No Suppression line','Location','northwest')
else
plot(negH,negH,'g',posH,posH,'g','LineWidth',1.5)
legend ('Negative data','Positive data','Negative regresion','Positive regresion','Normality line','Location','northwest')
end
hold off
%axis square
%Fourier plot
subplot(3,2,3)
[fHead,P1Head] = fourier(h);
[fEye,P1Eye] = fourier(e);
[~,ixx] = max(P1Head);
maxFreqHeadFour = fHead(ixx);
hold on
stem(fHead,P1Head,'b');
fourierTitle = strcat('Single-Side Amplitude Spectrum of Head and Eye (RAW) || Head Freq(Hz): ',num2str(maxFreqHeadFour));
title(fourierTitle)
xlabel('f (Hz)')
ylabel('|P1(f)|')
xlim([0 5])
stem(fEye,P1Eye,'r');
legend('Head','Eye')
hold off
%Fourier gain plot
subplot(3,2,4)
axis off
hold on
plotBar = bar([maxHeadPwrL maxEyeLPwr;maxHeadPwrR maxEyeRPwr],'hist');
gainFtitle = strcat(['Fourier Gain || LEFT(1): ',num2str(leftFouGain),' - RIGHT(2): ',num2str(rightFouGain)]);
title(gainFtitle)
legend('Head','Eye','Location','eastoutside');
if ~isOctave
plotBar(1).FaceColor = 'b';
plotBar(2).FaceColor = 'r';
end
hold off
% For FourierGain debug purposes only (uncoment next section)
% fgFigure = figure;
% subplot(2,2,3)
% hold on
% stem(fHeadL,P1HeadL,'b');
% title('Single-Side Amplitude Spectrum of Head and Eye (Desaccaded) || LEFT')
% xlabel('f (Hz)')
% ylabel('|P1(f)|')
% xlim([0 5])
% stem(fEyeL,P1EyeL,'r');
% legend('Head','Eye')
% hold off
%
% subplot(2,2,4)
% hold on
% stem(fHeadR,P1HeadR,'b');
% title('Single-Side Amplitude Spectrum of Head and Eye (Desaccaded) || RIGHT')
% xlabel('f (Hz)')
% ylabel('|P1(f)|')
% xlim([0 5])
% stem(fEyeR,P1EyeR,'r');
% legend('Head','Eye')
% hold off
%
% subplot(2,2,1)
% hold on
% plot(dataHeadL,'b','LineWidth',1.25)
% plot(dataEyeL,'r','LineWidth',1.25)
% hold off
% title('Test Output - LEFT SIDE')
% xlabel('Samples')
% ylabel('Velocity in deg/sec')
% ylim([-400 +400])
% legend ('Head velocity','Eye velocity')
%
% subplot(2,2,2)
% hold on
% plot(dataHeadR,'b','LineWidth',1.25)
% plot(dataEyeR,'r','LineWidth',1.25)
% hold off
% title('Test Output - RIGHT SIDE')
% xlabel('Samples')
% ylabel('Velocity in deg/sec')
% ylim([-400 +400])
% legend ('Head velocity','Eye velocity')
%
% set(0, 'currentfigure', figure1);
%%%%%%%%%Output analysis results to text%%%%%%%%%%%%
resultG = strcat('GAIN RESULTS: ',' Left(area): ',num2str(gainPos),' Right(area): ',num2str(gainNeg),' || Left(slope): ',num2str(posB),' Right(slope): ',num2str(negB),' || Left(Fourier): ',num2str(leftFouGain),' Right(Fourier): ',num2str(rightFouGain),' || Head Max(º/s): ', num2str(peakH),' Eye Max: ',num2str(peakE));
if s~= 1
resultPR = strcat('PR RESULTS: ',' Left PR Score: ',num2str(lPR),' Right PR score: ',num2str(rPR),' || Left/Right head peaks > 25º/s: ',num2str(lPeakN),'/',num2str(rPeakN),' || Left/Right velocity SD of head peaks: ',num2str(std(lHeadPeaks)),'/',num2str(std(rHeadPeaks)));
else
resultPR = 'PR score is not available for VORS - supression - testing';
end
mTextBoxGain = uicontrol(figure1,'style','text');
mTextBoxPR = uicontrol(figure1,'style','text');
set(mTextBoxGain,'String',resultG);
set(mTextBoxGain,'FontSize',10);
set(mTextBoxGain,'HorizontalAlignment','left');
set(mTextBoxGain,'Position',[20 20 1300 25]);
set(mTextBoxPR,'String',resultPR);
set(mTextBoxPR,'FontSize',10);
set(mTextBoxPR,'HorizontalAlignment','left');
set(mTextBoxPR,'Position',[20 1 1600 25]);
set(figure1,'MenuBar','figure');
disp(resultG);
disp(resultPR);
end