Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions audioLocTranslational.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
%% Auditory hMT localizer using translational motion in four directions
% (up- down- left and right-ward)

% Original Script Written by Sam Weiller to localize MT+/V5
% adapted by M.Rezk to localize MT/MST (Huk,2002)
% re-adapted by MarcoB and RemiG 2020
% by Mohamed Rezk 2018
% adapted by MarcoB and RemiG 2020

%%

getOnlyPress = 1;

more off;

% Clear all the previous stuff
% clc; clear;
Expand All @@ -12,13 +17,10 @@
clear Screen;
end

getOnlyPress = 1;

more off;

% make sure we got access to all the required functions and inputs
initEnv();

% set and load all the parameters to run the experiment
cfg = setParameters;
cfg = userInputs(cfg);
cfg = createFilename(cfg);
Expand All @@ -28,27 +30,30 @@
% Safety loop: close the screen if code crashes
try

% % % REFACTOR THIS FUNCTION
[cfg] = loadAudioFiles(cfg);

%% Init the experiment
[cfg] = initPTB(cfg);

% % Convert some values from degrees to pixels
% cfg = deg2Pix('diameterAperture', cfg, cfg);
% expParameters = deg2Pix('dotSize', expParameters, cfg);
% % % REFACTOR THIS FUNCTION % % %

[cfg] = loadAudioFiles(cfg);

% % % REFACTOR THIS FUNCTION % % %

[el] = eyeTracker('Calibration', cfg);

% % % REFACTOR THIS FUNCTION
% % % REFACTOR THIS FUNCTION % % %

[cfg] = expDesign(cfg);

% % % REFACTOR THIS FUNCTION % % %

% Prepare for the output logfiles with all
logFile = saveEventsFile('open', cfg, [], ...
'direction', 'speed', 'target', 'event', 'block');
logFile.extraColumns = cfg.extraColumns;
logFile = saveEventsFile('open', cfg, logFile);

% disp(cfg);
disp(cfg);

% Show experiment instruction
standByScreen(cfg);

% prepare the KbQueue to collect responses
Expand Down Expand Up @@ -79,25 +84,30 @@
checkAbort(cfg, cfg.keyboard.keyboard);

% set direction, speed of that event and if it is a target
thisEvent.trial_type = 'dummy';
thisEvent.direction = cfg.designDirections(iBlock, iEvent);
thisEvent.speed = cfg.designSpeeds(iBlock, iEvent);
thisEvent.target = cfg.designFixationTargets(iBlock, iEvent);
thisEvent.trial_type = cfg.design.blockNames{iBlock};
thisEvent.direction = cfg.design.directions(iBlock, iEvent);
% thisEvent.speed = cfg.design.speeds(iBlock, iEvent);
thisEvent.target = cfg.design.fixationTargets(iBlock, iEvent);

% % % REFACTOR THIS FUNCTION % % %

% play the sounds and collect onset and duration of the event
[onset, duration] = doAudMot(cfg, thisEvent, cfg.audio.pahandle);
[onset, duration] = doAudMot(cfg, thisEvent);

% % % REFACTOR THIS FUNCTION % % %

thisEvent.event = iEvent;
thisEvent.block = iBlock;
thisEvent.keyName = 'n/a';
thisEvent.duration = duration;
thisEvent.onset = onset - cfg.experimentStart;

% Save the events txt logfile
% we save event by event so we clear this variable every loop
thisEvent.fileID = logFile.fileID;
thisEvent.extraColumns = logFile.extraColumns;

saveEventsFile('save', cfg, thisEvent, ...
'direction', 'speed', 'target', 'event', 'block');
saveEventsFile('save', cfg, thisEvent);

clear thisEvent;

Expand All @@ -106,7 +116,7 @@
responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ...
getOnlyPress);

triggerString = ['trigger'];
triggerString = ['trigger_' cfg.design.blockNames{iBlock}];
saveResponsesAndTriggers(responseEvents, cfg, logFile, triggerString);

% wait for the inter-stimulus interval
Expand All @@ -118,28 +128,31 @@

WaitSecs(cfg.timing.IBI);

% trigger monitoring
triggerEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ...
getOnlyPress);

triggerString = 'trigger_baseline';
saveResponsesAndTriggers(triggerEvents, cfg, logFile, triggerString);

end

% End of the run for the BOLD to go down
WaitSecs(cfg.timing.endDelay);

cfg = getExperimentEnd(cfg);

% Close the logfiles
saveEventsFile('close', cfg, logFile);

getResponse('stop', cfg.keyboard.responseBox);
getResponse('release', cfg.keyboard.responseBox);

totalExperimentTime = GetSecs - cfg.experimentStart;

eyeTracker('Shutdown', cfg);

% save the whole workspace
matFile = fullfile(cfg.dir.output, strrep(cfg.fileName.events, 'tsv', 'mat'));
if IsOctave
save(matFile, '-mat7-binary');
else
save(matFile, '-v7.3');
end
createBoldJson(cfg, cfg);

farewellScreen(cfg);

cleanUp();

Expand Down
30 changes: 15 additions & 15 deletions subfun/expDesign.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
% matrix of the design
%
% Output:
% - ExpParameters.designBlockNames = cell array (nr_blocks, 1) with the
% - ExpParameters.design.blockNames = cell array (nr_blocks, 1) with the
% name for each block
%
% - ExpParameters.designDirections = array (nr_blocks, nbEventsPerBlock)
% - ExpParameters.design.directions = array (nr_blocks, nbEventsPerBlock)
% with the direction to present in a given block
% - 0 90 180 270 indicate the angle
% - -1 indicates static
%
%
% - ExpParameters.designFixationTargets = array (nr_blocks, nbEventsPerBlock)
% - ExpParameters.design.fixationTargets = array (nr_blocks, nbEventsPerBlock)
% showing for each event if it should be accompanied by a target
%

Expand All @@ -48,8 +48,8 @@

% Set variables here for a dummy test of this function
if nargin < 1 || isempty(cfg)
cfg.design.names = {'static', 'motion'};
cfg.design.nbRepetitions = 4;
cfg.design.names = {'static', 'motion'};
cfg.design.nbRepetitions = 4;
cfg.design.nbEventsPerBlock = 12;
cfg.target.maxNbPerBlock = 2;
end
Expand Down Expand Up @@ -93,14 +93,14 @@

%% Give the blocks the names with condition

cfg.designBlockNames = cell(nrBlocks, 1);
cfg.designDirections = zeros(nrBlocks, nbEventsPerBlock);
cfg.designFixationTargets = zeros(nrBlocks, nbEventsPerBlock);
cfg.design.blockNames = cell(nrBlocks, 1);
cfg.design.directions = zeros(nrBlocks, nbEventsPerBlock);
cfg.design.fixationTargets = zeros(nrBlocks, nbEventsPerBlock);

for iMotionBlock = 1:nbRepetitions

cfg.designDirections(motionIndex(iMotionBlock), :) = Shuffle(motionDirections);
cfg.designDirections(staticIndex(iMotionBlock), :) = Shuffle(staticDirections);
cfg.design.directions(motionIndex(iMotionBlock), :) = Shuffle(motionDirections);
cfg.design.directions(staticIndex(iMotionBlock), :) = Shuffle(staticDirections);

end

Expand All @@ -113,7 +113,7 @@
case 'motion'
thisBlockName = {'motion'};
end
cfg.designBlockNames(iBlock) = thisBlockName;
cfg.design.blockNames(iBlock) = thisBlockName;

% set target
% if there are 2 targets per block we make sure that they are at least
Expand Down Expand Up @@ -141,19 +141,19 @@

end

cfg.designFixationTargets(iBlock, chosenTarget) = 1;
cfg.design.fixationTargets(iBlock, chosenTarget) = 1;

end

%% Visualize the design matrix
if displayFigs

uniqueNames = unique(cfg.designBlockNames) ;
uniqueNames = unique(cfg.design.blockNames) ;

Ind = zeros(length(cfg.designBlockNames), length(uniqueNames)) ;
Ind = zeros(length(cfg.design.blockNames), length(uniqueNames)) ;

for i = 1:length(uniqueNames)
CondInd(:, i) = find(strcmp(cfg.designBlockNames, uniqueNames{i})) ; %#ok<*AGROW>
CondInd(:, i) = find(strcmp(cfg.design.blockNames, uniqueNames{i})) ; %#ok<*AGROW>
Ind(CondInd(:, i), i) = 1 ;
end

Expand Down