-
Notifications
You must be signed in to change notification settings - Fork 2
/
makeTRD_imagery_rt.m
316 lines (267 loc) · 11.8 KB
/
makeTRD_imagery_rt.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
function makeTRD_imagery_rt(subjectID, sessionNumber)
%function makeTRDoldNew4(outputName)
%
%%CREATES THE FILE outputName.trd FOR AN EXPERIMENT IN WHICH
%%ALL PICTURES ARE SHOWN, ONE FOURTH OF THE PICTURES IS REPEATED ONCE
%%PARTICIPANT RESPONDS:
%"NEW"->LEFT MOUSE BUTTON
%"OLD"->RIGHT MOUSE BUTTON
%
%%EXAMPLE CALL:
%makeTRDoldNew4('oldNewRandomizedRepeat.trd')
%DURATIONS
%PLAY WITH DURATIONS
info.TR = 2;
info.refreshHz = 60;
info.leadInTimeSec = 1; %6*info.TR;
info.leadOutTimeSec = 12;
info.trialOnsetAsynchronySec = 4*info.TR;
%1. Trial structure: blocks, 5 types including fixation
%2. block sequences, odd and even runs
%3. Sound
%4. Imagery cues/instructions
%info.nRuns=4;
info.cueType = [1 2]; %Car or Person
info.nCueTypes = length(info.cueType); %=the number of conditions
info.nRepeat=16;
info.nPictures=20; %20; %the number of stimuli in each condition type, e.g. 10 people and 10 cars
%info.trialType = [1, 2]; %Perception vs. Imagery
%info.nTrialTypes = length(info.trialType);
info.perceptionPeople = 1:info.nPictures*info.nRepeat; %people pictures, condition 1
info.perceptionCars = 1+info.nPictures*info.nRepeat:info.nPictures*info.nRepeat*info.nCueTypes; %car pictures, condition 2
info.Pictures=[info.perceptionPeople; info.perceptionCars]; %the number of images in perception trials
info.AllPictures=numel(info.Pictures);
info.Stop = 3;
info.emptyPicture = info.AllPictures+1;
info.fixationPicture = info.AllPictures+2;
info.cuePerson = info.AllPictures+3;
info.cueCar = info.AllPictures+4;
info.cuePictures=[info.cuePerson info.cueCar];
%for the even runs
idx1=[1 2 3 4; 3 1 4 2; 2 4 1 3; 4 3 2 1; 1 2 3 4; 3 1 4 2; 2 4 1 3; 4 3 2 1];
idx2=[2 4 1 3; 4 3 2 1; 1 2 3 4; 3 1 4 2; 2 4 1 3; 4 3 2 1; 1 2 3 4; 3 1 4 2];
if mod(sessionNumber,2) == 0
info.blockIdx=idx2;
else
info.blockIdx=idx1;
end
%for the odd runs
%info.blockIdx=[2 4 1 3; 4 3 2 1; 1 2 3 4; 3 1 4 2];
% info.pictureDuration = [6, 48];
% info.emptyDuration=[30, 90];
% info.fixDuration=[30, 90];
info.fixDuration = 42;
info.cueDuration=120;
info.pictureDuration = 21;
info.emptyDuration = 21;
info.emptyScreenDuration = 210;
%info.LastEmptyDuration=120;
info.factorialStructure = [info.nRepeat info.nCueTypes]; %prime(l, n, r), soa(50, 100), mask(l, r)
info.factorNames = [' NumberOfRepetitions ', ' ConditionTypes '];
%HOW MANY TRIALS PER DESIGN CELL DO YOU WANT TO RUN?
%TrialDefinitions = makeTrialDefinitions(info);
TrialDefinitions = makeTrialDefinitions(info);
writeTrialDefinitions(TrialDefinitions, info, subjectID, sessionNumber)
%--------------------------------------------------------------------------
%SPLIT UP TRIALS IN 4 SETS
%--------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MOPS %%%%%%%%%%%%
%function TrialDefinitions = makeTrialDefinitions(info)
% picNum(counter) = ASF_encode([iWorm, iMirror], [info.nShapeLevels, info.nMirrorLevels]);
%info.factorialStructure = [...
% info.nShapeLevels,...
% info.nStimRotationLevels,...
% info.nTaskRotationLevels,...
% info.nTaskRotationDirectionLevels,...
% info.nTargetDifferentLevels];
function TrialDefinitions = makeTrialDefinitions(info)
TrialDefinitionsTemp=[];
for iRepeat = 1:info.nRepeat
for iCondition=1:info.nCueTypes
%sprintf('carorperson=%d', iCondition*iRepeat)
ThisTrial.code = ASF_encode( [iRepeat-1 iCondition-1], info.factorialStructure);
%sprintf('TrialType=%d', iTrialType)
ThisTrial.tOnset = 0;
ThisTrial.userDefined = info.Stop;
pages = [info.cuePictures(iCondition)];
durations=[info.cueDuration];
for p = 1:info.nPictures-3
pages=[pages, info.emptyPicture, info.emptyPicture];
durations=[durations, info.emptyDuration, info.pictureDuration];
end
pages = [pages, info.emptyPicture,info.fixationPicture];
durations=[durations, info.emptyDuration,info.emptyScreenDuration];
ThisTrial.pictures = pages;
ThisTrial.nPages = length(ThisTrial.pictures);
ThisTrial.durations=durations;
ThisTrial.startRTonPage = 2;
ThisTrial.endRTonPage = ThisTrial.nPages;
ThisTrial.correctResponse = 1;
%sprintf('addtoblock=%d', iTrial)
TrialDefinitionsTemp=[TrialDefinitionsTemp, ThisTrial];
end
end
% sprintf('Blocklength=%d', length(BlockTemp))
% BlockTemp=BlockTemp(idxtemp);
%
% LastTrial.code = 0;
% LastTrial.tOnset = 0;
% LastTrial.userDefined = 0;
% pages = [info.fixationPicture];
% durations=[info.fixDuration];
% for p = 1:info.nPictures
%
%
% pages=[pages, info.fixationPicture, info.fixationPicture];
% durations=[durations, info.emptyDuration, info.pictureDuration];
%
% end
%
% LastTrial.pictures = pages;
% LastTrial.nPages = length(ThisTrial.pictures);
% LastTrial.durations=durations;
% LastTrial.startRTonPage = 2;
% LastTrial.endRTonPage = ThisTrial.nPages;
% LastTrial.correctResponse = 0;
% %sprintf('addtoblock=%d', iTrial)
% BlockTemp = [BlockTemp, LastTrial];
%
%
%
%%%%%Randomiza trials
nTrials=length(TrialDefinitionsTemp);
TrialDefinitions(1).code=0;
TrialDefinitions(1).tOnset=0; %TrialDef(nTrials).tOnset+nTrials*info.leadInTimeSec;
TrialDefinitions(1).userDefined=0;
TrialDefinitions(1).pictures=[];
TrialDefinitions(1).nPages = length(TrialDefinitionsTemp(nTrials).pictures);
TrialDefinitions(1).pictures=repmat(info.fixationPicture, 1, TrialDefinitions(1).nPages);
TrialDefinitions(1).durations=repmat(16, 1, TrialDefinitions(1).nPages);
TrialDefinitions(1).startRTonPage = 2;
TrialDefinitions(1).endRTonPage = TrialDefinitions(1).nPages-1;
TrialDefinitions(1).correctResponse = 0;
%Randomize trials
trial_index=randperm(length(TrialDefinitionsTemp));
TrialDefinitionsTemp=TrialDefinitionsTemp(trial_index);
for trial = 1:nTrials
TrialDefinitions(trial+1)=TrialDefinitionsTemp(trial);
end
% nTrials = length(TrialDefinitions);
% TrialDefinitions(nTrials+1).code=0;
% TrialDefinitions(nTrials+1).tOnset=0; %TrialDef(nTrials).tOnset+nTrials*info.leadInTimeSec;
% TrialDefinitions(nTrials+1).pictures=TrialDefinitions(1).pictures;
% TrialDefinitions(nTrials+1).durations=TrialDefinitions(1).durations;
% %TrialDefinitions(nTrials+1).userDefined=0;
% TrialDefinitions(nTrials+1).nPages = length(TrialDefinitions(nTrials+1).pictures);
% TrialDefinitions(nTrials+1).startRTonPage = 2;
% TrialDefinitions(nTrials+1).endRTonPage = TrialDefinitions(nTrials+1).nPages-1;
% TrialDefinitions(nTrials+1).correctResponse = 0;
trialDuration=0;
for i = 1:length(TrialDefinitions)
if i==1
TrialDefinitions(i).tOnset = trialDuration + info.leadInTimeSec;
else
trialDuration=trialDuration+sum(TrialDefinitions(i-1).durations);
%TrialDefinitions(i).tOnset = (i-1)*16 + info.leadInTimeSec;
TrialDefinitions(i).tOnset = round(trialDuration/info.refreshHz) + (i-1)*info.leadInTimeSec;
end
end
% %--------------------------------------------------------------------------
% %function writeTrialDefinitions(TrialDefinitions, info, fileName)
% %WRITES FACTORIAL INFO AND ARRAY OF TRIAL DEFINITIONS TO A FILE
% %IF YOU DO NOT USE USER-SUPPLIED TRD-COLUMNS, THIS WORKS FOR ALL
% %EXPERIMENTS AND DOES NOT NEED TO BE CHANGED
% %--------------------------------------------------------------------------
% function writeTrialDefinitions(TrialDefinitions, info, fileName, Cfg)
% if isempty(fileName)
% fid = 1;
% else
% %THIS OPENS A TEXT FILE FOR WRITING
% fid = fopen(fileName, 'w');
% fprintf(1, 'Creating file %s ...', fileName);
% end
%
% %WRITE DESIGN INFO
% fprintf(fid, '%4d', info.factorialStructure );
%
% nTrials = length(TrialDefinitions);
% for iTrial = 1:nTrials
% nPages = length(TrialDefinitions(iTrial).pictures);
%
% %STORE TRIALDEFINITION IN FILE
% fprintf(fid, '\n'); %New line for new trial
% fprintf(fid, '%4d', TrialDefinitions(iTrial).code);
% fprintf(fid, '\t%7.3f', TrialDefinitions(iTrial).tOnset);
%
% fprintf(fid, '\t');
% fprintf(fid, '%4d ', TrialDefinitions(iTrial).userDefined);
% fprintf(fid, '\t');
%
% for iPage = 1:nPages
% %TWO ENTRIES PER PAGE: 1) Picture, 2) Duration
% fprintf(fid, '\t%4d %4d', TrialDefinitions(iTrial).pictures(iPage), TrialDefinitions(iTrial).durations(iPage));
% end
% fprintf(fid, '\t%4d', TrialDefinitions(iTrial).startRTonPage);
% fprintf(fid, ' %4d', TrialDefinitions(iTrial).endRTonPage);
% fprintf(fid, '\t%4d', TrialDefinitions(iTrial).correctResponse);
% %ADD A SECONDARY TASK
% if Cfg.addSecondaryTask
% writeSecondaryTask(Cfg, fid, TrialDefinitions(iTrial).tOnset, length(TrialDefinitions(iTrial).userDefined))
% end
%
% end
% if fid > 1
% fclose(fid);
% end
%
% fprintf(1, '\nDONE\n'); %JUST FOR THE COMMAND WINDOW
%
%
% %
% %
% % TrialDef = [TrialDef, TrialDefRepeat];
% % nTrials = length(TrialDef);
% %
% %
% % %RANDOMIZE HERE
% % idx = randperm(nTrials);
% % TrialDef = TrialDef(idx);
% %
% %
% % %NOW CHECK WHO HAS BEEN REPEATED
% % hasBeenShownAlready = zeros(nTrials, 1);
% % for iTrial = 1:nTrials
% % if(hasBeenShownAlready(TrialDef(iTrial).code))
% % TrialDef(iTrial).code = ASF_encode( [1, TrialDef(iTrial).code-1], Design.factorLevels);
% % TrialDef(iTrial).correctResponse = 3;
% % end
% % hasBeenShownAlready(TrialDef(iTrial).code) = 1;
% % end
function writeTrialDefinitions(TrialDefinitions, info, subjectID, sessionNumber)
trdName = sprintf('%s_Im-%d.trd', subjectID, sessionNumber);
%THIS OPENS A TEXT FILE FOR WRITING
fid = fopen(trdName, 'w');
%DESIGN
fprintf(fid, '%3d ', info.factorialStructure);
fprintf(fid, '%s ', info.factorNames(:));
for iTrial = 1:length(TrialDefinitions)
%STORE TRIALDEFINITION IN FILE
fprintf(fid, '\n'); %New line for new trial
fprintf(fid, '%4d', TrialDefinitions(iTrial).code);
fprintf(fid, '\t%4d', TrialDefinitions(iTrial).tOnset);
fprintf(fid, '\t%4d', TrialDefinitions(iTrial).userDefined);
for iPage = 1:TrialDefinitions(iTrial).nPages
%TWO ENTRIES PER PAGE: 1) Picture, 2) Duration
fprintf(fid, '\t%4d %4d', TrialDefinitions(iTrial).pictures(iPage), TrialDefinitions(iTrial).durations(iPage));
end
%ADD A DUMMY EMPTY PICTURE WITH DURATION OF 1 FRAME
fprintf(fid, '\t%4d %4d', info.emptyPicture, 1);
fprintf(fid, '\t%4d', TrialDefinitions(iTrial).startRTonPage);
fprintf(fid, '\t%4d', TrialDefinitions(iTrial).endRTonPage);
fprintf(fid, '\t%4d', TrialDefinitions(iTrial).correctResponse);
end
if fid > 1
fclose(fid);
end
fprintf(1, '\n'); %JUST FOR THE COMMAND WINDOW
%faccombination = ASF_decode([TrialDefinitions.code], info.factorialStructure);