Diff for "ScannerSyncMatlab" - Methods
location: Diff for "ScannerSyncMatlab"
Differences between revisions 6 and 7
Revision 6 as of 2009-02-28 15:31:31
Size: 3000
Editor: AnnikaLinke
Comment:
Revision 7 as of 2009-03-19 12:40:59
Size: 3612
Editor: AnnikaLinke
Comment:
Deletions are marked like this. Additions are marked like this.
Line 42: Line 42:
You should dump out the timing of critical events and the measured TR You should dump out the timing of critical events (e.g. starttime of a trial) and the measured TR
Line 44: Line 44:
    picstarttime=invoke(objSS,'SSGetTimer');     starttime=invoke(objSS,'SSGetTimer');
Line 74: Line 74:
       
== Collecting Responses ==

To collect responses in matlab using the button box add a code similar to this:

{{{
 tic
 resp=0;
 gotresp=false;
   while toc<rt_window
      if (~gotresp)
         resp=bitand(30,invoke(objSS,'GetResponse'));
         if (resp==samekey || resp==diffkey)
            gotresp=true;
         end;
       end;
    end;
}}}

This will collect the responses made by the subject during a pre-defined time interval (rt_window). You will also need to define which buttons the subject should press (in this example they are called samekey and diffkey).

Include(ScannerSyncTopBar)

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 (e.g. starttime of a trial) and the measured TR

    starttime=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

Using pretend mode

If you'd like to test code on a machine without the card, you may use a feature of ScannerSync called "pretend mode". To do this:

(1) When in pretend mode, don't do "Initialise", and instead issue a "SetPretendMode" command. So change the first block to something like

pretendmode=1;
% Create & initialise scanner sync object
objSS=actxserver('MRISync.ScannerSync');  %Create a scanner object
if (~pretendmode)
  invoke(objSS,'Initialize','') %Initialise the Keithley board and object
else
  invoke(objSS,'SetPretendMode',1) 
end;
invoke(objSS,'SetMSPerSample',2); %Set StartExperiment routines’ sampling 

(2) You'll then see a warning message when you get to the "StartExperiment" command, to which you should click "OK". If you're using the PsychToolbox and have already set up the screen, make sure that you only use the HideCursor command after the StartExperiment command, otherwise you won't be able to click OK.

Collecting Responses

To collect responses in matlab using the button box add a code similar to this:

 tic
 resp=0;
 gotresp=false;
   while toc<rt_window
      if (~gotresp)
         resp=bitand(30,invoke(objSS,'GetResponse'));
         if (resp==samekey || resp==diffkey)
            gotresp=true;
         end;
       end;
    end;

This will collect the responses made by the subject during a pre-defined time interval (rt_window). You will also need to define which buttons the subject should press (in this example they are called samekey and diffkey).

None: ScannerSyncMatlab (last edited 2013-03-08 10:28:25 by localhost)