function SPR(cond) % ========================================================================= % function SPR % Experiment = Self-Paced/RSVP Paradigm % ========================================= % Assumes 60 Hz refresh rate % ** PLEASE ADJUST MONITOR REFRESH RATE ** % ========================================= % %% EXP 1: Experiment Title % Experiment description % %% Code Authors: % Thiago Oliveira da Motta Sampaio (ACESIN/LAPEX/UFRJ/INSERM/NeuroSpin) % Virginie van Wassenhove (CEA/NeuroSpin) %========================================================================== %% Rappel des "response pads" en MEG: % (On pose Port1= 888, Port2= 48353 et Port3= 48369) % % Couleur: blue / red / green / yellow / blue(thumb) % LEFT: [64] / [-128] / [64] / [32] / [16] % Port: Port3 / Port3 / Port2 / Port2 / Port2 % RIGHT: [8] / [64] / [32] / [16] / [8] % Port : Port2 /Port1+1 / Port1+1 / Port1+1 / Port1+1 % RQ1: Port3 donne un biais de 152 qu'il faut donc soustraire ? la % lecture ! % RQ2: Pas les m?mes n? pour l'ordi d'acquisition MEG %% EEG Ports and Triggers % PC stim port definition: %PCport1= hex2dec('378'); % &H378 -> 888 en base 10 %PCport2= hex2dec('BCE1'); %&HBCE1 -> 48353 en base 10 %PCport3= hex2dec('BCF1'); % &HBCF1 -> 48369 en base 10 %% Some frequently used KeyCodes for MAC Portability % ESC - 41 % SPACE - 44 % 1 - 30 % 2 - 31 % 3 - 32 % 4 - 33 % Q - 20 % P - 19 % A - 4 % L - 15 % K - 14 % J - 13 %% try KbName('UnifyKeyNames'); escapeKey = KbName('ESCAPE'); AssertOpenGL; %---------------------------------------------------------------------- % - PROMPT USER FOR DATA FILE NAME - %---------------------------------------------------------------------- dataFile='tmp'; promptUser=true; while promptUser prompt=inputdlg('ID','Output File',1,{'tmp'}); if isempty(prompt); disp(['Cancel experiment ...']); return; else initials=prompt{1}; end tmpFile = [initials,'_SPR.mat']; if ~exist(tmpFile); promptUser = false; else replace=questdlg(['Um arquivo com o mesmo nome já existe. Gostaria de substituí-lo?']); if strcmp( replace, 'Yes' ); dataFile = tmpFile; promptUser = false; end end end %---------------------------------------------------------------------- % LOADING VERSION/SUBJECT PARAMS %---------------------------------------------------------------------- if exist('cond') load([initials, '_SPR_params_', cond, '.mat']); dataFile = [initials,'_SPR_data_', cond]; else display('error: specify condition'); end psycdata = []; %---------------------------------------------------------------------- % - INITIALIZE DISPLAY - %---------------------------------------------------------------------- % affichage warning/error/autocalibration settings Screen('Preference','SkipSyncTests', 0); Screen('Preference','VisualDebugLevel', 1); Screen('Preference', 'ConserveVRAM', 4096); screens = Screen('Screens'); % Size of window: Default to fullscreen: screenNumber = 0; [w,screenRect] = Screen('OpenWindow', screenNumber,0,[],32,2); % blending (pour antialiasing) Screen('BlendFunction', w, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); % Display frequency fps = Screen('FrameRate',w); % frames per second ifi = Screen('GetFlipInterval', w); if fps == 0 fps = 1/ifi; end % Screen size in cm sH = 24; % screen height (cm) sW = 25; % screen width (cm) % whichScreen = max(Screen('Screens')); [w,wRect] = Screen('OpenWindow', whichScreen); % Color Defs white = WhiteIndex(w); black = BlackIndex(w); gray = (white+black)/2; red = [255 0 0 ]; green = [0 255 0]; blue = [0 0 255]; yellow = [255 255 0]; grayish = [100 100 100]; ft_color = white; bck_color = black; % Fixation Dot % dim + pos defs dW = wRect(3) - wRect(1); dH = wRect(4) - wRect(2); % pixel = dH/sH; x0 = dW/2; y0 = dH/2; fix_size = 0.2*pixel; fix_pos = [x0-fix_size/2 y0-fix_size/2 x0+fix_size/2 y0+fix_size/2]; fix_col = black; % choice positions TO CHECK x1 = x0 - 300; x2 = x0 + 150; y1 = y0 - 100; y2 = y0 - 150; % Screen('FillRect',w, bck_color); Screen('Flip', w); % %% %---------------------------------------------------------------------- % - INSTRUCTIONS SCREEN - %---------------------------------------------------------------------- HideCursor; inst1 = 'Pressione ESPALJO para continuar'; inst2 = 'PAUSA'; inst3 = 'Fim do Experimento. Obrigado pela participação'; % clear RestrictKeysForKbCheck; RestrictKeysForKbCheck([41, 44]); Screen('FillRect',w, bck_color); Screen('TextFont',w, 'Arial'); Screen('TextSize',w, 28); Screen('DrawText', w, inst1, x0-300, y0, ft_color); Screen('FillOval',w, fix_col, fix_pos); Screen('Flip', w); KbWait; %---------------------------------------------------------------------- % - STIMULI PRESENTATION - %---------------------------------------------------------------------- % - START LOOP - priorityLevel=MaxPriority(w); Priority(priorityLevel); for block = 1:1; % Initialize Data Matrix psycdata = []; for trial=1:length(expMat); clear RestrictKeysForKbCheck; RestrictKeysForKbCheck([41, 44]); % Screen('FillOval', w, fix_col, fix_pos); [nx, ny, bbox] = DrawFormattedText(w, ' + ', 'center', 'center', 255); Screen('Flip', w); WaitSecs(1); % [nx, ny, bbox] = DrawFormattedText(w, ' ', 'center', 'center', 255); Screen('Flip', w); WaitSecs(.03); % initialize trial RT t0 = GetSecs; for cnum = 3:9 promptUser = true; [nx, ny, bbox] = DrawFormattedText(w, lista{expMat(trial, cnum), expMat(trial,2)}, 'center', 'center', 255); Screen('Flip', w); WaitSecs(0.2); while (promptUser) KbWait; [keyIsDown,secs,keyCode]=KbCheck; WaitSecs(0.001); % delay to prevent CPU hogging if keyIsDown; psycdata{block}(trial,cnum) = secs-t0; % col 3:9 RT promptUser = false; end end end % %WaitSecs(0.03) %???? tempo RestrictKeysForKbCheck([14, 15, 41]); % TASK [nx, ny, bbox] = DrawFormattedText(w, lista{expMat(trial, 10), expMat(trial,2)}, 'center', 'center', red); Screen('Flip', w); %WaitSecs(.03); promptUser = true; while (promptUser) KbWait; [keyIsDown,secs,keyCode]=KbCheck; if keyIsDown; keyNum = find(keyCode); psycdata{block}(trial,10) = secs-t0; % col 2 RT if keyNum == 14; % Q psycdata{block}(trial,11) = 1; % col 11 choix elseif keyNum == 15; % P psycdata{block}(trial,11) = 2; % col 11 choix elseif keyCode(escapeKey) error('Esc key was pressed'); % ESCAPE program break; end promptUser = false; end end % end % trial save(dataFile,'expMat','psycdata'); %---------------------------------------------------------------------- % - BREAK AND END OF EXPERIMENT - %---------------------------------------------------------------------- if block > 1 % participant's break time after each block Screen('FillRect',w, bck_color); Screen('TextFont',w, 'Arial'); Screen('TextSize',w, 30); Screen('DrawText', w, inst2, x0-50, y0-10, ft_color); Screen('Flip', w); WaitSecs(2) KbWait; Screen('DrawText', w, inst1, x0-300, y0, ft_color); Screen('FillOval',w, fix_col, fix_pos); Screen('Flip', w); WaitSecs(2) KbWait; else Screen('FillRect',w, black); Screen('TextFont',w, 'Arial'); Screen('TextSize',w, 30); Screen('DrawText', w, inst3, x0-350, y0, ft_color); Screen('Flip', w); WaitSecs(3); end % end % block %% DATA correction % initialize temporary data matrix tmpdata = [] % Copy Subject Data from psycdata tmpdata = psycdata{1,1}; % merge trial number and stimuli number with subject data tmpdata(:,1) = expMat(:,1); tmpdata(:,2) = expMat(:,2); % As Rts are cumulative (2nd segment RT = 1st + 2nd segment RT) we need % to calculate segment RT from sentence check points. tmpdata(:,4) = tmpdata(:,4)-tmpdata(:,3) tmpdata(:,5) = tmpdata(:,5)-tmpdata(:,4)-tmpdata(:,3) % = tmpdata 5th column should be equal to tmpdata 5th column - tmpdata 4rd column and so on.... tmpdata(:,6) = tmpdata(:,6)-tmpdata(:,5)-tmpdata(:,4)-tmpdata(:,3) tmpdata(:,7) = tmpdata(:,7)-tmpdata(:,5)-tmpdata(:,4)-tmpdata(:,6)-tmpdata(:,3) tmpdata(:,8) = tmpdata(:,8)-tmpdata(:,5)-tmpdata(:,4)-tmpdata(:,6)-tmpdata(:,7)-tmpdata(:,3) tmpdata(:,9) = tmpdata(:,9)-tmpdata(:,5)-tmpdata(:,4)-tmpdata(:,6)-tmpdata(:,7)-tmpdata(:,8)-tmpdata(:,3) tmpdata(:,10) = tmpdata(:,10)-tmpdata(:,4)-tmpdata(:,3)-tmpdata(:,5)-tmpdata(:,6)-tmpdata(:,7)-tmpdata(:,8)-tmpdata(:,9) % save temporary data matrix as the final subject data matrix 'subjdata' subjdata = tmpdata % clear base matrixes clear psycdata, clear expMat, clear tmpdata %%% END RT Correction %%% %% SUBJECT DATA ANALYSIS % END SUBJ DATA ANALYSIS %% % Access DATA folder and save datafile cd DATA_SPR/ save(dataFile, 'initials', 'subjdata'); % Closing the Experiment Priority(0); ShowCursor; clear mex; Screen('CloseAll'); %---------------------------------------------------------------------- % - CATCH ERRORS - %---------------------------------------------------------------------- catch ShowCursor; Screen('CloseAll'); disp(['CRITICAL ERROR: ' lasterr ]); disp(['Exiting program ...']); rethrow(lasterror); end