-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathimCalibrateStimulus.m
More file actions
81 lines (69 loc) · 2.92 KB
/
imCalibrateStimulus.m
File metadata and controls
81 lines (69 loc) · 2.92 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
% make the target sequence
tgtSeq=mkStimSeqRand(nSymbs,nSeq,1,0);
% make the stimulus
%figure;
fig=figure(2);
set(fig,'Name','Imagined Movement','color',[0 0 0],'menubar','none','toolbar','none','doublebuffer','on');
set(fig,'Units','pixel');wSize=get(fig,'position');set(fig,'units','normalized');% win size in pixels
clf;
ax=axes('position',[0.025 0.025 .95 .95],'units','normalized','visible','off','box','off',...
'xtick',[],'xticklabelmode','manual','ytick',[],'yticklabelmode','manual',...
'color',[0 0 0],'DrawMode','fast','nextplot','replacechildren',...
'xlim',[-1.5 1.5],'ylim',[-1.5 1.5],'Ydir','normal');
stimPos=[]; h=[];
stimRadius=.5;
theta=linspace(0,pi,nSymbs); stimPos=[cos(theta);sin(theta)];
for hi=1:nSymbs;
h(hi)=rectangle('curvature',[1 1],'position',[stimPos(:,hi)-stimRadius/2;stimRadius*[1;1]],...
'facecolor',bgColor);
end;
% add symbol for the center of the screen
stimPos(:,nSymbs+1)=[0 0];
h(nSymbs+1)=rectangle('curvature',[1 1],'position',[stimPos(:,nSymbs+1)-stimRadius/4;stimRadius/2*[1;1]],...
'facecolor',bgColor);
set(gca,'visible','off');
% play the stimulus
% reset the cue and fixation point to indicate trial has finished
set(h(:),'facecolor',bgColor);
sendEvent('stimulus.training','start');
% Wait for key-press to being stimuli
t=text(mean(get(ax,'xlim')),mean(get(ax,'ylim')),imInstruct,'HorizontalAlignment','center','color',[0 1 0],...
'fontunits','pixel','FontSize',.05*wSize(4));
drawnow;
waitforbuttonpress;% wait for button press to continue
delete(t);
drawnow;
for si=1:nSeq;
if ( ~ishandle(fig) ) break; end;
sleepSec(intertrialDuration);
% show the screen to alert the subject to trial start
set(h(end),'facecolor',fixColor); % red fixation indicates trial about to start/baseline
drawnow;% expose; % N.B. needs a full drawnow for some reason
sendEvent('stimulus.baseline','start');
sleepSec(baselineDuration);
sendEvent('stimulus.baseline','end');
% show the target
fprintf('%d) tgt=%d : ',si,find(tgtSeq(:,si)>0));
set(h(tgtSeq(:,si)>0),'facecolor',tgtColor);
set(h(tgtSeq(:,si)<=0),'facecolor',bgColor);
set(h(end),'facecolor',[0 1 0]); % green fixation indicates trial running
sendEvent('stimulus.target',find(tgtSeq(:,si)>0));
drawnow;% expose; % N.B. needs a full drawnow for some reason
sendEvent('stimulus.trial','start');
% wait for trial end
sleepSec(trialDuration);
% reset the cue and fixation point to indicate trial has finished
set(h(:),'facecolor',bgColor);
drawnow;
sendEvent('stimulus.trial','end');
ftime=getwTime();
fprintf('\n');
end % sequences
% end training marker
sendEvent('stimulus.training','end');
% thanks message
if ( ishandle(fig) )
text(mean(get(ax,'xlim')),mean(get(ax,'ylim')),{'That ends the training phase.','Thanks for your patience'},'HorizontalAlignment','center',...
'color',[0 1 0],'fontunits','pixel','FontSize',.05*wSize(4));
pause(3);
end