Skip to content

Commit 946295a

Browse files
committed
add final part
1 parent 123ad4c commit 946295a

File tree

2 files changed

+118
-172
lines changed

2 files changed

+118
-172
lines changed

ALocalizer.m

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1 @@
11

2-
eventOnsets=zeros(numBlocks,numEventsPerBlock);
3-
eventEnds=zeros(numBlocks,numEventsPerBlock);
4-
eventDurations=zeros(numBlocks,numEventsPerBlock);
5-
6-
responsesPerBlock=zeros(numBlocks,1);6
7-
8-
playTime = zeros(numBlocks,1);
9-
10-
for blocks = 1:numBlocks
11-
12-
for iEvent = 1: numEventsPerBlock
13-
14-
15-
eventEnds(blocks,iEvent)=GetSecs-experimentStartTime;
16-
eventDurations(blocks,iEvent)=eventEnds(blocks,iEvent)-eventOnsets(blocks,iEvent);
17-
18-
WaitSecs(ISI);
19-
20-
end
21-
22-
responsesPerBlock (blocks,1) = responseCount ;
23-
24-
%% Get Block end and duration
25-
timeLogger.block(blocks).endTime = GetSecs - experimentStartTime; % Get the time for the block end
26-
timeLogger.block(blocks).length = timeLogger.block(blocks).endTime - timeLogger.block(blocks).startTime; %Get the block duration
27-
28-
%% Fixation cross and inter-block interval
29-
Screen('FillOval', w, uint8(white), fix_cord); % draw fixation dot (flip erases it)
30-
blank_onset=Screen('Flip', w);
31-
WaitSecs('UntilTime', blank_onset + ibi); % wait for the inter-block interval
32-
33-
end;
34-
35-
% At the end of the blocks wait ... secs before ending the experiment.
36-
Screen('FillOval', w, uint8(white), fix_cord); % draw fixation dot (flip erases it)
37-
blank_onset=Screen('Flip', w);
38-
WaitSecs('UntilTime', blank_onset + finalWait);
39-
40-
41-
%% Save the results ('names','onsets','ends','duration') of each block
42-
names = cell(length(timeLogger.block),1);
43-
onsets = zeros(length(timeLogger.block),1);
44-
ends = zeros(length(timeLogger.block),1);
45-
durations = zeros(length(timeLogger.block),1);
46-
47-
for i=1:length(timeLogger.block)
48-
names(i,1) = timeLogger.block(i).names;
49-
onsets(i,1) = timeLogger.block(i).startTime;
50-
ends(i,1) = timeLogger.block(i).endTime;
51-
durations(i,1) = timeLogger.block(i).length;
52-
end
53-
54-
%% KeyPresses and Times
55-
% for i=length(responseKey):-1:2 % responseKey gives a '1' in all frames where button was pressed, so one motor response = gives multiple consequitive '1' frames
56-
% if responseKey(i-1)~=0 % therefore, we need to cancel consequitive '1' frames after the first button press
57-
% responseKey(i)=0; % we loop through the responses and remove '1's that are not preceeded by a zero
58-
% responseTime(i)=0; % this way, we remove the additional 1s for the same button response
59-
% end % - The same concept for the responseTime
60-
% end
61-
%
62-
% for i=length(targetTime):-1:2 % The same concept as responseKey adn responseTime.
63-
% if targetTime(i-1)~=0 % Our Targets lasts 3 frames, to remove the TargetTime for the 2nd and 3rd frame
64-
% targetTime(i)=0; % we remove targets that are preceeded by a non-zero value
65-
% end % that way, we have the time of the first frame only of the target
66-
% end
67-
%
68-
% responseKey = responseKey(responseKey > 0); % Remove zero elements from responseKey, responseTime, & targetTime
69-
% responseTime = responseTime(responseTime > 0);
70-
% targetTime = targetTime(targetTime > 0);
71-
72-
%% Shutdown Procedures
73-
ShowCursor;
74-
clear screen;
75-
myTotalSecs=GetSecs;
76-
Experiment_duration = myTotalSecs - experimentStartTime;
77-
78-
%% Save a mat Log file
79-
% Onsets & durations are saved in seconds.
80-
save(['logFileFull_',SubjName,'.mat']);
81-
save(['logFile_',SubjName,'.mat'], 'names','onsets','durations','ends','targets','responseTime','responseKey','targetTime','Experiment_duration','playTime');
82-
83-
84-
%% FUNCTION
85-
% close Serial Port ---- VERY IMPORTANT NOT FORGET
86-
if strcmp(device,'Scanner')
87-
CloseSerialPort(SerPor);
88-
end
89-
90-
catch
91-
clear Screen;
92-
fprintf('Code was catched!')
93-
%% Close serial port of the scanner IF CRASH OF THE CODE
94-
if strcmp(Cfg.device,'Scanner')
95-
CloseSerialPort(Cfg.SerPor);
96-
end
97-
98-
end

audioLocTranslational.m

Lines changed: 118 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
% Clear all the previous stuff
1111
% clc; clear;
1212
if ~ismac
13-
close all;
14-
clear Screen;
13+
close all;
14+
clear Screen;
1515
end
1616

1717
% make sure we got access to all the required functions and inputs
@@ -30,132 +30,175 @@
3030
% Safety loop: close the screen if code crashes
3131
try
3232

33-
%% Init the experiment
34-
[cfg] = initPTB(cfg);
33+
%% Init the experiment
34+
[cfg] = initPTB(cfg);
3535

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);
3939

4040

41-
[el] = eyeTracker('Calibration', cfg, expParameters);
41+
[el] = eyeTracker('Calibration', cfg, expParameters);
4242

43-
% % % REFACTOR THIS FUNCTION
44-
[expParameters] = expDesign(expParameters);
45-
% % %
43+
% % % REFACTOR THIS FUNCTION
44+
[expParameters] = expDesign(expParameters);
45+
% % %
4646

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');
5050

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+
% % %
5555

56-
% Prepare for fixation Cross
57-
if expParameters.Task1
56+
% Prepare for fixation Cross
57+
if expParameters.Task1
5858

59-
cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ...
60-
+ expParameters.xDisplacementFixCross;
59+
cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ...
60+
+ expParameters.xDisplacementFixCross;
6161

62-
cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ...
63-
+ expParameters.yDisplacementFixCross;
62+
cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ...
63+
+ expParameters.yDisplacementFixCross;
6464

65-
cfg.allCoords = [cfg.xCoords; cfg.yCoords];
65+
cfg.allCoords = [cfg.xCoords; cfg.yCoords];
6666

67-
end
67+
end
6868

69-
% Wait for space key to be pressed
70-
pressSpace4me
69+
% Wait for space key to be pressed
70+
pressSpace4me
7171

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);
7575

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
8282

83-
% Wait for Trigger from Scanner
84-
wait4Trigger(cfg)
83+
% Wait for Trigger from Scanner
84+
wait4Trigger(cfg)
8585

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
9191

92-
%% Experiment Start
93-
cfg.experimentStart = GetSecs;
92+
%% Experiment Start
93+
cfg.experimentStart = GetSecs;
9494

95-
WaitSecs(expParameters.onsetDelay);
95+
WaitSecs(expParameters.onsetDelay);
9696

97-
%% For Each Block
97+
%% For Each Block
9898

99-
stopEverything = 0;
99+
stopEverything = 0;
100100

101-
for iBlock = 1:expParameters.numBlocks
101+
for iBlock = 1:expParameters.numBlocks
102102

103-
if stopEverything
104-
break;
105-
end
103+
if stopEverything
104+
break;
105+
end
106106

107-
fprintf('\n - Running Block %.0f \n',iBlock)
107+
fprintf('\n - Running Block %.0f \n',iBlock)
108108

109-
eyeTracker('StartRecording', cfg, expParameters);
109+
eyeTracker('StartRecording', cfg, expParameters);
110110

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
113113

114114

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
122122

123123

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);
129129

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)
132132

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;
137137

138+
% Save the events txt logfile
139+
% we save event by event so we clear this variable every loop
140+
thisEvent.eventLogFile = logFile.eventLogFile;
138141

142+
saveEventsFile('save', expParameters, thisEvent, ...
143+
'direction', 'speed', 'target', 'event', 'block');
139144

145+
clear thisEvent
140146

141147

148+
% collect the responses and appends to the event structure for
149+
% saving in the tsv file
150+
responseEvents = getResponse('check', cfg, expParameters);
142151

152+
if ~isempty(responseEvents(1).onset)
143153

154+
responseEvents.eventLogFile = logFile.eventLogFile;
144155

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
145163

164+
saveEventsFile('save', expParameters, responseEvents, ...
165+
'direction', 'speed', 'target', 'event', 'block');
166+
end
146167

168+
% wait for the inter-stimulus interval
169+
WaitSecs(expParameters.ISI);
147170

171+
getResponse('flush', cfg, expParameters);
148172

173+
end
149174

175+
eyeTracker('StopRecordings', cfg, expParameters);
150176

177+
WaitSecs(expParameters.IBI);
151178

179+
end
152180

181+
% End of the run for the BOLD to go down
182+
WaitSecs(expParameters.endDelay);
153183

184+
% Close the logfiles
185+
saveEventsFile('close', expParameters, logFile);
154186

187+
getResponse('stop', cfg, expParameters, 1);
155188

189+
totalExperimentTime = GetSecs-cfg.experimentStart;
156190

191+
eyeTracker('Shutdown', cfg, expParameters);
157192

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
158200

201+
cleanUp()
159202

160203
catch
161204

0 commit comments

Comments
 (0)