= Using ScannerSync from Matlab = Make sure you have the ScannerSync control installed. Somewhere near the top of your code, set up ScannerSync & initialise communication with the input-output board (will not work if you're using a machine without the board, e.g., not the mimic or stim delivery machines). {{{ %% SCANNERSYNC TR=1000; % TR in ms numdummies=8; % Create & initialise scanner sync object objSS=actxserver('MRISync.ScannerSync'); %Create a scanner object invoke(objSS,'Initialize','') %Initialise the Keithley board and object invoke(objSS,'SetMSPerSample',2); %Set StartExperiment routines’ sampling }}} Now, wait for first pulse from scanner. Also, tell ScannerSync the approximate TR. {{ % ScannerSync - waits for the first pulse, resets timer to 0, sets TR invoke(objSS,'StartExperiment', double(TR)); }} Wait for dummies (one less as StartExperiment command above will already have heard a pulse) {{ for countdown=(numdummies-1):-1:1 count_text=sprintf('%d', countdown); % uncomment the next two if you're using the PsychToolbox % DrawFormattedText(window, count_text, 'center', 'center', white); % Screen(window, 'Flip'); invoke(objSS,'SynchroniseExperiment',1,0); % 1= force wait for actual pulse; 0=return this many ms after pulse end; }} In your trial loop, you'll need to spend some of the time listening for pulses {{ invoke(objSS,'CheckPulseSynchronyForTime', double(500)); % spend 500 ms listening for any pulses }} You should dump out the timing of critical events and the measured TR {{ picstarttime=invoke(objSS,'SSGetTimer'); measuredTR=invoke(objSS,'GetMeasuredTR'); % ...add your own code to write these to your output file }} Also, for some designs you may want to occasionally synchronise your trials to the scanner {{ invoke(objSS,'SynchroniseExperiment',1,0); % 1= force wait for actual pulse; 0=return this many ms after pulse }}