-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPAS_validate_EMG_responses2.m
More file actions
108 lines (87 loc) · 3.86 KB
/
PAS_validate_EMG_responses2.m
File metadata and controls
108 lines (87 loc) · 3.86 KB
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
function [valid_stims] = PAS_validate_EMG_responses2(all_evoked_EMGs, time_axis, baseline_mean, valid_stims, muscle_of_interest, tdt_struct)
%Plots individual trials of EMG responses and presents a space for user to enter a vector, indicating which trial to take out
figure;
%trialvect = true([size(all_evoked_EMGs,1),ch]);
set(gcf,'renderer','painters');
%Calculate the baseline standard deviation from the 16 values of
%baseline_mean prior to stimulation. Stays the same regardless of
%whether baseline was removed or not.
% baseline_m2SD = mean(baseline_mean) + 2*(std(baseline_mean,0,1));
breakflag = 0;
med1sd= median(baseline_mean)+1*std(baseline_mean);
trialvect = baseline_mean < med1sd;
% autoflagvector = trialvect;
% manualvector = nan(size(trialvect));
% notevector = cell(size(trialvect));
trialvect = and(valid_stims,trialvect);
for tr = 1:size(all_evoked_EMGs,1)
if trialvect(tr)
plot(time_axis,all_evoked_EMGs(tr,:),'b');
else
plot(time_axis,all_evoked_EMGs(tr,:),'r');
end
title(['stim number: ' num2str(tr)]);
BLSD = (baseline_mean(tr)-median(baseline_mean))/std(baseline_mean);
ChannelLabel = ['Ch ' sprintf('%d, %.2f SD',muscle_of_interest,BLSD)];
% dim = [.62 .5 .3 .3];
%annotation('textbox',dim,'String',ChannelLabel,'FitBoxToText','on');
legend(ChannelLabel);
% Construct a questdlg with three options
choice = MFquestdlg( [0.4, 0.3], 'Would you like to keep this trial?', ...
'Trial Validation', ...
'KEEP','DISCARD','AUTO/Break','KEEP');
switch choice
case 'KEEP'
selection = 'TRU';
sprintf('Trial %d KEPT', tr)
% manualvector(tr) = true;
% if autoflagvector(tr) ~= manualvector(tr)
% warning('DEVIANT DETECTED')
% x = inputdlg('Indicate why you deviated from autoflag','Trial Notes', [1 50]);
% if isempty(x) == 1
% notevector(tr,ch) = cellstr('NA');
% elseif isempty(x) == 0
% notevector(tr,ch) = x;
% end
% end
trialvect(tr) = true;
trialindex = sprintf('trial_%d',tr);
saveas(gcf, [pwd '\supervisedlearning\block_' tdt_struct.info.blockname '_' trialindex '_selection_' selection '_EMG.png']);
case 'DISCARD'
selection = 'FAL';
sprintf('Trial %d DISCARDED', tr)
% manualvector(tr) = false;
% if autoflagvector(tr,ch) ~= manualvector(tr)
% warning('DEVIANT DETECTED')
% x = inputdlg('Indicate why you deviated from autoflag','Trial Notes', [1 50]);
% if isempty(x) == 1
% notevector(tr,ch) = cellstr('NA');
% elseif isempty(x) == 0
% notevector(tr,ch) = x;
% end
% end
trialvect(tr) = false;
trialindex = sprintf('trial_%d',tr)
selection = selection
saveas(gcf, [pwd '\supervisedlearning\block_' tdt_struct.info.blockname '_' trialindex '_selection_' selection '_EMG.png']);
case 'AUTO/Break'
breakflag = 1;
break;
end
if breakflag == 1
break;
end
% prompt = {'Exclude this Trial?'};
% dlg_title = 'Trial Exclusion';
% num_lines = 1;
% defaultans = {''};
% params = inputdlg(prompt,dlg_title,num_lines,defaultans);
% excludethistrial = params{1};
end
warning('Trial Validation Applied!');
valid_stims = and(valid_stims,trialvect);
% trial_validation_summary = struct('autoflagvect', autoflagvector, ...
% 'manualvect', manualvector, ...
% 'notevect', {notevector});
% all_evoked_EMGs = all_evoked_EMGs(trialvect,:);
end