-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfindOffset_phantom.m
184 lines (142 loc) · 6.54 KB
/
findOffset_phantom.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
function [vertOffset,horiOffset] = findOffset_phantom(subject, session, debug)
%%%%%%%%%%%%%%%%%%%
% BASIC SETTINGS
%%%%%%%%%%%%%%%%%%%
%%%% resolution
if debug == 1
SetResolution(max(Screen('Screens')), 2880, 1800, 0); % laptop
else
SetResolution(max(Screen('Screens')),1024,768,60); % scanner
end
experiment.runNum = input('Run number :');
%%%% keyboards
[keyboardIndices, productNames, ~] = GetKeyboardIndices ;
deviceNumber = keyboardIndices(1);
%%%% input this at the beginning of the scan session for 7T
scSize.vertOffset = 0; % vertical offset from FindScreenSize.m
scSize.horiOffset = 0;
% scSize.screenDeg = 14; % pRF screen size
scSize.screenDegY = 8; %figSizeDeg;
scSize.screenDegX = 16; %figSizeDeg*3;%9; % pRF screen size
% scSize.centerDeg = 4; % center circle size in diameter
% scSize.surroundDeg = 12; % surround circle size in diameter
%%%% scales all of the stimuli in DVA to the screensize
params.screenWidth = 17; % in cm; laptop=27.5, office=43, 3Tb=19, 7T=17, miniHelm=39;
params.viewingDist = 48; % in cm; 3Tb/office=43, 7T=48, miniHelm=57;
params.fixSizeDeg = .5; % in degrees, the size of the biggest white dot in the fixation
params.littleFixDeg = params.fixSizeDeg* .5;% proportion of the fixSizeDeg occupied by the smaller black dot
params.outerFixPixels = 2; % in pixels, the black ring around fixation
params.backgroundColor = [128 128 128]; % color
params.boxColor = params.backgroundColor * .7;
%%%% response listening - so we don't read in scanner triggers!
responseKeys = zeros(1,256);
responseKeys(KbName('1!'))=1; % button box 1
responseKeys(KbName('2@'))=1; % button box 2
responseKeys(KbName('3#'))=1; % button box 3
%%%%%%%%%%%%%%%%
% OPEN SCREEN
%%%%%%%%%%%%%%%%
HideCursor;
Priority(9); % highest priority
%%%% open screen
Screen('Preference', 'SkipSyncTests', 1);
screen=max(Screen('Screens'));
[win, rect]=Screen('OpenWindow',screen,180,[],[],[],[],[],kPsychNeed32BPCFloat);
Screen(win, 'TextSize', 32);
% xc = rect(3)/2;
% yc = rect(4)/2;
%Load the gamma table of the specified screen
load 7T_Sam.mat
Screen('LoadNormalizedGammaTable', win, linearizedCLUT);
%%%% scale the stims for the screen
params.ppd = pi* rect(3) / (atan(params.screenWidth/params.viewingDist/2)) / 360;
params.fixSize = round(params.fixSizeDeg*params.ppd);
params.littleFix = round(params.littleFixDeg*params.ppd);
scSize.screenX = scSize.screenDegX*params.ppd;
scSize.screenY = scSize.screenDegY*params.ppd;
%%%% Fixation dot
% params.yFixOffset = 3*params.ppd;
KbQueueCreate(deviceNumber,responseKeys);
%%%% find center Y
Screen('FillRect',win,params.backgroundColor)
text = 'Find CENTER Y. 1 = Up, 2 = Down, 3 = Accept\n\nPress any button to start';
width = RectWidth(Screen('TextBounds',win,text));
DrawFormattedText(win, text, 'center', 'center');
Screen(win, 'Flip', 0);
WaitSecs(1); KbPressWait; KbQueueFlush();
%%%%%%%%
% RUN
%%%%%%%%
while 1
xS = rect(3)/2+scSize.horiOffset;
yS = rect(4)/2+scSize.vertOffset;
xc = rect(3)/2+scSize.horiOffset;
yc = rect(4)/2+scSize.vertOffset; %+params.yFixOffset;
KbQueueStart();
%%%% draw screen square
Screen('FillRect', win,params.boxColor, [xS-round(scSize.screenX/2) yS-round(scSize.screenY/2) xS+round(scSize.screenX/2) yS+round(scSize.screenY/2)]);
%%%% draw fixation
Screen('FillOval', win,[0 0 0], [xc-round(params.fixSize/2+params.outerFixPixels ) yc-round(params.fixSize/2+params.outerFixPixels ) xc+round(params.fixSize/2+params.outerFixPixels ) yc+round(params.fixSize/2+params.outerFixPixels )]); % black fixation ring
Screen('FillOval', win,[255 255 255], [xc-round(params.fixSize/2) yc-round(params.fixSize/2) xc+round(params.fixSize/2) yc+round(params.fixSize/2)]); % white fixation ring
Screen('FillOval', win,[0 0 0], [xc-round(params.littleFix/2) yc-round(params.littleFix/2) xc+round(params.littleFix/2) yc+round(params.littleFix/2)]); % black fixation dot
%%%% FLIP
Screen(win, 'Flip', 0);
%%%% check for responses
[pressed, firstPress]= KbQueueCheck();
if find(firstPress,1) == KbName('1!')
scSize.vertOffset = scSize.vertOffset - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('2@')
scSize.vertOffset = scSize.vertOffset + 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('3#')
break;
KbQueueFlush();
end
end
vertOffset = scSize.vertOffset;
Screen('FillRect',win,params.backgroundColor)
text = 'Find CENTER X. 1 = Left, 2 = Right, 3 = Accept\n\nPress any button to start';
width = RectWidth(Screen('TextBounds',win,text));
DrawFormattedText(win, text, 'center', 'center');
Screen(win, 'Flip', 0);
WaitSecs(1); KbPressWait; KbQueueFlush();
while 1
xc = rect(3)/2+scSize.horiOffset;
yc = rect(4)/2+scSize.vertOffset;
KbQueueStart();
%%%% draw screen square
Screen('FillRect', win,params.boxColor, [xc-round(scSize.screenX/2) yc-round(scSize.screenY/2) xc+round(scSize.screenX/2) yc+round(scSize.screenY/2)]);
%%%% draw fixation
Screen('FillOval', win,[0 0 0], [xc-round(params.fixSize/2+params.outerFixPixels ) yc-round(params.fixSize/2+params.outerFixPixels ) xc+round(params.fixSize/2+params.outerFixPixels ) yc+round(params.fixSize/2+params.outerFixPixels )]); % black fixation ring
Screen('FillOval', win,[255 255 255], [xc-round(params.fixSize/2) yc-round(params.fixSize/2) xc+round(params.fixSize/2) yc+round(params.fixSize/2)]); % white fixation ring
Screen('FillOval', win,[0 0 0], [xc-round(params.littleFix/2) yc-round(params.littleFix/2) xc+round(params.littleFix/2) yc+round(params.littleFix/2)]); % black fixation dot
%%%% FLIP
Screen(win, 'Flip', 0);
%%%% check for responses
[pressed, firstPress]= KbQueueCheck();
if find(firstPress,1) == KbName('1!')
scSize.horiOffset = scSize.horiOffset - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('2@')
scSize.horiOffset = scSize.horiOffset + 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('3#')
break;
KbQueueFlush();
end
end
horiOffset = scSize.horiOffset;
%%%%%%%%%%%%%%%%%%
% DONE! WRAP UP
%%%%%%%%%%%%%%%%%%
KbQueueRelease();
ShowCursor;
Screen('Close');
Screen('CloseAll');
% save
savedir = fullfile(pwd,'data',subject,session,'findOffset_figureGround');
if ~exist(savedir); mkdir(savedir); end
savename=fullfile(savedir, strcat(subject,'_screenSize.mat'));
save(savename,'scSize')
end