Skip to content
Snippets Groups Projects
Commit e9d2d5bb authored by Violante, Ines Dr (Psychology)'s avatar Violante, Ines Dr (Psychology)
Browse files

updates

parent be81f7eb
No related branches found
No related tags found
No related merge requests found
Showing
with 1110 additions and 197 deletions
......@@ -14,6 +14,7 @@
% v7 July 2019 - adapted for MRI
% v8 June 2021 - adjusting for more flexibility and a Part-the-Cloud
% project
% v9 Jan 2022 - adjust for session based behv task
%% Clear the workspace and the screen
sca;
......@@ -23,50 +24,48 @@ clear
rand('state',sum(100*clock));
%% Go to task directory
load PathTask
load (['Parameters' filesep 'PathTask.mat'])
TaskDir = (path);
ResultsDir = ([TaskDir filesep 'Data']);
addpath(genpath(TaskDir));
cd (TaskDir)
load BlockParameters_3Cond
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Subject Info, Directories, Task Parameters
[SubjectInfo, TaskParameters] = GetSubjectInfo(ResultsDir);
[SubjectInfo, TaskParameters, OrderStim, StructBlockParameters] = GetSubjectInfo(ResultsDir);
%%
Stimulation = SubjectInfo.Stimulation;
MRI = SubjectInfo.MRI;
Stimulation = SubjectInfo.Stimulation;
if (Stimulation)
if (Stimulation)
port = SubjectInfo.COM;
% Standard Parameters to start with
rampOnTime = 5*1000; % ms
rampOnTime = 5*1000; % ms %% Cannot be longer than baseline time
rampOffTime =5*1000; % ms
% Channel 1
Freq1 = 2000; % Hz
Amp1 = 2; % mA
load1a = '20';
load1b = '20';
load1a = '32';
load1b = '32';
pin1a = '01';
pin1b = '02';
% Channel 2
Freq2 = 2005; % Hz
Amp2 = 2; % mA
load2a = '20';
load2b = '20';
load2a = '32';
load2b = '32';
pin2a = '03';
pin2b = '04';
% Initialise TI
[stimulator] = InitialiseTI(port);
% Give some initial parameters
UploadStimTI(stimulator, Freq1, Freq2, Amp1, Amp2, load1a, load1b, load2a, load2b, pin1a, pin1b, pin2a, pin2b)
stimulationStatus = 0;
end
......@@ -105,10 +104,13 @@ blue = [0 153 153];
grey = [128 128 128];
% Make a base Rect
imageRect = [0 0 250 100];
%%imageRect = [0 0 250 100];
imageRect = [0 0 310 100];
%%imageRect = [0 0 360 100]; - ICL
% Screen X positions of rectangles
squareXposTop = [screenXpixels * 0.25 screenXpixels * 0.5 screenXpixels * 0.75];
%squareXposTop = [screenXpixels * 0.25 screenXpixels * 0.5 screenXpixels * 0.75];
squareXposTop = [screenXpixels * 0.15 screenXpixels * 0.5 screenXpixels * 0.85];
squareXposMid = [screenXpixels * 0.375 screenXpixels * 0.625 ];
% Make rectangle coordinates
......@@ -146,7 +148,7 @@ end
%BottomRect = CenterRectOnPointd(imageRect, xCenter, yCenter+360);
if strcmp(SubjectInfo.Study, 'Part-the-Cloud')
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
allRects = [TopRects];
else
allRects = [TopRects MidRects];
......@@ -198,7 +200,7 @@ if (MRI)
if strcmp(SubjectInfo.MRIsite,'Invicro')
escapeKey = KbName('q');
respKey = KbName('3#');
respKey = KbName('1!');
leftKey = KbName('b');
rightKey = KbName('2@');
tkey=KbName('t');
......@@ -233,14 +235,14 @@ end
%% Text Parameters
TextSize = 28;
TextSize = 45;
Screen('TextFont', window, 'Helvetica');
Screen('TextSize', window, TextSize);
%% Fixation Cross Parameters
fixCrossDimPix = 40;
lineWidthPix = 4;
fixCrossDimPix = 50;
lineWidthPix = 7;
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
......@@ -256,9 +258,9 @@ StructTask.TrialStart = []; % Trial start time in relation to the beginning
StructTask.FacePresented = []; % Time at which the face was presented in relation to the beginning of the task
StructTask.Face = []; % Full path to the face picture
StructTask.Name = []; % Name
StructTask.NameNum = []; % Number matching the name
StructTask.NameFreqOrder = []; % The order the name has in terms of frequency (small numbers are more frequent)
StructTask.NameFreq = []; % The actual number of newborns with that name (larger numbers are more frequent)
%StructTask.NameNum = []; % Number matching the name
%StructTask.NameFreqOrder = []; % The order the name has in terms of frequency (small numbers are more frequent)
%StructTask.NameFreq = []; % The actual number of newborns with that name (larger numbers are more frequent)
StructTask.RespOrder = []; % Order in which this image will be presented during response period
StructTask.RespTimeStart = []; % Time the response time started for each trial in relation to the beginning of the task
StructTask.OnsetRespButtonPress = []; % Onset button press
......@@ -285,21 +287,7 @@ StructTask.Probed = []; % Indicates whether this is one of the selected
StructTask.Counting = []; % Task counter
%% Variables to save for EVs
EVblock_part1.StartTime = [];
EVblock_part1.Duration = [];
EVblock_part1.Condition = [];
EVblock_part2.StartTime = [];
EVblock_part2.Duration = [];
EVblock_part2.Condition = [];
EVresponse.StartTime = [];
EVresponse.Duration = [];
EVresponse.Condition = [];
EVinst.StartTime = [];
EVinst.Duration = [];
EVinst.Condition = [];
EVblock = [];
%% Define the order of the blocks
......@@ -313,13 +301,17 @@ run = SubjectInfo.Run;
bb = 1;
counter = 0;
counterdisttask=1;
HideCursor;
%% Task Loop
DrawFormattedText(window, 'Face-Name Task', 'center', 'center', [0 0 0]);
DrawFormattedText(window, 'Get Ready!', 'center', yCenter+100, [0 0 0]);
Screen(window, 'Flip');
%% ------- Task Loop -------------
% --------------------------------
TextSize = 60; %%%%%%%%%%%%%
Screen('TextSize', window, TextSize); %%%%%%%%%%%%%%%%%
DrawFormattedText(window, 'Face-Name Task', 'center', 'center', [0 0 0]);
DrawFormattedText(window, 'Get Ready!', 'center', yCenter+100, [0 0 0]);
Screen(window, 'Flip');
if MRI == 1
[keyisdown,secs,keycode] = KbCheck;
......@@ -331,19 +323,34 @@ HideCursor;
WaitSecs(2)
end
TimeTaskStart = GetSecs();
counter_ev = 1;
TimeTaskStart = GetSecs();
for bb=1:numel(block)
%% Load Task Parameters file for the Block
[OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParameters(SubjectInfo, TaskParameters, StructBlockParameters, block(bb));
if strcmp(SubjectInfo.Study,'TIDES-Behv')
StructBlockParameters = [StructBlockParameters(find([StructBlockParameters.Session] == session))];
[StructBlock]= BlockParameters2(SubjectInfo, TaskParameters, StructBlockParameters, block(bb), session);
elseif strcmp(SubjectInfo.Study,'Part-the-Cloud')
if strcmp(SubjectInfo.Type,'Task')
[OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParameters(SubjectInfo, TaskParameters, StructBlockParameters, block(bb));
elseif strcmp(SubjectInfo.Type,'Practice')
[OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParametersPractice(SubjectInfo, TaskParameters, StructBlockParameters, block(bb));
end
else
[OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParameters(SubjectInfo, TaskParameters, StructBlockParameters, block(bb));
end
%% Start with Rest
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen('Flip',window);
time_start_baseline1 = GetSecs() - TimeTaskStart;
EVblock(counter_ev).block = bb;
EVblock(counter_ev).type = 'baseline';
EVblock(counter_ev).start = time_start_baseline1;
if (Stimulation)
WaitSecs(TaskParameters.BaselineTime-(rampOnTime/1000)) % Because there is always a ramp
......@@ -351,57 +358,94 @@ for bb=1:numel(block)
WaitSecs(TaskParameters.BaselineTime)
end
%% Define Stimulation Parameters for the Block and start stimulation
if (session==1) % Only stimulate in session 1
if(Stimulation)
if (OrderStim(subject,block(bb))==2) % Steer condition
%% Define Stimulation Parameters and start stimulation
if(Stimulation)
if (SubjectInfo.Encode ==1) % Only stimulate if session includes encode
if strcmp(SubjectInfo.Study, 'TIDES-MRI')
if (OrderStim(subject,block(bb))==2) % Steer condition
Amp1 = 1;
Amp2 = 3;
else
Amp1 = 2;
Amp2 = Amp1;
end
stimulationStatus = 1;
StartStimulationTI(stimulator, Amp1, Amp2, rampOnTime)
WaitSecs(rampOnTime/1000)
if(OrderStim(subject,block(bb)))==0
% Stop Stimulation
StopStimulationTI(stimulator, Amp1, Amp2, rampOffTime)
stimulationStatus = 0;
end
elseif strcmp(SubjectInfo.Study, 'TIDES-Behv') % Here we stimulate per session
Amp1 = 1;
Amp2 = 3;
else
Amp1 = 2;
Amp2 = Amp1;
end
stimulationStatus = 1;
StartStimulationTI(stimulator, Amp1, Amp2, rampOnTime)
WaitSecs(rampOnTime/1000)
if(OrderStim(subject,block(bb)))==0
% Stop Stimulation
StopStimulationTI(stimulator, Amp1, Amp2, rampOffTime)
stimulationStatus = 0;
% Only the first block of a series triggers the beginning of stimulation / end
if bb==1
stimulationStatus = 1;
StartStimulationTI(stimulator, Amp1, Amp2, rampOnTime)
WaitSecs(rampOnTime/1000)
if (OrderStim(subject,session)==0)
% Stop Stimulation % Sham condition
StopStimulationTI(stimulator, Amp1, Amp2, rampOffTime)
stimulationStatus = 0;
end
end
end
end
end
time_finish_baseline1 = GetSecs() - TimeTaskStart;
EVblock(counter_ev).end = time_finish_baseline1;
EVblock(counter_ev).duration = time_finish_baseline1 - time_start_baseline1;
counter_ev = counter_ev+1;
trial = 1;
for trial = 1:TaskParameters.NumTrials
time_start_trial = GetSecs()-TimeTaskStart;
counter=counter+1;
if trial==1
EVblock(counter_ev).block = bb;
EVblock(counter_ev).type = 'encode';
EVblock(counter_ev).start = time_start_trial;
timest = [EVblock(counter_ev).start];
end
%% Show stimuli
tmp_idx = [StructBlock(find([StructBlock.idx]==OrderFaceType(trial)))];
if strcmp(SubjectInfo.Study, 'TIDES-Behv')
tmp_idx = StructBlock(trial);
else
tmp_idx = [StructBlock(find([StructBlock.idx]==OrderFaceType(trial)))];
end
name = tmp_idx.Name;
stimfilename = ([tmp_idx.FacePath filesep tmp_idx.FaceFolder filesep tmp_idx.FaceFile]);
imdata = imread(char(stimfilename));
[imageHeight, imageWidth, colorChannels] = size(imdata);
aspectRatio = imageWidth/imageHeight;
imageHeights = screenYpixels .* 0.3;
imageHeights = screenYpixels .* 0.45;
%imageHeights = screenYpixels .* 0.3;
imageWidths = imageHeights .* aspectRatio;
xOffset = xCenter-(imageWidths/2);
yOffset = yCenter - imageHeights;
imageRect = [xOffset, yOffset, xOffset+imageWidths, yOffset+imageHeights];
if session == 1
if (SubjectInfo.Encode ==1)
TextSize = 70; %%%%%%%%%%%%%
Screen('TextSize', window, TextSize); %%%%%%%%%%%%%%%%%
DrawFormattedText(window, char(name), xCenter-(TextSize*2), yCenter+(imageHeights/2)-(TextSize*1.5), [0 0 0]);
tex=Screen('MakeTexture',window,imdata);
Screen('DrawTexture', window, tex,[],imageRect);
DrawFormattedText(window, char(name), xCenter-(TextSize*2), yCenter+(imageHeights/2)-(TextSize*1.5), [0 0 0]);
Screen(window, 'Flip');
TimeFaceStarted = GetSecs();
StructTask(counter).FacePresented = GetSecs()-TimeTaskStart;
......@@ -418,28 +462,43 @@ for bb=1:numel(block)
end
end
StructTask(counter).session = session;
StructTask(counter).block = block(bb);
StructTask(counter).trial = trial;
StructTask(counter).StimType = OrderStim(subject,block(bb));
if strcmp(SubjectInfo.Study, 'TIDES-Behv')
StructTask(counter).StimType = OrderStim(subject,session);
else
StructTask(counter).StimType = OrderStim(subject,block(bb));
end
StructTask(counter).OrderCond = tmp_idx.FaceType;
if session ==1
if (SubjectInfo.Encode ==1)
StructTask(counter).TrialStart = time_start_trial;
end
StructTask(counter).Face = stimfilename;
StructTask(counter).Name = name;
StructTask(counter).NameNum = tmp_idx.NameNum;
StructTask(counter).NameFreqOrder = tmp_idx.NameFreqOrder;
StructTask(counter).NameFreq = tmp_idx.NameFreq;
if any(AssociationsProbed==tmp_idx.idx)
if ~strcmp(SubjectInfo.Study, 'TIDES-Behv')
if any(AssociationsProbed==tmp_idx.idx)
StructTask(counter).Probed = 1;
else
StructTask(counter).Probed = 0;
end
elseif strcmp(SubjectInfo.Study, 'TIDES-Behv')
StructTask(counter).Probed = 1;
end
if strcmp(SubjectInfo.Study, 'TIDES-Behv')
StructTask(counter).RespOrder = tmp_idx.RespOrder;
else
StructTask(counter).Probed = 0;
StructTask(counter).RespOrder = find(OrderResp==tmp_idx.idx);
end
StructTask(counter).RespOrder = find(OrderResp==tmp_idx.idx);
StructTask(counter).NameDistractor1 = tmp_idx.DistractorName1;
StructTask(counter).DistractorNameFreq1 = tmp_idx.DistractorNameFreq1;
StructTask(counter).NameDistractor2 = tmp_idx.DistractorName2;
......@@ -451,47 +510,205 @@ for bb=1:numel(block)
clear stimfilename imdata tmp_idx
%%
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen(window, 'Flip');
WaitSecs(TaskParameters.ISI)
if trial == TaskParameters.NumTrials
timeblock2ended = GetSecs()-TimeTaskStart;
EVblock(counter_ev).end = timeblock2ended;
EVblock(counter_ev).duration = timeblock2ended - timest;
counter_ev = counter_ev+1;
end
if (SubjectInfo.Encode ==1)
Screen('Close', tex);
%Screen('Close');
end
Screen('Close', tex);
%Screen('Close');
end
%% stop stimulation
if (session==1)
%% stop stimulation if per block
if strcmp(SubjectInfo.Study, 'TIDES-MRI')
if(Stimulation)
if(stimulationStatus)
% Stop Stimulation
StopStimulationTI(stimulator, Amp1, Amp2, rampOffTime)
stimulationStatus = 0;
end
end
end
end
%% Save Information
pathname = SubjectInfo.RunFolder;
matfile = fullfile(pathname, SubjectInfo.baseNameTask);
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'EVblock');
%% Maintenance / Distractor Period
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen('Flip',window);
time_start_baseline2 = GetSecs()- TimeTaskStart;
WaitSecs(TaskParameters.BaselineTime)
EVblock(counter_ev).block = bb;
EVblock(counter_ev).type = 'baseline';
EVblock(counter_ev).start = time_start_baseline2;
if ~strcmp(SubjectInfo.Study, 'TIDES-Behv')
WaitSecs(TaskParameters.MaintainTime) % just fixation cross
elseif strcmp(SubjectInfo.Study, 'TIDES-Behv')
NumDuration = 0.5;
if (SubjectInfo.Encode ==1)
% --- Distractor Task ----
% 1. Say odd << and even >> in the screen for 1 s
DrawFormattedText(window, 'Odd or Even Task', 'center', yCenter-100, [0 0 0]);
DrawFormattedText(window, 'Press LEFT Arrow for ODD Numbers', 'center', yCenter+100, [0 0 0]);
DrawFormattedText(window, 'Press RIGHT Arrow for EVEN Numbers', 'center', yCenter+200, [0 0 0]);
Screen(window, 'Flip');
WaitSecs(4)
% Present Fixation Cross
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen(window, 'Flip');
WaitSecs(TaskParameters.ISI)
%Get Stimuli Parameters
[StructDistractor] = DistractorParameters(TaskParameters, NumDuration);
% 2. Show odd and even numbers 1:99
counterdist = 1;
TextSize = 160;
Screen('TextSize', window, TextSize);
% Initialise keyboard
keysOfInterest=zeros(1,256);
keysOfInterest(rightKey)=1;
keysOfInterest(leftKey)=1;
keysOfInterest(respKey)=1;
KbQueueCreate(deviceIndex, keysOfInterest);
KbQueueStart(deviceIndex);
timesUp = 0;
TimeDistStart = GetSecs();
while (GetSecs - TimeDistStart <= TaskParameters.MaintainTime-4-TaskParameters.ISI);
responded = 0;
number = [StructDistractor(counterdist).Stimuli];
DrawFormattedText(window, num2str(number), 'center', 'center', [0 0 0]);
Screen(window, 'Flip');
TimePresented = GetSecs();
counterdisttask = counterdisttask+1;
StructDistractor(counterdist).Presented = 1;
StructDistractor(counterdist).TimePresented = GetSecs() - TimeDistStart;
StructTaskDist(counterdisttask).block = bb;
StructTaskDist(counterdisttask).trial = [StructDistractor(counterdist).trial];
StructTaskDist(counterdisttask).Stimuli = number;
StructTaskDist(counterdisttask).Type = [StructDistractor(counterdist).Type];
tic
while (toc < NumDuration)
[pressed, firstPress]=KbQueueCheck(deviceIndex);
if pressed
responded = 1;
StructDistractor(counterdist).RT = GetSecs() - TimePresented;
StructTaskDist(counterdisttask).RT = [StructDistractor(counterdist).RT];
if firstPress(rightKey)
if (StructDistractor(counterdist).Type==0) % Correct answer
StructDistractor(counterdist).accuracy = 1;
StructTaskDist(counterdisttask).accuracy = 1;
else
StructDistractor(counterdist).accuracy = 0;
StructTaskDist(counterdisttask).accuracy = 0;
end
elseif firstPress(leftKey)
if (StructDistractor(counterdist).Type==1) % Correct answer
StructDistractor(counterdist).accuracy = 1;
StructTaskDist(counterdisttask).accuracy = 1;
else
StructDistractor(counterdist).accuracy = 0;
StructTaskDist(counterdisttask).accuracy = 0;
end
end
end
end
% ISI Period -
% Present Fixation Cross
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen(window, 'Flip');
StructDistractor(counterdist).TimeISIstart = GetSecs() - TimeDistStart;
StructTaskDist(counterdisttask).ISI = [StructDistractor(counterdist).ISI];
tic
while (toc < StructDistractor(counterdist).ISI)
[pressed, firstPress]=KbQueueCheck(deviceIndex);
if pressed
if ~(responded) % If already press during number do not take another key press
responded = 1;
StructDistractor(counterdist).RT = GetSecs() - TimePresented;
StructTaskDist(counterdisttask).RT = StructDistractor(counterdist).RT;
if firstPress(rightKey)
if (StructDistractor(counterdist).Type==0) % Correct answer
StructDistractor(counterdist).accuracy = 1;
StructTaskDist(counterdisttask).accuracy = 1;
else
StructDistractor(counterdist).accuracy = 0;
StructTaskDist(counterdisttask).accuracy = 0;
end
elseif firstPress(leftKey)
if (StructDistractor(counterdist).Type==1) % Correct answer
StructDistractor(counterdist).accuracy = 1;
StructTaskDist(counterdisttask).accuracy = 1;
else
StructDistractor(counterdist).accuracy = 0;
StructTaskDist(counterdisttask).accuracy = 0;
end
end
end
end
end
counterdist = counterdist + 1;
end
end
end
%
EVblock(counter_ev).end = GetSecs()- TimeTaskStart;
EVblock(counter_ev).duration = [EVblock(counter_ev).end] - time_start_baseline2;
counter_ev = counter_ev+1;
%% Save Information
pathname = SubjectInfo.RunFolder;
matfile = fullfile(pathname, SubjectInfo.baseNameTask);
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters');
if ((SubjectInfo.Encode ==1) && strcmp(SubjectInfo.Study, 'TIDES-Behv'))
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'StructDistractor','EVblock','StructTaskDist');
else
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'EVblock');
end
%% Collect Responses at the end of each Block
if strcmp(SubjectInfo.Study, 'TIDES-Behv')
if (SubjectInfo.Encode ==1)
TextSize = 60;
Screen('TextSize', window, TextSize);
DrawFormattedText(window, 'Recall Faces + Names', 'center', 'center', [0 0 0]);
Screen(window, 'Flip');
WaitSecs(2)
end
end
KbQueueCreate(deviceIndex, keysOfInterest);
KbQueueStart(deviceIndex);
block_resp = [StructTask(find([StructTask.block]==block(bb)))];
......@@ -500,16 +717,18 @@ for bb=1:numel(block)
NumTrialsResp = TaskParameters.NumTrialsResp;
Resp=sort([block_resp.RespOrder]);
if strcmp(SubjectInfo.Study, 'Part-the-Cloud') % In this case only 3 response options
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud')) % In this case only 3 response options
order_resp = [zeros(1,1) 1 (ones(1,1))*3];
else
order_resp = [zeros(1,2) 1 (ones(1,2))*3];
end
trial=1;
EVresponse(bb).StartTime = GetSecs()-TimeTaskStart;
EVblock(counter_ev).block = bb;
EVblock(counter_ev).type = 'recall';
EVblock(counter_ev).start = [EVresponse(bb).StartTime];
for trial = 1:NumTrialsResp
......@@ -527,7 +746,7 @@ for bb=1:numel(block)
rect = {};
if strcmp(SubjectInfo.Study, 'Part-the-Cloud')
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
rect(find(ordernames_resp==1),:)=cellstr(stimname); % this is the position of the correct name
rect(find(ordernames_resp==3),:)=[cellstr([tmp_idx.NameDistractor1])];
rect(find(ordernames_resp==0),:)=[cellstr([tmp_idx.NameFoil1])];
......@@ -545,7 +764,7 @@ for bb=1:numel(block)
StructTask(tmp_idx.Counting).RectFoil = find(ordernames_resp==0);
StructTask(tmp_idx.Counting).RectDistractor = find(ordernames_resp==3);
if strcmp(SubjectInfo.Study, 'Part-the-Cloud')
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
currentsq = 1;
else
currentsq = 2;
......@@ -601,7 +820,7 @@ for bb=1:numel(block)
currentsq = 1;
end
if strcmp(SubjectInfo.Study, 'Part-the-Cloud')
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
if currentsq > size(allRects,2)
currentsq = 1;
end
......@@ -620,9 +839,9 @@ for bb=1:numel(block)
for r = 1:size(allRects,2)
if r<=3
DrawFormattedText(window, char(rect(r,:)), squareXposTop(r)-(TextSize*2.5), yCenter+120, [1 1 1]);
DrawFormattedText(window, char(rect(r,:)), squareXposTop(r)-(TextSize*2), yCenter+120, [1 1 1]);
elseif r>=4
DrawFormattedText(window, char(rect(r,:)), squareXposMid(r-3)-(TextSize*2.5), yCenter+305, [1 1 1]);
DrawFormattedText(window, char(rect(r,:)), squareXposMid(r-3)-(TextSize*2), yCenter+305, [1 1 1]);
end
end
......@@ -691,101 +910,110 @@ for bb=1:numel(block)
%% Confidence
if ~strcmp(SubjectInfo.Study, 'Part-the-Cloud')
keysOfInterest=zeros(1,256);
keysOfInterest(rightKey)=1;
keysOfInterest(leftKey)=1;
keysOfInterest(respKey)=1;
KbQueueCreate(deviceIndex, keysOfInterest);
KbQueueStart(deviceIndex);
responded = 0;
currentsq = 1;
TimeConfidenceStart = GetSecs();
StructTask(tmp_idx.Counting).ConfidenceStartTime = GetSecs - TimeTaskStart;
while (GetSecs - TimeConfidenceStart <= TaskParameters.TimeResponse/4);
% Move square depending on key press
%[keyisdown,secs,keycode] = KbCheck;
[pressed, firstPress]=KbQueueCheck(deviceIndex);
if pressed
if firstPress(rightKey)
currentsq = currentsq + 1;
elseif firstPress(leftKey)
currentsq = currentsq - 1;
end
end
if currentsq < 1
currentsq = 1;
end
if currentsq > size(allSquares,2)
currentsq = size(allSquares,2);
end
if ~(strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
if (SubjectInfo.Encode ==1) % Only present with encoding blocks
keysOfInterest=zeros(1,256);
keysOfInterest(rightKey)=1;
keysOfInterest(leftKey)=1;
keysOfInterest(respKey)=1;
for jj=1:size(allSquares,2)
Screen('FillRect', window, grey, allSquares(:,jj));
end
Screen('FillRect', window, blue, allSquares(:,currentsq));
for sq =1:size(allSquares,2)
DrawFormattedText(window, num2str(sq), squareXpos(sq)-10, 'center', [1 1 1]);
end
KbQueueCreate(deviceIndex, keysOfInterest);
KbQueueStart(deviceIndex);
responded = 0;
currentsq = 1;
TimeConfidenceStart = GetSecs();
StructTask(tmp_idx.Counting).ConfidenceStartTime = GetSecs - TimeTaskStart;
%vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
Screen('Flip', window);
if pressed
if firstPress(respKey)
StructTask(tmp_idx.Counting).ConfidenceRT = GetSecs() - TimeConfidenceStart;
responded=currentsq;
while (GetSecs - TimeConfidenceStart <= TaskParameters.TimeConfidence);
% Move square depending on key press
%[keyisdown,secs,keycode] = KbCheck;
[pressed, firstPress]=KbQueueCheck(deviceIndex);
if pressed
if firstPress(rightKey)
currentsq = currentsq + 1;
elseif firstPress(leftKey)
currentsq = currentsq - 1;
end
end
if currentsq < 1
currentsq = 1;
end
if currentsq > size(allSquares,2)
currentsq = size(allSquares,2);
end
for jj=1:size(allSquares,2)
Screen('FillRect', window, grey, allSquares(:,jj));
end
Screen('FillRect', window, blue, allSquares(:,currentsq));
for sq =1:size(allSquares,2)
DrawFormattedText(window, num2str(sq), squareXpos(sq)-10, 'center', [1 1 1]);
end
%vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
Screen('Flip', window);
if pressed
if firstPress(respKey)
StructTask(tmp_idx.Counting).ConfidenceRT = GetSecs() - TimeConfidenceStart;
responded=currentsq;
end
end
if responded>0
Screen('Flip', window, [], 0);
WaitSecs(0.2);
break;
end
[keyisdown,secs,keycode] = KbCheck;
if(keycode(escapeKey))
Screen('CloseAll');
sca;
ShowCursor;
ListenChar(0);
break;
end;
WaitSecs(0.004)
end
KbQueueRelease(deviceIndex);
%KbQueueStop(deviceIndex)
StructTask(tmp_idx.Counting).Confidence = responded;
if responded>0
Screen('Flip', window, [], 0);
WaitSecs(0.2);
break;
end
[keyisdown,secs,keycode] = KbCheck;
if(keycode(escapeKey))
Screen('CloseAll');
sca;
ShowCursor;
ListenChar(0);
break;
end;
WaitSecs(0.004)
clear n stimfilename imdata rect resp0_tmp resp3_tmp tmp_idx
end
KbQueueRelease(deviceIndex);
%KbQueueStop(deviceIndex)
StructTask(tmp_idx.Counting).Confidence = responded;
clear n stimfilename imdata rect resp0_tmp resp3_tmp tmp_idx
end
end
Timerespended = GetSecs()-TimeTaskStart;
EVblock(counter_ev).end = Timerespended;
EVblock(counter_ev).duration = Timerespended - [EVresponse(bb).StartTime];
counter_ev = counter_ev+1;
Screen('Close');
%% Save Information
pathname = SubjectInfo.RunFolder;
matfile = fullfile(pathname, SubjectInfo.baseNameTask);
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters');
if ((SubjectInfo.Encode ==1) && strcmp(SubjectInfo.Study, 'TIDES-Behv'))
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'StructDistractor','EVblock','StructTaskDist');
else
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'EVblock');
end
bb=bb+1;
% Adjust Time
% Adjust Time
if MRI == 1
[keyisdown,secs,keycode] = KbCheck;
while(~keycode(tkey)) % wait for a right button press
......@@ -799,6 +1027,29 @@ end
Screen('DrawLines', window, allCoords,lineWidthPix, black, [xCenter yCenter], 2);
Screen('Flip',window);
if(Stimulation)
if strcmp(SubjectInfo.Study, 'TIDES-Behv') % Here we stimulate per session
Amp1 = 1;
Amp2 = 3;
if (OrderStim(subject,session)==0) % Sham session; ramp up at the end
stimulationStatus = 1;
StartStimulationTI(stimulator, Amp1, Amp2, rampOnTime)
WaitSecs(rampOnTime/1000)
end
elseif (OrderStim(subject,session)==1)
WaitSecs(rampOnTime/1000)
end
end
%% If any stimulation is going stop it now
if(Stimulation)
if(stimulationStatus)
% Stop Stimulation
StopStimulationTI(stimulator, Amp1, Amp2, rampOffTime)
stimulationStatus = 0;
end
end
WaitSecs(TaskParameters.BaselineTime)
......@@ -806,8 +1057,11 @@ WaitSecs(TaskParameters.BaselineTime)
pathname = SubjectInfo.RunFolder;
matfile = fullfile(pathname, SubjectInfo.baseNameTask);
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters');
if ((SubjectInfo.Encode ==1) && strcmp(SubjectInfo.Study, 'TIDES-Behv'))
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'StructDistractor','EVblock','StructTaskDist');
else
save (matfile, 'SubjectInfo', 'StructTask', 'TaskParameters', 'EVblock');
end
DrawFormattedText(window, 'Thank you', 'center', 'center', [0 0 0]);
Screen(window, 'Flip');
......@@ -827,3 +1081,11 @@ end
%% REMIND EXPERIMENTER WHICH BLOCK WAS JUST RUN
clc
warning(['Completed: Block no. ' num2str(block) ', Run no. ' num2str(run)])
% Tell experimenter accuracy if Practice run
if strcmp(SubjectInfo.Study,'TIDES-Behv')
if strcmp(SubjectInfo.Type,'Practice')
Accuracy_FaceName = (nansum([StructTask.Accuracy])/length(StructTask))*100
Accuracy_Distractor = (nansum([StructDistractor.accuracy])/sum([StructDistractor.Presented]==1))*100
end
end
function [OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParameters(SubjectInfo, TaskParameters, StructBlockParameters, block)
if ~exist([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'])
if ((strcmp(SubjectInfo.Study, 'Part-the-Cloud') && ...
~exist([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'])) || ( ~exist([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'])))
% Select the order each Face Type will be shown
if TaskParameters.NumTrials/4
......@@ -23,26 +25,40 @@ if ~exist([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_
StructBlock = [StructBlockParameters(find([StructBlockParameters.Block] == block))];
%clear StructBlockParameters
% (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
OrderFaceType=OrderFaceType_tmp(1:TaskParameters.NumTrials)*100;
Order_idx = [StructBlock(find([StructBlock.FaceType]==1))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==100)=Order_idx(1:length( OrderFaceType(OrderFaceType==100)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==2))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==200)=Order_idx(1:length( OrderFaceType(OrderFaceType==200)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==3))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==300)=Order_idx(1:length( OrderFaceType(OrderFaceType==300)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==4))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==400)=Order_idx(1:length( OrderFaceType(OrderFaceType==400)));
clear Order_idx OrderFaceType_tmp
......@@ -50,11 +66,18 @@ if ~exist([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_
AssociationsProbed = [sort(datasample(OrderFaceType(1:TaskParameters.NumTrials),TaskParameters.NumTrials,'Replace',false))];
save([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
end
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
save([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
else
save([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
end
end
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
load([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
else
load([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
end
%% Generate a new order to present - but make sure that this is split in half
a=[TaskParameters.NumTrials/2+1:1:TaskParameters.NumTrials];
......
function [StructBlock]= BlockParameters2(SubjectInfo, TaskParameters, StructBlockParameters, block, session)
%% Generate a random order to present - ensure no more than 2 of the same type in a row
StructBlock = [StructBlockParameters(find([StructBlockParameters.Block] == block))];
OrderFaceType_tmp = [StructBlock.FaceType];
pass=0;
while pass<1 % Ensure no more than 2 of the same type in a row
order = randperm(numel(OrderFaceType_tmp));
%OrderFaceType_tmp = OrderFaceType_tmp(randperm(numel(OrderFaceType_tmp)));
seqones = findseq(OrderFaceType_tmp(order));
oneseq=find(seqones(:,1)==1);
maxseqones=max(seqones(oneseq,3));
if maxseqones<3
pass=1;
end;
end
OrderFaceType = OrderFaceType_tmp(order);
StructBlock = struct2table(StructBlock);
StructBlock = StructBlock(order,:); % now the table has the new order
StructBlock.idx = [];
StructBlock.idx = [1:height(StructBlock)]'; % idx is now trial order
clear OrderFaceType_tmp
%% Select the order each face will be presented in the response part
ntrials = 1:numel(OrderFaceType);
pass=0;
while pass<1
OrderResp = ntrials(randperm(numel(ntrials)));
if ~any(OrderResp(end-1:end)==ntrials(end-1:end))
pass=1;
end
end
StructBlock.RespOrder = OrderResp'; % OrderResp added to table
%% Select Foils for each face
StructBlock.FaceType2 = mod(StructBlock.FaceType,2); % now males = 1 and females = 0
M = StructBlock(StructBlock.FaceType2==1,:);
F = StructBlock(StructBlock.FaceType2==0,:);
% M foils
pass=0;
while pass<1
foilnames1 = randperm(height(M));
foilnames2 = randperm(height(M));
if any(strcmpi(M.Name,M.Name(foilnames1))) || any(strcmpi(M.Name,M.Name(foilnames2))) || any(strcmpi(M.Name(foilnames1),M.Name(foilnames2)))
pass=0;
else
pass=1;
end
end
M.FoilName1=M.Name(foilnames1);
M.FoilName2=M.Name(foilnames2);
% F foils
pass=0;
while pass<1
foilnames1 = randperm(height(F));
foilnames2 = randperm(height(F));
if any(strcmpi(F.Name,F.Name(foilnames1))) || any(strcmpi(F.Name,F.Name(foilnames2))) || any(strcmpi(F.Name(foilnames1),F.Name(foilnames2)))
pass=0;
else
pass=1;
end
end
F.FoilName1=F.Name(foilnames1);
F.FoilName1=F.Name(foilnames1);
StructBlock = table2struct(StructBlock);
end
function [StructBlock, AssociationsProbed]= BlockParameters2(SubjectInfo, TaskParameters, StructBlockParameters, block, session)
%% Generate a random order to present - ensure no more than 2 of the same type in a row
StructBlock = [StructBlockParameters(find([StructBlockParameters.Block] == block))];
OrderFaceType_tmp = [StructBlock.FaceType];
pass=0;
while pass<1 % Ensure no more than 2 of the same type in a row
order = randperm(numel(OrderFaceType_tmp));
%OrderFaceType_tmp = OrderFaceType_tmp(randperm(numel(OrderFaceType_tmp)));
seqones = findseq(OrderFaceType_tmp(order));
oneseq=find(seqones(:,1)==1);
maxseqones=max(seqones(oneseq,3));
if isempty(maxseqones)
pass = 1;
end
if maxseqones<3
pass=1;
end;
end
OrderFaceType = OrderFaceType_tmp(order);
StructBlock = struct2table(StructBlock);
StructBlock = StructBlock(order,:); % now the table has the new order
StructBlock.idx = [];
StructBlock.idx = [1:height(StructBlock)]'; % idx is now trial order
clear OrderFaceType_tmp
%% Select the order each face will be presented in the response part
ntrials = 1:numel(OrderFaceType);
pass=0;
while pass<1
OrderResp = ntrials(randperm(numel(ntrials)));
y = intersect(OrderResp(end-1:end),ntrials(1:2)); % last two encode cannot be the 1st or 2nd to recall
if isempty(y)
pass=1;
end
end
StructBlock.RespOrder = OrderResp'; % OrderResp added to table
%% Select Foils for each face
StructBlock.FaceType2 = mod(StructBlock.FaceType,2); % now males = 1 and females = 0
M = StructBlock(StructBlock.FaceType2==1,:);
F = StructBlock(StructBlock.FaceType2==0,:);
% M foils
pass=0;
while pass<1
foilnames1 = randperm(height(M));
foilnames2 = randperm(height(M));
if any(strcmpi(M.Name,M.Name(foilnames1))) || any(strcmpi(M.Name,M.Name(foilnames2))) || any(strcmpi(M.Name(foilnames1),M.Name(foilnames2)))
pass=0;
else
pass=1;
end
end
M.FoilName1=M.Name(foilnames1);
M.FoilName2=M.Name(foilnames2);
% F foils
pass=0;
while pass<1
foilnames1 = randperm(height(F));
foilnames2 = randperm(height(F));
if any(strcmpi(F.Name,F.Name(foilnames1))) || any(strcmpi(F.Name,F.Name(foilnames2))) || any(strcmpi(F.Name(foilnames1),F.Name(foilnames2)))
pass=0;
else
pass=1;
end
end
F.FoilName1=F.Name(foilnames1);
F.FoilName2=F.Name(foilnames2);
StructBlockcomp = vertcat(F,M);
StructBlockcomp = sortrows(StructBlockcomp,'idx','ascend');
StructBlock = table2struct(StructBlockcomp);
end
function [OrderFaceType, StructBlock, AssociationsProbed, OrderResp]= BlockParametersPractice(SubjectInfo, TaskParameters, StructBlockParameters, block)
% Select the order each Face Type will be shown
if TaskParameters.NumTrials/4
Numtrials_generator = TaskParameters.NumTrials + (4 - rem(TaskParameters.NumTrials,4));
else
Numtrials_generator = TaskParameters.NumTrials;
end
OrderFaceType_tmp = repmat(1:4,[1 Numtrials_generator/4]);
pass=0;
while pass<1 % Ensure no more than 3 of the same type in a row
OrderFaceType_tmp = OrderFaceType_tmp(randperm(numel(OrderFaceType_tmp)));
seqones = findseq(OrderFaceType_tmp);
oneseq=find(seqones(:,1)==1);
maxseqones=max(seqones(oneseq,4));
if maxseqones<3
pass=1;
end;
end
StructBlock = [StructBlockParameters(find([StructBlockParameters.Block] == block))];
%clear StructBlockParameters
% (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
OrderFaceType=OrderFaceType_tmp(1:TaskParameters.NumTrials)*100;
Order_idx = [StructBlock(find([StructBlock.FaceType]==1))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==100)=Order_idx(1:length( OrderFaceType(OrderFaceType==100)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==2))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==200)=Order_idx(1:length( OrderFaceType(OrderFaceType==200)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==3))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==300)=Order_idx(1:length( OrderFaceType(OrderFaceType==300)));
clear Order_idx
Order_idx = [StructBlock(find([StructBlock.FaceType]==4))];
Order_idx = [Order_idx.idx];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud') && (SubjectInfo.Session==2))
Order_idx = Order_idx(3:end);
end
OrderFaceType(OrderFaceType==400)=Order_idx(1:length( OrderFaceType(OrderFaceType==400)));
clear Order_idx OrderFaceType_tmp
AssociationsProbed = [sort(datasample(OrderFaceType(1:TaskParameters.NumTrials),TaskParameters.NumTrials,'Replace',false))];
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
save([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
elseif (strcmp(SubjectInfo.Study, 'Practice'))
save([SubjectInfo.SessionFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
else
save([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
end
if (strcmp(SubjectInfo.Study, 'Part-the-Cloud'))
load([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
elseif (strcmp(SubjectInfo.Study, 'Practice'))
load([SubjectInfo.SessionFolder filesep 'Parameters_S' SubjectInfo.Subject '_Session_' num2str(SubjectInfo.Session) '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
else
load([SubjectInfo.ParamFolder filesep 'Parameters_S' SubjectInfo.Subject '_Block_' num2str(block) '.mat'],'AssociationsProbed','OrderFaceType','StructBlock');
end
%% Generate a new order to present - but make sure that this is split in half
a=[TaskParameters.NumTrials/2+1:1:TaskParameters.NumTrials];
Order_tmp = [(randperm(TaskParameters.NumTrials/2)) a(randperm(numel(a)))];
OrderFaceType = OrderFaceType(Order_tmp);
clear Order_tmp a
%% Select the order each face will be presented in the response part
pass=0;
while pass<1
OrderResp = OrderFaceType(randperm(numel(OrderFaceType)));
if (OrderResp(1)~= OrderFaceType(end)) && (OrderResp(1)~= OrderFaceType(end-1))
pass=1;
end
end
%% Select Foils for each face
Mfoils = [StructBlock(find([StructBlock.FaceType]<3))];
Ffoils = [StructBlock(find([StructBlock.FaceType]>2))];
tmp = [1:1:length(Mfoils)];
pass = 0;
while pass<1
orderTochoose = [randperm(length(Mfoils)); randperm(length(Mfoils))];
if (any([tmp-orderTochoose(1,:)]==0)) || (any([tmp-orderTochoose(2,:)]==0)) || (any([orderTochoose(1,:)-orderTochoose(2,:)]==0))
pass =0;
else
pass=1;
end
end
counterM=1;
counterF=1;
for ii=1:length(StructBlock)
if ([StructBlock(ii).FaceType]<3)
StructBlock(ii).FoilName1 = [Mfoils(orderTochoose(1,counterM)).Name];
StructBlock(ii).FoilName2 = [Mfoils(orderTochoose(2,counterM)).Name];
counterM=counterM+1;
else
StructBlock(ii).FoilName1 = [Ffoils(orderTochoose(1,counterF)).Name];
StructBlock(ii).FoilName2 = [Ffoils(orderTochoose(2,counterF)).Name];
counterF=counterF+1;
end
end
select = ismember([StructBlock.idx],OrderFaceType); % this is for the case where the number of trials is less than 16!
if sum(select)~=length(select)
StructBlock = StructBlock(select);
end
File moved
function [StructDistractor] = DistractorParameters(TaskParameters, NumDuration)
%% Odd/even distractor parameter generator
NumStimuli = TaskParameters.MaintainTime*NumDuration; % larger than what would be shown
% Generate ISI distribution
meanISI = 2.1;
sdISI = 0.5;
ISI_dist = sdISI.*randn(NumStimuli,1) + meanISI;
% Generate stim distribution - numbers might be repeated, but have similar
% number of odd and even numbers; allow a difference of 30%
pass=0;
while pass<1
stimuli = randi(99,1,NumStimuli);
if ~(numel(find(mod(stimuli,2)==0)) > NumStimuli*0.7)
pass=1;
end
end
% Create a structure for the distractor task
StructDistractor = table;
StructDistractor.trial = (1:NumStimuli)';
StructDistractor.Stimuli = stimuli';
StructDistractor.ISI = ISI_dist;
StructDistractor.Type = mod(stimuli,2)';
StructDistractor.Presented = zeros(NumStimuli,1);
StructDistractor = table2struct(StructDistractor);
end
......@@ -39,7 +39,7 @@ Formats(3,1).type = 'edit';
Formats(3,1).format = 'text';
Formats(3,1).size = 120;
Formats(3,1).unitsloc = 'bottomleft';
DefAns.Block = '1 2 3 4 5 6';
DefAns.Block = '1 2 3 4';
Prompt(4,:) = {'Run', 'Run','(run number)'};
Formats(4,1).type = 'edit';
......@@ -64,7 +64,7 @@ Formats(6,1).format = 'text';
Formats(6,1).style = 'radiobutton';
Formats(6,1).items = {'Yes' 'No'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.Stimulation = 'No';%3; %
DefAns.Stimulation = 'Yes';%3; %
Prompt(end+1,:) = {'COM Port','Port','(port number - for Stim)'};
Formats(7,1).type = 'edit';
......@@ -80,16 +80,24 @@ Formats(8,1).format = 'text';
Formats(8,1).style = 'radiobutton';
Formats(8,1).items = {'No' 'CIF' 'Invicro'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.MRI = 'Invicro';%3; %
DefAns.MRI = 'No';%3; %
Prompt(end+1,:) = {'Task Parameters','Parameters',[]};
Formats(9,1).type = 'list';
Formats(9,1).format = 'text';
Formats(9,1).style = 'radiobutton';
Formats(9,1).items = {'Behv-Standard' 'TIDES-MRI' 'Part-the-Cloud'};
Formats(9,1).items = {'Behv-Standard' 'TIDES-MRI' 'Part-the-Cloud' 'TIDES-Behv' 'Practice'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.Parameters = 'Part-the-Cloud';%3; %
DefAns.Parameters = 'TIDES-Behv';%3; %
Prompt(end+1,:) = {'Task Stages','Stages',[]};
Formats(10,1).type = 'list';
Formats(10,1).format = 'text';
Formats(10,1).style = 'radiobutton';
Formats(10,1).items = {'Encode + Recall' 'Recall Only'};
DefAns.Stages = 'Encode + Recall';%3; %
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)
......@@ -100,10 +108,20 @@ Run = Answer.Run;
Block = Answer.Block;
cTask = clock; %Current date and time as date vector. [year month day hour minute seconds]
baseNameTask=[SUBJECT '_S_' Session '_Block_' Block '_FaceName_' num2str(cTask(3)) '_' num2str(cTask(2)) '_' num2str(cTask(1)) '_' num2str(cTask(4)) '_' num2str(cTask(5))]; %makes unique filename
baseNameTask=[SUBJECT '_S_' num2str(Session) '_Block_' num2str(Block) '_FaceName_' num2str(cTask(3)) '_' num2str(cTask(2)) '_' num2str(cTask(1)) '_' num2str(cTask(4)) '_' num2str(cTask(5))]; %makes unique filename
%% Create directory to save Data
SubjFolder = ([ResultsDir filesep 'Subject_' char(SUBJECT)]);
%SubjectInfo.infoTask = infoTask;
SubjectInfo.Subject = SUBJECT;
SubjectInfo.Session = Session;
SubjectInfo.Block = Block;
SubjectInfo.Run = Run;
SubjectInfo.cTask = cTask;
SubjectInfo.baseNameTask = baseNameTask;
SubjectInfo.Study = Answer.Parameters;
SubjFolder = ([ResultsDir filesep 'Subject_' num2str(SUBJECT)]);
% Create Subject folder
if ~exist(SubjFolder, 'dir')
......@@ -111,33 +129,28 @@ if ~exist(SubjFolder, 'dir')
end
% Create Parameters folder
ParamFolder = ([SubjFolder filesep 'Parameters' ]);
if ~exist(ParamFolder, 'dir')
mkdir(ParamFolder);
end
SubjectInfo.ParamFolder = ParamFolder;
% Create session folder
SessionFolder = ([SubjFolder filesep 'Session_' char(Session)]);
SessionFolder = ([SubjFolder filesep 'Session_' num2str(Session)]);
if ~exist(SessionFolder, 'dir')
mkdir(SessionFolder);
end
% Create Run folder
RunFolder = ([SessionFolder filesep 'Run_' char(Run)]);
RunFolder = ([SessionFolder filesep 'Run_' num2str(Run)]);
if ~exist(RunFolder, 'dir')
mkdir(RunFolder);
end
%SubjectInfo.infoTask = infoTask;
SubjectInfo.Subject = SUBJECT;
SubjectInfo.Session = Session;
SubjectInfo.Block = Block;
SubjectInfo.Run = Run;
SubjectInfo.cTask = cTask;
SubjectInfo.baseNameTask = baseNameTask;
SubjectInfo.SubjFolder = SubjFolder;
SubjectInfo.ParamFolder = ParamFolder;
SubjectInfo.SessionFolder = SessionFolder;
SubjectInfo.RunFolder = RunFolder;
......@@ -153,7 +166,9 @@ SubjectInfo.Stimulation = Stimulation;
SubjectInfo.COM = (['COM' num2str(Answer.Port)]);
SubjectInfo.MRI = MRI;
SubjectInfo.MRIsite = Answer.MRI;
SubjectInfo.Study = Answer.Parameters;
if strcmp(Answer.Stages,'Encode + Recall'); encode = true; end
%% Task Parameters
......@@ -185,9 +200,23 @@ if strcmp(Answer.Parameters,'Part-the-Cloud');
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
end
if strcmp(Answer.Parameters,'Practice');
TaskParameters.FaceDisplayTime = 4; % Time face is displayed
TaskParameters.TimeResponse = 16; % Max time allowed for a response
TaskParameters.NumTrials = 6; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 16; % Duration of the baseline
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
end
if strcmp(Answer.Parameters,'TIDES-Behv');
TaskParameters.FaceDisplayTime = 2; % Time face is displayed
TaskParameters.TimeResponse = 6; % Max time allowed for a response
TaskParameters.NumTrials = 16; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 5; % Duration of the baseline - 5s to match rump up and rump down - during rump down do we do a filler task (?)
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
end
end
\ No newline at end of file
function [SubjectInfo, TaskParameters, OrderStim, StructBlockParameters] = GetSubjectInfo(ResultsDir)
Title = 'Face Name Task';
%%%% SETTING DIALOG OPTIONS
% Options.WindowStyle = 'modal';
Options.Resize = 'on';
Options.Interpreter = 'tex';
Options.CancelButton = 'on';
Options.ApplyButton = 'off';
Options.ButtonNames = {'Continue','Cancel'}; %<- default names, included here just for illustration
Option.Dim = 8; % Horizontal dimension in fields
Prompt = {};
Formats = {};
DefAns = struct([]);
% Prompt(1,:) = {['Face Name Task'],[],[]};
% Formats(1,1).type = 'text';
% Formats(1,1).size = [-1 0];
% Formats(1,1).span = [1 2]; % item is 1 field x 4 fields
Prompt(1,:) = {'Subject Number', 'Number',[]};
Formats(1,1).type = 'edit';
Formats(1,1).format = 'text';
Formats(1,1).size = 30; % automatically assign the height
DefAns(1).Number = '';
Prompt(2,:) = {'Initials', 'Initials',[]};
Formats(2,1).type = 'edit';
Formats(2,1).format = 'text';
Formats(2,1).size = 80;
DefAns.Initials = '';
Prompt(3,:) = {'Task Parameters','Parameters',[]};
Formats(3,1).type = 'list';
Formats(3,1).format = 'text';
Formats(3,1).style = 'radiobutton';
Formats(3,1).items = { 'TIDES-MRI' 'TIDES-Behv' 'Part-the-Cloud'};
%Formats(9,1).items = {'Behv-Standard' 'TIDES-MRI' 'Part-the-Cloud' 'TIDES-Behv' 'Practice'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.Parameters = 'TIDES-Behv';%3; %
Prompt(4,:) = {'Type','Type',[]};
Formats(4,1).type = 'list';
Formats(4,1).format = 'text';
Formats(4,1).style = 'radiobutton';
Formats(4,1).items = {'Task' 'Practice'};
DefAns.Type = 'Task';%3; %
Prompt(5,:) = {'Session', 'Session','(session number)'};
Formats(5,1).type = 'edit';
Formats(5,1).format = 'integer';
Formats(5,1).limits = [0 999999999]; % 9-digits (positive #)
Formats(5,1).size = 80;
Formats(5,1).unitsloc = 'bottomleft';
DefAns.Session = '';
Prompt(6,:) = {'Run', 'Run','(run number; use 0 for Practice)'};
Formats(6,1).type = 'edit';
Formats(6,1).format = 'integer';
Formats(6,1).limits = [0 999999999]; % 9-digits (positive #)
Formats(6,1).size = 80;
Formats(6,1).unitsloc = 'bottomleft';
DefAns.Run = 1;
Prompt(7,:) = {'Block Order', 'Block','(use space between numbers (up to 9))'};
Formats(7,1).type = 'edit';
Formats(7,1).format = 'text';
Formats(7,1).size = 120;
Formats(7,1).unitsloc = 'bottomleft';
DefAns.Block = '1 2 3 4';
Prompt(end+1,:) = {'Task Stages','Stages',[]};
Formats(8,1).type = 'list';
Formats(8,1).format = 'text';
Formats(8,1).style = 'radiobutton';
Formats(8,1).items = {'Encode + Recall' 'Recall Only'};
DefAns.Stages = 'Encode + Recall';%3; %
Prompt(end+1,:) = {'Stimulation','Stimulation',[]};
Formats(9,1).type = 'list';
Formats(9,1).format = 'text';
Formats(9,1).style = 'radiobutton';
Formats(9,1).items = {'Yes' 'No'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.Stimulation = 'Yes';%3; %
Prompt(end+1,:) = {'COM Port','Port','(port number - for Stim)'};
Formats(10,1).type = 'edit';
Formats(10,1).format = 'integer';
Formats(10,1).limits = [0 999999999]; % 9-digits (positive #)
Formats(10,1).size = 80;
Formats(10,1).unitsloc = 'bottomleft';
DefAns.Port = 5;
Prompt(end+1,:) = {'MRI','MRI',[]};
Formats(11,1).type = 'list';
Formats(11,1).format = 'text';
Formats(11,1).style = 'radiobutton';
Formats(11,1).items = {'No' 'CIF' 'Invicro'};
% Formats(7,1).span = [2 1]; % item is 2 field x 1 fields
DefAns.MRI = 'No';%3; %
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)
if (Cancelled)
error(' ---- Cancel button pressed -----');
return;
end
SUBJECT = Answer.Number;
Session = Answer.Session;
Run = Answer.Run;
Block = Answer.Block;
cTask = clock; %Current date and time as date vector. [year month day hour minute seconds]
baseNameTask=[SUBJECT '_S_' num2str(Session) '_Block_' num2str(Block) '_FaceName_' num2str(cTask(3)) '_' num2str(cTask(2)) '_' num2str(cTask(1)) '_' num2str(cTask(4)) '_' num2str(cTask(5))]; %makes unique filename
%% Create directory to save Data
%SubjectInfo.infoTask = infoTask;
SubjectInfo.Subject = SUBJECT;
SubjectInfo.Session = Session;
SubjectInfo.Block = Block;
SubjectInfo.Run = Run;
SubjectInfo.cTask = cTask;
SubjectInfo.baseNameTask = baseNameTask;
SubjectInfo.Study = Answer.Parameters;
SubjFolder = ([ResultsDir filesep 'Subject_' num2str(SUBJECT)]);
% Create Subject folder
if ~exist(SubjFolder, 'dir')
mkdir(SubjFolder);
end
% Create Parameters folder
ParamFolder = ([SubjFolder filesep 'Parameters' ]);
if ~exist(ParamFolder, 'dir')
mkdir(ParamFolder);
end
SubjectInfo.ParamFolder = ParamFolder;
% Create session folder
SessionFolder = ([SubjFolder filesep 'Session_' num2str(Session)]);
if ~exist(SessionFolder, 'dir')
mkdir(SessionFolder);
end
% Create Run folder
RunFolder = ([SessionFolder filesep 'Run_' num2str(Run)]);
if ~exist(RunFolder, 'dir')
mkdir(RunFolder);
end
SubjectInfo.SubjFolder = SubjFolder;
SubjectInfo.SessionFolder = SessionFolder;
SubjectInfo.RunFolder = RunFolder;
if strcmp(Answer.Stimulation,'Yes'); Stimulation = true; end
if strcmp(Answer.Stimulation,'No'); Stimulation = false; end
if strcmp(Answer.MRI,'No'); MRI = false; end
if strcmp(Answer.MRI,'CIF'); MRI = true; end
if strcmp(Answer.MRI,'Invicro'); MRI = true; end
if strcmp(Answer.Stages,'Encode + Recall'); encode = true; end
if strcmp(Answer.Stages,'Recall Only'); encode = false; end
SubjectInfo.Stimulation = Stimulation;
SubjectInfo.COM = (['COM' num2str(Answer.Port)]);
SubjectInfo.MRI = MRI;
SubjectInfo.MRIsite = Answer.MRI;
SubjectInfo.Encode = encode;
SubjectInfo.Type = Answer.Type;
ppath=('Parameters');
%% Task Parameters
if strcmp(Answer.Parameters,'Behv-Standard');
TaskParameters.FaceDisplayTime = 2; % Time face is displayed
TaskParameters.TimeResponse = 20; % Max time allowed for a response
TaskParameters.NumTrials = 16; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 5; % Duration of the baseline - 5s to match rump up and rump down - during rump down do we do a filler task (?)
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
TaskParameters.TimeConfidence = 4;
TaskParameters.MaintainTime = TaskParameters.BaselineTime;
load ([ppath filesep 'BlockParameters_3Cond.mat'])
end
if strcmp(Answer.Parameters,'TIDES-MRI');
TaskParameters.FaceDisplayTime = 2; % Time face is displayed
TaskParameters.TimeResponse = 20; % Max time allowed for a response
TaskParameters.NumTrials = 16; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 16; % Duration of the baseline
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
TaskParameters.TimeConfidence = 4;
TaskParameters.MaintainTime = TaskParameters.BaselineTime;
load ([ppath filesep 'BlockParameters_3Cond.mat'])
end
if strcmp(Answer.Parameters,'Part-the-Cloud');
TaskParameters.FaceDisplayTime = 4; % Time face is displayed
TaskParameters.TimeResponse = 16; % Max time allowed for a response
TaskParameters.NumTrials = 6; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 16; % Duration of the baseline
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
TaskParameters.MaintainTime = TaskParameters.BaselineTime;
if strcmp(Answer.Type,'Task');
load ([ppath filesep 'BlockParameters_3Cond.mat'])
elseif strcmp(Answer.Type,'Practice');
load ([ppath filesep 'BlockParameters_3Cond_Practice.mat'])
end
end
if strcmp(Answer.Parameters,'TIDES-Behv');
TaskParameters.FaceDisplayTime = 2; % Time face is displayed
TaskParameters.TimeResponse = 8; % Max time allowed for a response
TaskParameters.NumTrials = 16; % Num of faces to learn per block - 4 per category: WM, WF, BM, BF
TaskParameters.ISI = 0.05; % Inter-stimulus interval - in effect 1s, takes ~100 ms to load the picture
TaskParameters.BaselineTime = 5; % Duration of the baseline - 5s to match rump up and rump down - during rump down do we do a filler task (?)
TaskParameters.NumTrialsResp = TaskParameters.NumTrials;
TaskParameters.MaintainTime = 40;
TaskParameters.TimeConfidence = 3;
if strcmp(Answer.Type,'Task');
load ([ppath filesep 'BlockParameters_TIDES-behv.mat'])
elseif strcmp(Answer.Type,'Practice');
load ([ppath filesep 'BlockParameters_TIDES-behv_Practice.mat'])
end
end
end
\ No newline at end of file
File moved
File moved
File moved
File moved
File moved
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment