|
10 | 10 | % Clear all the previous stuff |
11 | 11 | % clc; clear; |
12 | 12 | if ~ismac |
13 | | - close all; |
14 | | - clear Screen; |
| 13 | + close all; |
| 14 | + clear Screen; |
15 | 15 | end |
16 | 16 |
|
17 | 17 | % make sure we got access to all the required functions and inputs |
|
30 | 30 | % Safety loop: close the screen if code crashes |
31 | 31 | try |
32 | 32 |
|
33 | | - %% Init the experiment |
34 | | - [cfg] = initPTB(cfg); |
| 33 | + %% Init the experiment |
| 34 | + [cfg] = initPTB(cfg); |
35 | 35 |
|
36 | | - % % Convert some values from degrees to pixels |
37 | | - % cfg = deg2Pix('diameterAperture', cfg, cfg); |
38 | | - % expParameters = deg2Pix('dotSize', expParameters, cfg); |
| 36 | + % % Convert some values from degrees to pixels |
| 37 | + % cfg = deg2Pix('diameterAperture', cfg, cfg); |
| 38 | + % expParameters = deg2Pix('dotSize', expParameters, cfg); |
39 | 39 |
|
40 | 40 |
|
41 | | - [el] = eyeTracker('Calibration', cfg, expParameters); |
| 41 | + [el] = eyeTracker('Calibration', cfg, expParameters); |
42 | 42 |
|
43 | | - % % % REFACTOR THIS FUNCTION |
44 | | - [expParameters] = expDesign(expParameters); |
45 | | - % % % |
| 43 | + % % % REFACTOR THIS FUNCTION |
| 44 | + [expParameters] = expDesign(expParameters); |
| 45 | + % % % |
46 | 46 |
|
47 | | - % Prepare for the output logfiles with all |
48 | | - logFile = saveEventsFile('open', expParameters, [], ... |
49 | | - 'direction', 'speed', 'target', 'event', 'block'); |
| 47 | + % Prepare for the output logfiles with all |
| 48 | + logFile = saveEventsFile('open', expParameters, [], ... |
| 49 | + 'direction', 'speed', 'target', 'event', 'block'); |
50 | 50 |
|
51 | | - % % % REFACTOR THIS FUNCTION |
52 | | - [soundData, freq] = loadAudioFiles(SubjName); |
53 | | - phandle = PsychPortAudio('Open',[],[],1,freq,2); |
54 | | - % % % |
| 51 | + % % % REFACTOR THIS FUNCTION |
| 52 | + [soundData, freq] = loadAudioFiles(SubjName); |
| 53 | + phandle = PsychPortAudio('Open',[],[],1,freq,2); |
| 54 | + % % % |
55 | 55 |
|
56 | | - % Prepare for fixation Cross |
57 | | - if expParameters.Task1 |
| 56 | + % Prepare for fixation Cross |
| 57 | + if expParameters.Task1 |
58 | 58 |
|
59 | | - cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ... |
60 | | - + expParameters.xDisplacementFixCross; |
| 59 | + cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ... |
| 60 | + + expParameters.xDisplacementFixCross; |
61 | 61 |
|
62 | | - cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ... |
63 | | - + expParameters.yDisplacementFixCross; |
| 62 | + cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ... |
| 63 | + + expParameters.yDisplacementFixCross; |
64 | 64 |
|
65 | | - cfg.allCoords = [cfg.xCoords; cfg.yCoords]; |
| 65 | + cfg.allCoords = [cfg.xCoords; cfg.yCoords]; |
66 | 66 |
|
67 | | - end |
| 67 | + end |
68 | 68 |
|
69 | | - % Wait for space key to be pressed |
70 | | - pressSpace4me |
| 69 | + % Wait for space key to be pressed |
| 70 | + pressSpace4me |
71 | 71 |
|
72 | | - % prepare the KbQueue to collect responses |
73 | | - getResponse('init', cfg, expParameters, 1); |
74 | | - getResponse('start', cfg, expParameters, 1); |
| 72 | + % prepare the KbQueue to collect responses |
| 73 | + getResponse('init', cfg, expParameters, 1); |
| 74 | + getResponse('start', cfg, expParameters, 1); |
75 | 75 |
|
76 | | - % Show instructions |
77 | | - if expParameters.Task1 |
78 | | - DrawFormattedText(cfg.win,expParameters.TaskInstruction,... |
79 | | - 'center', 'center', cfg.textColor); |
80 | | - Screen('Flip', cfg.win); |
81 | | - end |
| 76 | + % Show instructions |
| 77 | + if expParameters.Task1 |
| 78 | + DrawFormattedText(cfg.win,expParameters.TaskInstruction,... |
| 79 | + 'center', 'center', cfg.textColor); |
| 80 | + Screen('Flip', cfg.win); |
| 81 | + end |
82 | 82 |
|
83 | | - % Wait for Trigger from Scanner |
84 | | - wait4Trigger(cfg) |
| 83 | + % Wait for Trigger from Scanner |
| 84 | + wait4Trigger(cfg) |
85 | 85 |
|
86 | | - % Show the fixation cross |
87 | | - if expParameters.Task1 |
88 | | - drawFixationCross(cfg, expParameters, expParameters.fixationCrossColor) |
89 | | - Screen('Flip',cfg.win); |
90 | | - end |
| 86 | + % Show the fixation cross |
| 87 | + if expParameters.Task1 |
| 88 | + drawFixationCross(cfg, expParameters, expParameters.fixationCrossColor) |
| 89 | + Screen('Flip',cfg.win); |
| 90 | + end |
91 | 91 |
|
92 | | - %% Experiment Start |
93 | | - cfg.experimentStart = GetSecs; |
| 92 | + %% Experiment Start |
| 93 | + cfg.experimentStart = GetSecs; |
94 | 94 |
|
95 | | - WaitSecs(expParameters.onsetDelay); |
| 95 | + WaitSecs(expParameters.onsetDelay); |
96 | 96 |
|
97 | | - %% For Each Block |
| 97 | + %% For Each Block |
98 | 98 |
|
99 | | - stopEverything = 0; |
| 99 | + stopEverything = 0; |
100 | 100 |
|
101 | | - for iBlock = 1:expParameters.numBlocks |
| 101 | + for iBlock = 1:expParameters.numBlocks |
102 | 102 |
|
103 | | - if stopEverything |
104 | | - break; |
105 | | - end |
| 103 | + if stopEverything |
| 104 | + break; |
| 105 | + end |
106 | 106 |
|
107 | | - fprintf('\n - Running Block %.0f \n',iBlock) |
| 107 | + fprintf('\n - Running Block %.0f \n',iBlock) |
108 | 108 |
|
109 | | - eyeTracker('StartRecording', cfg, expParameters); |
| 109 | + eyeTracker('StartRecording', cfg, expParameters); |
110 | 110 |
|
111 | | - % For each event in the block |
112 | | - for iEvent = 1:expParameters.numEventsPerBlock |
| 111 | + % For each event in the block |
| 112 | + for iEvent = 1:expParameters.numEventsPerBlock |
113 | 113 |
|
114 | 114 |
|
115 | | - % Check for experiment abortion from operator |
116 | | - [keyIsDown, ~, keyCode] = KbCheck(cfg.keyboard); |
117 | | - if keyIsDown && keyCode(KbName(cfg.escapeKey)) |
118 | | - stopEverything = 1; |
119 | | - warning('OK let us get out of here') |
120 | | - break; |
121 | | - end |
| 115 | + % Check for experiment abortion from operator |
| 116 | + [keyIsDown, ~, keyCode] = KbCheck(cfg.keyboard); |
| 117 | + if keyIsDown && keyCode(KbName(cfg.escapeKey)) |
| 118 | + stopEverything = 1; |
| 119 | + warning('OK let us get out of here') |
| 120 | + break; |
| 121 | + end |
122 | 122 |
|
123 | 123 |
|
124 | | - % set direction, speed of that event and if it is a target |
125 | | - thisEvent.trial_type = 'dummy'; |
126 | | - thisEvent.direction = expParameters.designDirections(iBlock,iEvent); |
127 | | - thisEvent.speed = expParameters.designSpeeds(iBlock,iEvent); |
128 | | - thisEvent.target = expParameters.designFixationTargets(iBlock,iEvent); |
| 124 | + % set direction, speed of that event and if it is a target |
| 125 | + thisEvent.trial_type = 'dummy'; |
| 126 | + thisEvent.direction = expParameters.designDirections(iBlock,iEvent); |
| 127 | + thisEvent.speed = expParameters.designSpeeds(iBlock,iEvent); |
| 128 | + thisEvent.target = expParameters.designFixationTargets(iBlock,iEvent); |
129 | 129 |
|
130 | | - % play the sounds and collect onset and duration of the event |
131 | | - [onset, duration] = doAudMot(cfg, expParameters, thisEvent) |
| 130 | + % play the sounds and collect onset and duration of the event |
| 131 | + [onset, duration] = doAudMot(cfg, expParameters, thisEvent) |
132 | 132 |
|
133 | | - thisEvent.event = iEvent; |
134 | | - thisEvent.block = iBlock; |
135 | | - thisEvent.duration = duration; |
136 | | - thisEvent.onset = onset - cfg.experimentStart; |
| 133 | + thisEvent.event = iEvent; |
| 134 | + thisEvent.block = iBlock; |
| 135 | + thisEvent.duration = duration; |
| 136 | + thisEvent.onset = onset - cfg.experimentStart; |
137 | 137 |
|
| 138 | + % Save the events txt logfile |
| 139 | + % we save event by event so we clear this variable every loop |
| 140 | + thisEvent.eventLogFile = logFile.eventLogFile; |
138 | 141 |
|
| 142 | + saveEventsFile('save', expParameters, thisEvent, ... |
| 143 | + 'direction', 'speed', 'target', 'event', 'block'); |
139 | 144 |
|
| 145 | + clear thisEvent |
140 | 146 |
|
141 | 147 |
|
| 148 | + % collect the responses and appends to the event structure for |
| 149 | + % saving in the tsv file |
| 150 | + responseEvents = getResponse('check', cfg, expParameters); |
142 | 151 |
|
| 152 | + if ~isempty(responseEvents(1).onset) |
143 | 153 |
|
| 154 | + responseEvents.eventLogFile = logFile.eventLogFile; |
144 | 155 |
|
| 156 | + for iResp = 1:size(responseEvents, 1) |
| 157 | + responseEvents(iResp).onset = ... |
| 158 | + responseEvents(iResp).onset - cfg.experimentStart; |
| 159 | + responseEvents(iResp).target = expParameters.designFixationTargets(iBlock,iEvent); |
| 160 | + responseEvents(iResp).event = iEvent; |
| 161 | + responseEvents(iResp).block = iBlock; |
| 162 | + end |
145 | 163 |
|
| 164 | + saveEventsFile('save', expParameters, responseEvents, ... |
| 165 | + 'direction', 'speed', 'target', 'event', 'block'); |
| 166 | + end |
146 | 167 |
|
| 168 | + % wait for the inter-stimulus interval |
| 169 | + WaitSecs(expParameters.ISI); |
147 | 170 |
|
| 171 | + getResponse('flush', cfg, expParameters); |
148 | 172 |
|
| 173 | + end |
149 | 174 |
|
| 175 | + eyeTracker('StopRecordings', cfg, expParameters); |
150 | 176 |
|
| 177 | + WaitSecs(expParameters.IBI); |
151 | 178 |
|
| 179 | + end |
152 | 180 |
|
| 181 | + % End of the run for the BOLD to go down |
| 182 | + WaitSecs(expParameters.endDelay); |
153 | 183 |
|
| 184 | + % Close the logfiles |
| 185 | + saveEventsFile('close', expParameters, logFile); |
154 | 186 |
|
| 187 | + getResponse('stop', cfg, expParameters, 1); |
155 | 188 |
|
| 189 | + totalExperimentTime = GetSecs-cfg.experimentStart; |
156 | 190 |
|
| 191 | + eyeTracker('Shutdown', cfg, expParameters); |
157 | 192 |
|
| 193 | + % save the whole workspace |
| 194 | + matFile = fullfile(expParameters.outputDir, strrep(expParameters.fileName.events,'tsv', 'mat')); |
| 195 | + if IsOctave |
| 196 | + save(matFile, '-mat7-binary'); |
| 197 | + else |
| 198 | + save(matFile, '-v7.3'); |
| 199 | + end |
158 | 200 |
|
| 201 | + cleanUp() |
159 | 202 |
|
160 | 203 | catch |
161 | 204 |
|
|
0 commit comments