Commit 1393aa47 authored by Julian Kosciessa's avatar Julian Kosciessa
Browse files

clean-up

parent f3ad63c4
function Stroop_170904(subjectsPath, setup)
% 170904 JQK | adapted from http://peterscarfe.com/stroopdemo.html
% | merged with parts of BasicSoundInputDemo for audio recording
% | removed parts related to RT encoding by button press
%% create individual directory
StroopPath = [subjectsPath, 'Stroop/']; mkdir(StroopPath);
%% set Stroop parameters
expInfo.Stroop.durITI = 1;
expInfo.Stroop.durResp = 2;
%% startup PTB
% Setup PTB with some default values
PsychDefaultSetup(2);
% Perform basic initialization of the sound driver:
InitializePsychSound;
% Open the default audio device [], with mode 2 (== Only audio capture),
% and a required latencyclass of zero 0 == no low-latency mode, as well as
% a frequency of 44100 Hz and 2 sound channels for stereo capture.
% This returns a handle to the audio device:
freq = 44100;
pahandle = PsychPortAudio('Open', [], 2, 0, freq, 2);
% Preallocate an internal audio recording buffer with a capacity of 5 seconds:
PsychPortAudio('GetAudioData', pahandle, 5);
rng('default');
rng('shuffle');
expInfo.Stroop.seed = rng;
% Set the screen number to the external secondary monitor if there is one
% connected
displayList = Screen('screens');
displayIdx = displayList(setup.screen);
KbName('UnifyKeyNames'); % Make sure keyboard mapping is the same on all supported operating systems
oldVerbosityLevel = Screen('Preference', 'Verbosity', 2); % show errors and warnings
if setup.DEBUG == 1
Screen('Preference', 'SkipSyncTests', 1);
PsychDebugWindowConfiguration(0, setup.opacity);
else
clear Screen; %PsychDebugWindowConfiguration([], 1);
end
% % Define black, white and grey
% white = WhiteIndex(displayIdx);
% grey = white / 2;
% black = BlackIndex(displayIdx);
screenInfo = openExperiment(50,50,displayIdx); clc; % open drawing canvas
if numel(Screen('screens')) == 1
HideCursor(screenInfo.curWindow);
end
Screen('TextFont', screenInfo.curWindow, 'Helvetica');
Screen('TextSize', screenInfo.curWindow, 20);
Screen('TextStyle', screenInfo.curWindow, 0); % regular
Screen('TextColor', screenInfo.curWindow, 255); % white
ifi = Screen('GetFlipInterval', screenInfo.curWindow); % Query the frame duration
% initiate black background
Screen('FillRect', screenInfo.curWindow, [255/2 255/2 255/2])
% Flip to clear
Screen('Flip', screenInfo.curWindow);
% Query the frame duration
ifi = Screen('GetFlipInterval', screenInfo.curWindow);
% Set the text size
Screen('TextSize', screenInfo.curWindow, 60);
% Query the maximum priority level
topPriorityLevel = MaxPriority(screenInfo.curWindow);
% Get the centre coordinate of the screenInfo.curWindow
[xCenter, yCenter] = RectCenter(screenInfo.screenRect);
% Set the blend funciton for the screen
Screen('BlendFunction', screenInfo.curWindow, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Do dummy calls to GetSecs, WaitSecs, KbCheck(-1) to make sure
% they are loaded and ready when we need them - without delays
% in the wrong moment:
KbCheck(-1);
WaitSecs(0.1);
GetSecs;
%----------------------------------------------------------------------
% Timing Information
%----------------------------------------------------------------------
% Interstimulus interval time in seconds and frames
isiTimeSecs = expInfo.Stroop.durITI;
isiTimeFrames = round(isiTimeSecs / ifi);
% Numer of frames to wait before re-drawing
waitframes = 1;
expInfo.Stroop.Timing = [];
%----------------------------------------------------------------------
% Colors in words and RGB
%----------------------------------------------------------------------
% We are going to use three colors for this demo. Red, Green and blue.
expInfo.Stroop.wordList = {'Rot', 'Grn', 'Blau'};
rgbColors = [255 0 0; 0 255 0; 0 0 255];
% Make the matrix which will determine our condition combinations
condMatrixBase = [sort(repmat([1 2 3], 1, 3)); repmat([1 2 3], 1, 3)];
trialsPerCondition = 9;
% Duplicate the condition matrix to get the full number of trials
condMatrix = repmat(condMatrixBase, 1, trialsPerCondition);
% Get the size of the matrix
[~, numTrials] = size(condMatrix);
% Randomise the conditions
shuffler = Shuffle(1:numTrials);
condMatrixShuffled = condMatrix(:, shuffler);
expInfo.Stroop.ColorCondsByTrial = condMatrixShuffled;
expInfo.Stroop.ColorCondsName = {'Row1: word'; 'Row2: color'};
%----------------------------------------------------------------------
% Experimental loop
%----------------------------------------------------------------------
% Animation loop: we loop for the total number of trials
for trial = 1:numTrials
% Word and color number
wordNum = condMatrixShuffled(1, trial);
colorNum = condMatrixShuffled(2, trial);
% The color word and the color it is drawn in
theWord = expInfo.Stroop.wordList(wordNum);
theColor = rgbColors(colorNum, :);
% If this is the first trial we present a start screen and wait for a
% key-press
if trial == 1
DrawFormattedText(screenInfo.curWindow, 'Bennenen Sie bitte die Wortfarbe. \n\n Drcken Sie eine Taste, um zu beginnen.',...
'center', 'center', [0 0 0]);
vbl = Screen('Flip', screenInfo.curWindow);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'ExpOnset'}, {vbl}];
KbStrokeWait;
end
% Flip again to sync us to the vertical retrace at the same time as
% drawing our fixation point
Screen('DrawDots', screenInfo.curWindow, [xCenter; yCenter], 10, [0 0 0], [], 2);
if trial == 1
flipWhen = 0;
else
flipWhen = StimOnset+expInfo.Stroop.durResp-ifi/2;
end
ITIOnset = Screen('Flip', screenInfo.curWindow, flipWhen);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'FixOnset'}, {ITIOnset}];
% set Onset for next stimulus
flipWhen = ITIOnset+expInfo.Stroop.durITI-ifi/2;
while GetSecs() < ITIOnset+expInfo.Stroop.durITI-100
pause(.001)
end
if trial ~= 1
% get audio from previous trial
StroopAudio.audio{trial-1} = PsychPortAudio('GetAudioData', pahandle);
PsychPortAudio('Stop', pahandle);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'GetAudio'}, {GetSecs()}];
AudioEncoded = 1;
end
% start next audio recording at specified time
PsychPortAudio('Start', pahandle, [], flipWhen);
% The person should be asked to respond to either the written word or
% the color the word is written in.
% Present the word, start audio recording.
DrawFormattedText(screenInfo.curWindow, char(theWord), 'center', 'center', theColor);
AudioEncoded = 0;
StimOnset = Screen('Flip', screenInfo.curWindow, flipWhen);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'StroopStart'}, {StimOnset}];
% We retrieve status once to get access to SampleRate:
if trial == 1
StroopAudio.s = PsychPortAudio('GetStatus', pahandle);
end
end
% record last audio response and exit PTB screen
DrawFormattedText(screenInfo.curWindow, 'Sie haben die Stroop-Aufgabe nun beendet. \n\n Vielen Dank!','center', 'center', [0 0 0]);
vbl = Screen('Flip', screenInfo.curWindow, StimOnset+expInfo.Stroop.durResp-ifi/2);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'EndScreen'}, {vbl}];
while GetSecs() < StimOnset+expInfo.Stroop.durResp+expInfo.Stroop.durITI-100
pause(.001);
end
PsychPortAudio('Stop', pahandle);
StroopAudio.audio{trial} = PsychPortAudio('GetAudioData', pahandle);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'GetAudio'}, {GetSecs()}];
PsychPortAudio('Close', pahandle);
%% save data
save([StroopPath,setup.subj(1:4), '_StroopData.mat'], 'StroopAudio', 'expInfo');
% KbStrokeWait;
pause(2);
sca;
end
\ No newline at end of file
% Main script for the state switching EEG experiment (September 2017)
% TO DO:
% - encode if EEG/MR
% - include MR onset trigger in resting state
% - preallocate randomization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% enter subject ID & task variant %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
prompt = {'Enter subject ID:','Enter paradigm (dynamic/words/visual):'};
dlg_title = 'StateSwitch Input';
num_lines = 1;
defaultans = {'0000','dynamic'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
setup.subj = answer{1}; % task materials: 'words', 'visual', 'dynamic'
setup.task = answer{2};
disp(['Continuing with subject ',setup.subj, ' and ', setup.task, ' task version.']);
%% add required paths
if ispc
pn.root = ['D:',filesep,'Dokumente und Einstellungen',filesep,'guest',filesep,'Desktop',filesep,'StateSwitchMR',filesep,'C_Paradigm',filesep];
else
disp('Setup no supported.');
%pn.root = [filesep,'Volumes',filesep,'LNDG',filesep,'stateSwitch',filesep,'B_paradigm',filesep,'StateSwitchEEG',filesep,'C_Paradigm',filesep];
end
pn.CB = [pn.root, 'checker',filesep]; addpath(pn.CB);
pn.MAT = [pn.root, 'dotsx',filesep]; addpath(pn.MAT);
pn.SS = [pn.root, 'StateSwitch',filesep]; addpath(pn.SS);
pn.Stroop = [pn.root, 'Stroop',filesep]; addpath(pn.Stroop);
addpath(genpath([pn.root, 'functions',filesep]));
addpath(genpath([pn.root, 'helper',filesep]));
% if ispc
% addpath(['C:',filesep,'toolbox',filesep,'Psychtoolbox']); % PTB 3.0.11
% else
% addpath(genpath('/Users/Shared/Psychtoolbox/')); % PTB 3.0.13 (160606)
% end
%% create results directory
setup.subjectsPath = [pn.root,filesep,'data',filesep, setup.subj '_MR_' datestr(now, 'yymmdd_HHMM') filesep]; mkdir(setup.subjectsPath);
diary([setup.subjectsPath, setup.subj, '_ptbnotes_setup.txt']); version
%% set up PTB
if ispc
Screen('Preference', 'SkipSyncTests', 0);
else
Screen('Preference', 'SkipSyncTests', 1);
oldLevel = Screen('Preference', 'Verbosity', 4); % output debugging info
PsychDebugWindowConfiguration(0,0.3)
% setenv('PSYCH_ALLOW_DANGEROUS', '1');
end
% %% practice task
%
% questdlg('Ready for Switch Practice?', 'Practice','YES!','YES!');
%
% cd(pn.root);
% setup = StateSwitch_settingsTaskPractice(setup);
% expInfo = []; expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170911']);
% StateSwitch_practice_170911(expInfo, setup);
%% run state switching task
questdlg('Ready for Switch Task?', 'Task','YES!','YES!');
cd(pn.root);
setup = StateSwitch_settingsTask_MR(setup);
%expInfo = []; expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170911']);
load('D:\Dokumente und Einstellungen\guest\Desktop\StateSwitchMR\C_Paradigm\data\1210_170914_1308\1210_StateSwitch_dynamic_170914_1337.mat', 'expInfo');
StateSwitch_experiment_170911(expInfo, setup)
%% resting state
questdlg('Ready for Resting State?', 'Rest','YES!','YES!');
setup = StateSwitch_settingsResting_MR(setup);
StateSwitch_resting_170829(setup)
\ No newline at end of file
% Main script for the state switching EEG experiment (Ocober 2017)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% enter subject ID & task variant %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
prompt = {'Enter subject ID:','Enter paradigm (dynamic/words/visual):'};
dlg_title = 'StateSwitch Input';
num_lines = 1;
defaultans = {'0000','words'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
setup.subj = answer{1}; % task materials: 'words', 'visual', 'dynamic'
setup.task = answer{2};
disp(['Continuing with subject ',setup.subj, ' and ', setup.task, ' task version.']);
%% add required paths
if ispc
pn.root = ['D:',filesep,'Dokumente und Einstellungen',filesep,'guest',filesep,'Desktop',filesep,'StateSwitchMR',filesep,'C_Paradigm',filesep];
else
disp('Setup no supported.');
pn.root = ['/Volumes/LNDG/StateSwitch/B_paradigm/StateSwitchMR/C_Paradigm/'];
end
pn.CB = [pn.root, 'checker',filesep]; addpath(pn.CB);
pn.MAT = [pn.root, 'dotsx',filesep]; addpath(pn.MAT);
pn.SS = [pn.root, 'StateSwitch',filesep]; addpath(pn.SS);
pn.Stroop = [pn.root, 'Stroop',filesep]; addpath(pn.Stroop);
addpath(genpath([pn.root, 'functions',filesep]));
addpath(genpath([pn.root, 'helper',filesep]));
if ispc
%addpath(['C:',filesep,'toolbox',filesep,'Psychtoolbox']); % PTB 3.0.11
else
addpath(genpath('/Users/Shared/Psychtoolbox/')); % PTB 3.0.13 (160606)
end
%% create results directory
setup.subjectsPath = [pn.root,filesep,'data',filesep, 'STSW_',setup.task(1),'_', setup.subj '_MR_' datestr(now, 'yymmdd_HHMM') filesep]; mkdir(setup.subjectsPath);
diary([setup.subjectsPath, setup.subj, '_ptbnotes_setup.txt']); version
%% set up PTB
if ispc
Screen('Preference', 'SkipSyncTests', 0);
else
Screen('Preference', 'SkipSyncTests', 1);
oldLevel = Screen('Preference', 'Verbosity', 4); % output debugging info
PsychDebugWindowConfiguration(0,0.3)
% setenv('PSYCH_ALLOW_DANGEROUS', '1');
end
%% run state switching task
% questdlg('Ready for Switch Task?', 'Task','YES!','YES!');
prompt = {'Start on run:'};
dlg_title = 'StateSwitch Run Input';
num_lines = 1;
defaultans = {'1'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
setup.StartRunOn = str2num(answer{1});
cd(pn.root);
setup = StateSwitch_settingsTask_MR(setup);
expInfo = []; expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_171023']);
StateSwitch_experiment_171023(expInfo, setup)
% practice and task of state switching variant
%%%%%%%%%%%%%%%%%%%%%%
%% enter subject ID %%
%%%%%%%%%%%%%%%%%%%%%%
subj = '0009_JQK';
%%%%%%%%%%%%%%%%%%%%%%%%
%% enter task variant %%
%%%%%%%%%%%%%%%%%%%%%%%%
setup.task = 'dynamic'; % task materials: 'words', 'visual', 'dynamic'
%% add required paths
pn.root = '/Volumes/LNDG/Julian/Projects/StateSwitch/C_Paradigm/';
pn.CB = [pn.root, 'checker/'];
pn.MAT = [pn.root, 'dotsx/'];
pn.SS = [pn.root, 'StateSwitch/'];
addpath(genpath([pn.root, 'functions/']));
addpath(pn.CB);
addpath(pn.MAT);
addpath(pn.SS);
addpath(genpath([pn.root, 'helper/']));
addpath(genpath('/Users/Shared/Psychtoolbox/')); % PTB 3.0.13 (160606)
%% create results directory
subjectsPath = [pn.root, '/data/', subj '_' datestr(now, 'yymmdd_HHMM') '/']; mkdir(subjectsPath);
diary([subjectsPath, '_ptbnotes.txt']); version
%% set up PTB
Screen('Preference', 'SkipSyncTests', 1);
oldLevel = Screen('Preference', 'Verbosity', 4); % output debugging info
PsychDebugWindowConfiguration(0,0.3)
% Screen('Preference', 'SkipSyncTests', 0);
% setenv('PSYCH_ALLOW_DANGEROUS', '1');
availableKeyboards = 1;
%% settings
setup.DEBUG = 1;
setup.opacity = .99;
setup.keyB = availableKeyboards;
setup.ET.useET = 0;
setup.ET.DIO.parallelTrigger = 1;
setup.EEG.useEEG = 0;
setup.MR.useMR = 0;
setup.ET.falsePupilRec = 'no';
setup.ET.ELdummymode = 0;
setup.pr.ntrials_single = 5; % amount of practice trials: single
setup.pr.ntrials_conj = 8; % amount of practice trials: conjunctions
%% practice task
% cd(pn.root);
%
% expInfo = [];
% expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170829']);
% expInfo.dataDir = subjectsPath;
%
% cursubj = [subj, '_MAT_Practice']; P = [];
% StateSwitch_practice_170829(expInfo, cursubj, setup, P);
%% run state switching task
cd(pn.root);
expInfo = [];
expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170829']);
expInfo.dataDir = [pn.root, 'data/'];
cursubj = [subj, '_StateDims_', setup.task];
StateSwitch_experiment_170829(expInfo, cursubj, setup)
% practice and task of state switching variant
%%%%%%%%%%%%%%%%%%%%%%
%% enter subject ID %%
%%%%%%%%%%%%%%%%%%%%%%
subj = '00010_test';
%%%%%%%%%%%%%%%%%%%%%%%%
%% enter task variant %%
%%%%%%%%%%%%%%%%%%%%%%%%
setup.task = 'dynamic'; % task materials: 'words', 'visual', 'dynamic'
%% add required paths
pn.root = 'C:\Users\eeg\Desktop\StateSwitch\C_Paradigm\';
pn.CB = [pn.root, 'checker\'];
pn.MAT = [pn.root, 'dotsx\'];
pn.SS = [pn.root, 'StateSwitch\'];
sca
addpath(genpath([pn.root, 'functions\']));
addpath(pn.CB);
addpath(pn.MAT);
addpath(pn.SS);
addpath(genpath([pn.root, 'helper\']));
addpath('C:\toolbox\Psychtoolbox'); % PTB ???
%% create results directory
subjectsPath = [pn.root, '/data/', subj '_' datestr(now, 'yymmdd_HHMM') '/']; mkdir(subjectsPath);
diary([subjectsPath, '_ptbnotes.txt']); version
%% set up PTB
%Screen('Preference', 'SkipSyncTests', 1);
%oldLevel = Screen('Preference', 'Verbosity', 4); % output debugging info
% PsychDebugWindowConfiguration(0,0.3)
% Screen('Preference', 'ConserveVRAM', 64)
Screen('Preference', 'SkipSyncTests', 0);
% setenv('PSYCH_ALLOW_DANGEROUS', '1');
availableKeyboards = 1;
%% settings for practice
setup.DEBUG = 0;
setup.opacity = .4;
setup.keyB = availableKeyboards;
setup.ET.useET = 0;
setup.EEG.useEEG = 0;
setup.EEG.DIO.parallelTrigger = 0;
setup.EEG.DIO.protocolDynamic = 0;
setup.EEG.waitTrigEnc = .005; % wait 5 ms to ensure encoding of trigger
setup.MR.useMR = 0;
setup.ET.falsePupilRec = 'no';
setup.ET.ELdummymode = 0;
setup.pr.ntrials_single = 5; % amount of practice trials: single
setup.pr.ntrials_conj = 8; % amount of practice trials: conjunctions
%% practice task
cd(pn.root);
expInfo = [];
expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170829']);
expInfo.dataDir = subjectsPath;
cursubj = [subj, '_MAT_Practice']; P = [];
StateSwitch_practice_170829(expInfo, cursubj, setup, P);
%% settings for task
setup.DEBUG = 0;
setup.opacity = .4;
setup.keyB = availableKeyboards;
setup.ET.useET = 1;
setup.EEG.useEEG = 1;
setup.EEG.DIO.parallelTrigger = 1;
setup.EEG.DIO.protocolDynamic = 1;
setup.EEG.waitTrigEnc = .005; % wait 5 ms to ensure encoding of trigger
setup.MR.useMR = 0;
setup.ET.falsePupilRec = 'no';
setup.ET.ELdummymode = 0;
%% run state switching task
cd(pn.root);
expInfo = [];
expInfo = eval(['StateSwitch_createExpInfo_',setup.task,'_170829']);
expInfo.dataDir = [pn.root, 'data/'];
expInfo.disp = 1;
cursubj = [subj, '_StateDims_', setup.task];
StateSwitch_experiment_170829(expInfo, cursubj, setup)
% practice and task of state switching variant
%%%%%%%%%%%%%%%%%%%%%%
%% enter subject ID %%
%%%%%%%%%%%%%%%%%%%%%%
subj = '0013_TEST';
%%%%%%%%%%%%%%%%%%%%%%%%
%% enter task variant %%
%%%%%%%%%%%%%%%%%%%%%%%%
setup.task = 'dynamic'; % task materials: 'words', 'visual', 'dynamic'
%% add required paths
if ispc
pn.root = ['C:',filesep,'Users',filesep,'eeg',filesep,'Desktop',filesep,'StateSwitchEEG',filesep,'C_Paradigm',filesep];
else
pn.root = [filesep,'Volumes',filesep,'LNDG',filesep,'Julian',filesep,'Projects',filesep,'StateSwitchEEG',filesep,'C_Paradigm',filesep];
end
pn.CB = [pn.root, 'checker',filesep]; addpath(pn.CB);
pn.MAT = [pn.root, 'dotsx',filesep]; addpath(pn.MAT);
pn.SS = [pn.root, 'StateSwitch',filesep]; addpath(pn.SS);
pn.Stroop = [pn.root, 'Stroop',filesep]; addpath(pn.Stroop);
addpath(genpath([pn.root, 'functions',filesep]));
addpath(genpath([pn.root, 'helper',filesep]));
if ispc
addpath(['C:',filesep,'toolbox',filesep,'Psychtoolbox']); % PTB 3.0.11
else
addpath(genpath('/Users/Shared/Psychtoolbox/')); % PTB 3.0.13 (160606)
end
%% create results directory
subjectsPath = [pn.root,filesep,'data',filesep, subj '_' datestr(now, 'yymmdd_HHMM') filesep]; mkdir(subjectsPath);
diary([subjectsPath, '_ptbnotes.txt']); version