-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaderEpochFeedbackSignals.m
More file actions
93 lines (80 loc) · 3.3 KB
/
readerEpochFeedbackSignals.m
File metadata and controls
93 lines (80 loc) · 3.3 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
function [testdata,testevents]=readerContFeedbackSignals(clsfr,varargin)
% apply classifier to data after the indicated events
%
% [testdata,testevents]=imContFeedbackSignals(clsfr,varargin)
%
% Inputs:
% clsfr -- [struct] a classifier structure as returned by train_ersp_clsfr
% Outputs:
% testdata -- [struct 1xN] data classifier was applied to in each epoch
% testevents -- [struct 1xN] event which triggered the classifier to be applied
% Options:
% buffhost, buffport, hdr
% startSet -- {2 x 1} cell array of {event.type event.value} to match to start getting data to
% apply the classifier to. ({'stimulus.target'})
% endType, endValue -- event type and value to match to stop giving feedback
% trlen_ms/samp -- [int] length of trial to apply classifier to ([])
% if empty, then = windowFn size used in the classifier training
opts=struct('buffhost','localhost','buffport',1972,'hdr',[],...
'startSet',{'stimulus.target'},...
'endType','stimulus.test','endValue','end','verb',0,...
'trlen_ms',[],'trlen_samp',[],...
'alpha',[],'timeout_ms',1000);
[opts,varargin]=parseOpts(opts,varargin);
trlen_samp=opts.trlen_samp;
if ( isempty(trlen_samp) )
trlen_samp=0;
if ( ~isempty(opts.trlen_ms) )
if(~isempty(opts.hdr))
fs=opts.hdr.fsample;
else
hdr=buffer('get_hdr',opts.buffhost,opts.buffport);
fs=hdr.fsample;
end;
trlen_samp = opts.trlen_ms /1000 * fs;
end
% ensure is at least a big as the welch window size!
if ( isfield(clsfr,'windowFn') ) % est from size welch window function
trlen_samp=max(trlen_samp,size(clsfr.windowFn,2));
end
end
testdata={};
testevents={}; %N.B. cell array to avoid expensive mem-realloc during execution loop
state=[];
endTest=false;
nepochs=0;
while ( ~endTest )
% wait for data to apply the classifier to
[data,devents,state]=buffer_waitData(opts.buffhost,opts.buffport,state,'startSet',opts.startSet,'trlen_samp',trlen_samp,'exitSet',{'data' {opts.endType}},'verb',opts.verb);
% process these events
for ei=1:numel(devents)
if ( matchEvents(devents(ei),opts.endType,opts.endValue) ) % end training
if ( opts.verb>0 )
fprintf('Got end feedback event\n');
end;
endTest=true;
elseif ( matchEvents(devents(ei),opts.startSet) ) % flash, apply the classifier
if ( opts.verb>0 )
fprintf('Processing event: %s',ev2str(devents(ei)));
end;
nepochs=nepochs+1;
if ( nargout>0 )
testdata{nepochs}=data(ei);
testevents{nepochs}=devents(ei);
end;
% apply classification pipeline to this events data
[f,fraw,p]=buffer_apply_ersp_clsfr(data(ei).buf,clsfr);
sendEvent('classifier.prediction',f,devents(ei).sample);
if ( opts.verb>0 )
fprintf('Sent classifier prediction = %s.\n',sprintf('%g ',f));
end;
elseif ( opts.verb>0 )
fprintf('Unmatched event : %s\n',ev2str(devents(ei)));
end;
end
end % devents
if( nargout>0 )
testdata=cat(1,testdata{:});
testevents=cat(1,testevents{:});
end;
end % feedback phase