| Author |
Topic  |
|
|
sem
New Member

13 Posts |
Posted - Mar 16 2004 : 1:14:38 PM
|
We're trying to use Psychtoolbox (www.psychtoolbox.org) to trigger off of the scanner. Has anyone done this successfully with the BIAC scanners (specificially, the 4T)? If not, could someone explain how the scanner pulses are sent to the computer from which the paradigms are run, i.e., on what port, etc.? I know that groups at other facilities with other types of scanners have triggered Psychtoolbox experiments, so it must be possible. Any information would be appreciated.
Thanks, Sara Moore sem@geri.duke.edu |
|
|
deshmukh
BIAC Alum
 
40 Posts |
Posted - Apr 08 2004 : 4:33:50 PM
|
The NIDAQ board has been registered in Matlab, so you can use the following code to catch trigger pulses from the scanner.
ainidaq = analoginput('nidaq',1);
chan = addchannel(ainidaq,0);
duration = 2; % two second acquisition
set(ainidaq,'SampleRate',44100)
ActualRate = get(AIVoice,'SampleRate');
set(ainidaq,'SamplesPerTrigger',ActualRate*duration)
set(ainidaq,'TriggerChannel',chan)
set(ainidaq,'TriggerType','Software')
set(ainidaq,'TriggerCondition','Rising')
set(ainidaq,'TriggerConditionValue',5)
set(ainidaq,'TriggerFcn','mycallback');
start(ainidaq);
set(ainidaq,'TriggerFcn','mycallback') binds the Trigger to a callback function which executes any Matlab functions you need (eg. Psychtoolbox calls) in the presence of a trigger.
For eg. to determine the system time when a trigger occurs you would use
function mycallback(obj,event) time = datestr(now,0)
Hope that helps
|
 |
|
|
sem
New Member

13 Posts |
Posted - Apr 08 2004 : 4:39:55 PM
|
Thanks! I have a couple of questions. First, the reference to "AIVoice" in the sample code -- is that supposed to be "ainidaq"? Also, is "duration" essentially TR, or is it a separate variable?
Thanks again, Sara |
 |
|
|
deshmukh
BIAC Alum
 
40 Posts |
Posted - Apr 08 2004 : 5:07:42 PM
|
"duration" specifies the amount of time that the device should acquire data after the trigger signal has been detected. This is useful if you are using the callback to acquire data through Matlab. However, if you want to use the trigger as an automated start point, it really has no significance. Also append the following cleanup code to free "ainidaq", post the trigger event.
waittilstop(ainidaq,26);
delete(ainidaq)
clear ainidaq
The second argument to waittilstop specifies how long the device should wait for the trigger signal after the starting "ainidaq".
"AIVoice" should be "ainidaq", sorry about that |
 |
|
|
jim.voyvodic
BIAC Faculty
   
138 Posts |
Posted - Apr 08 2004 : 5:13:38 PM
|
Sara & Imran, Glad to see that Matlab looks like it's working. Reading over the above messages it seems to me that the sample code is not appropriate for triggering a fMRI scan. First, the CHAN has to be 2, not 0 (this is scanner specific but happens to be 2 on both scanners). Second, the duration and sampling rate seem wrong, or at least misleading. If all you want is to get a trigger pulse you want SamplesPerTrigger to be 1 (so duration and samplerate are irrelevant). If you request more than 1 sample point you will have to look closely at when your acquisition terminates, because with a duration of 2s you might get the triggered acquisition to actually be reported to you at the end, i.e., 2 secs after the actual trigger pulse.
These details will best be sorted out by trial and error I suppose.
Jim
|
 |
|
|
deshmukh
BIAC Alum
 
40 Posts |
Posted - Apr 08 2004 : 5:36:36 PM
|
The trigger acquisition event is set to the rising edge, this is the event that executes the callback function. Any following samples of the trigger do not result in events, this includes the falling edge of the signal.
Imran |
 |
|
|
sem
New Member

13 Posts |
Posted - Apr 22 2004 : 1:56:45 PM
|
I successfully tested the trigger today (both in a Psychtoolbox script and from the Matlab command line). Here is the code that worked:
ainidaq = analoginput('nidaq',1); chan = addchannel(ainidaq,2); duration = 2; % two second acquisition set(ainidaq,'SampleRate',44100); ActualRate = get(ainidaq,'SampleRate'); set(ainidaq,'SamplesPerTrigger',ActualRate*duration); set(ainidaq,'TriggerChannel',chan); set(ainidaq,'TriggerType','Software'); set(ainidaq,'TriggerCondition','Rising'); set(ainidaq,'TriggerConditionValue',1); set(ainidaq,'TriggerFcn','mycallback'); start(ainidaq);
The correct channel was 2 (as Jim mentioned above). The Data Acquisition Toolbox seems to acquire data for the 'duration' that you set, but this acquisition it does not seem to influence when the 'TriggerFcn' runs. In other words, the 'TriggerFcn' begins immediately after the trigger occurs, regardless of the value of 'duration' (as Imran mentioned above). I changed 'TriggerConditionValue' to 1 because the signal never actually reached 5 (I tested this on the Win XP computer at the 4T); the maximum voltage recorded from the NI board when I tested it was around 4.35 or 4.4.
Thanks for all the help, Sara |
 |
|
|
deshmukh
BIAC Alum
 
40 Posts |
Posted - Mar 06 2007 : 4:43:55 PM
|
waittilstop has been deprecated in the newer ainidaq libraries. Please change all calls to that function with "wait".
Replace waittilstop(ainidaq,26); with wait(ainidaq,26);
|
 |
|
| |
Topic  |
|
|
|