Skip to content

Commit 023447d

Browse files
authored
Merge pull request #28 from Remi-Gau/remi-refactor
refactor trigger and response collection
2 parents 7bc1a21 + 770003e commit 023447d

File tree

7 files changed

+55
-67
lines changed

7 files changed

+55
-67
lines changed

lib/CPP_BIDS

setParameters.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@
3434

3535
%% Experiment Design
3636

37-
% cfg.design.motionType = 'translation';
38-
% cfg.design.motionType = 'radial';
37+
% cfg.design.motionType = 'translation';
38+
% cfg.design.motionType = 'radial';
3939
cfg.design.motionType = 'translation';
4040
cfg.design.names = {'static'; 'motion'};
4141
cfg.design.nbRepetitions = 4;
4242
cfg.design.nbEventsPerBlock = 12; % DO NOT CHANGE
4343

4444
%% Timing
45-
45+
4646
% FOR 7T: if you want to create localizers on the fly, the following must be
4747
% multiples of the scanneryour sequence TR
48-
%
48+
%
4949
% IBI
5050
% block length = (cfg.eventDuration + cfg.ISI) * cfg.design.nbEventsPerBlock
5151

5252
% Time between blocs in secs
53-
cfg.IBI = 1.8*3; % 8;
53+
cfg.IBI = 1.8 * 3; % 8;
5454
% Time between events in secs
5555
cfg.ISI = 0.1;
5656
% Number of seconds before the motion stimuli are presented
@@ -59,7 +59,7 @@
5959
cfg.endDelay = .1;
6060

6161
cfg.eventDuration = 0.8; % second
62-
62+
6363
%% Visual Stimulation
6464

6565
% Speed in visual angles / second

subfun/doDotMo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
apertureTexture('draw', cfg, thisEvent);
4848

49-
% If this frame shows a target we change the color
49+
% If this frame shows a target we change the color of the cross
5050
thisFixation.fixation = cfg.fixation;
5151
thisFixation.screen = cfg.screen;
5252
if thisEvent.target(1) && GetSecs < (onset + cfg.target.duration)

subfun/expDesign.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
% Set variables here for a dummy test of this function
5959
if nargin < 1 || isempty(cfg)
60-
% cfg.design.motionType = 'translation';
60+
% cfg.design.motionType = 'translation';
6161
cfg.design.motionType = 'radial';
6262
cfg.design.names = {'static'; 'motion'};
6363
cfg.design.nbRepetitions = 4;
@@ -184,20 +184,20 @@
184184
end
185185

186186
function [MOTION_DIRECTIONS, STATIC_DIRECTIONS] = getDirectionBaseVectors(cfg)
187-
187+
188188
% CONSTANTS
189189
% Set directions for static and motion condition
190-
190+
191191
STATIC_DIRECTIONS = [-1 -1 -1 -1];
192-
192+
193193
switch cfg.design.motionType
194194
case 'translation'
195195
MOTION_DIRECTIONS = [0 90 180 270];
196196
case 'radial'
197197
STATIC_DIRECTIONS = [666 -666 666 -666];
198198
MOTION_DIRECTIONS = [666 -666 666 -666];
199-
end
200-
199+
end
200+
201201
end
202202

203203
function [nbBlocks, nbRepet, nbEventsBlock, maxTargBlock] = getInput(cfg)
@@ -271,7 +271,7 @@ function diplayDesign(cfg, displayFigs)
271271
title('Fixation Targets position distribution');
272272

273273
figure(2);
274-
274+
275275
[motionDirections] = getDirectionBaseVectors(cfg);
276276
motionDirections = unique(motionDirections);
277277

subfun/saveResponsesAndTriggers.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function saveResponsesAndTriggers(responseEvents, cfg, logFile, triggerString)
2+
3+
if isfield(responseEvents(1), 'onset') && ~isempty(responseEvents(1).onset)
4+
5+
for iResp = 1:size(responseEvents, 1)
6+
responseEvents(iResp).onset = ...
7+
responseEvents(iResp).onset - cfg.experimentStart;
8+
responseEvents(iResp).event = 'n/a';
9+
responseEvents(iResp).block = 'n/a';
10+
responseEvents(iResp).direction = 'n/a';
11+
responseEvents(iResp).speed = 'n/a';
12+
responseEvents(iResp).target = 'n/a';
13+
if strcmp(responseEvents(iResp).keyName, 't')
14+
responseEvents(iResp).trial_type = triggerString;
15+
end
16+
end
17+
18+
responseEvents(1).fileID = logFile.fileID;
19+
responseEvents(1).extraColumns = logFile.extraColumns;
20+
saveEventsFile('save', cfg, responseEvents);
21+
22+
end
23+
24+
end

visualLocTanslational.m

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
[cfg] = initPTB(cfg);
3535

3636
cfg.dot.matrixWidth = cfg.screen.winHeight;
37-
37+
3838
% Convert some values from degrees to pixels
3939
cfg.dot = degToPix('size', cfg.dot, cfg);
4040
cfg.dot = degToPix('speed', cfg.dot, cfg);
@@ -56,7 +56,7 @@
5656
% Prepare for the output logfiles with all
5757
logFile.extraColumns = cfg.extraColumns;
5858
logFile = saveEventsFile('open', cfg, logFile);
59-
59+
6060
% prepare textures
6161
cfg = apertureTexture('init', cfg);
6262
cfg = dotTexture('init', cfg);
@@ -67,14 +67,15 @@
6767

6868
% prepare the KbQueue to collect responses
6969
getResponse('init', cfg.keyboard.responseBox, cfg);
70-
getResponse('start', cfg.keyboard.responseBox);
7170

7271
% Wait for Trigger from Scanner
7372
waitForTrigger(cfg);
7473

7574
%% Experiment Start
7675
cfg = getExperimentStart(cfg);
7776

77+
getResponse('start', cfg.keyboard.responseBox);
78+
7879
WaitSecs(cfg.onsetDelay);
7980

8081
%% For Each Block
@@ -119,62 +120,25 @@
119120
% saving in the tsv file
120121
responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ...
121122
getOnlyPress);
122-
123-
if isfield(responseEvents(1), 'onset') && ~isempty(responseEvents(1).onset)
124-
125-
for iResp = 1:size(responseEvents, 1)
126-
responseEvents(iResp).onset = ...
127-
responseEvents(iResp).onset - cfg.experimentStart;
128-
responseEvents(iResp).event = 'n/a';
129-
responseEvents(iResp).block = 'n/a';
130-
responseEvents(iResp).direction = 'n/a';
131-
responseEvents(iResp).speed = 'n/a';
132-
responseEvents(iResp).target = 'n/a';
133-
if strcmp(responseEvents(iResp).keyName, 't')
134-
responseEvents(iResp).trial_type = 'trigger';
135-
end
136-
end
137-
138-
responseEvents(1).fileID = logFile.fileID;
139-
responseEvents(1).extraColumns = logFile.extraColumns;
140-
saveEventsFile('save', cfg, responseEvents);
141-
142-
end
143-
123+
124+
triggerString = ['trigger_' cfg.design.blockNames{iBlock}];
125+
saveResponsesAndTriggers(responseEvents, cfg, logFile, triggerString);
126+
144127
% wait for the inter-stimulus interval
145128
WaitSecs(cfg.ISI);
146129

147130
end
148-
131+
149132
eyeTracker('StopRecordings', cfg);
150-
133+
151134
WaitSecs(cfg.IBI);
152-
135+
153136
% trigger monitoring
154137
triggerEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ...
155138
getOnlyPress);
156-
157-
if isfield(triggerEvents(1), 'onset') && ~isempty(triggerEvents(1).onset)
158-
159-
for iResp = 1:size(triggerEvents, 1)
160-
triggerEvents(iResp).onset = ...
161-
triggerEvents(iResp).onset - cfg.experimentStart;
162-
triggerEvents(iResp).event = 'n/a';
163-
triggerEvents(iResp).block = 'n/a';
164-
triggerEvents(iResp).direction = 'n/a';
165-
triggerEvents(iResp).speed = 'n/a';
166-
triggerEvents(iResp).target = 'n/a';
167-
if strcmp(triggerEvents(iResp).keyName, 't')
168-
triggerEvents(iResp).trial_type = 'trigger-baseline';
169-
end
170-
end
171-
172-
triggerEvents(1).fileID = logFile.fileID;
173-
triggerEvents(1).extraColumns = logFile.extraColumns;
174-
saveEventsFile('save', cfg, triggerEvents);
175-
176-
end
177139

140+
triggerString = 'trigger_baseline';
141+
saveResponsesAndTriggers(triggerEvents, cfg, logFile, triggerString);
178142

179143
end
180144

@@ -190,8 +154,8 @@
190154
getResponse('release', cfg.keyboard.responseBox);
191155

192156
eyeTracker('Shutdown', cfg);
193-
194-
createBoldJson(cfg, cfg)
157+
158+
createBoldJson(cfg, cfg);
195159

196160
farewellScreen(cfg);
197161

0 commit comments

Comments
 (0)