Welcome! Log In Create A New Profile

Advanced

How to give stimulation while detecting signals?

Posted by Ming 
How to give stimulation while detecting signals?
August 02, 2021 11:16AM
Hello!
I need to counting pulses to trigger the stimulation. That is, when detecting 50 pulses then giving a continuous current stimulation until detecting 60 pulses. To my understanding, the current can only set its length previously, not controlled by time or numbers. Can it be controlled like this?

The complete scene is the EEG/fMRI experiment. The TR pulse (just a pulse) gives every 2s, while the stimulation need be outputted after the 50th TR and stopped after 60th TR and then circulate. In case of the timing error accumulation, we need trace every TR to guarantee the accurate stimulation time rather than giving the stimulation after "idle(100000);" or write long continuous 0 equals to 100s (50*2s) before "stim_waveform.mat". My seniors told me I should use two NI boards, one for counting TR numbers and when it reaches 50 then giving an output, the other for stimulation after receiving the signal from the formal board. Does this method work? If I just use one board, it must be an interval between detecting pulses and giving stimulation and there will be an accumulative timing error, isn't it? How can I control the stop time by the counting numbers or just set a stimulation wave which length equal to 20s (10 * 2s)?

Much thanks!
Re: How to give stimulation while detecting signals?
August 05, 2021 01:47AM
Hello there!

I suggest using the ClosedLoopStimulator class from the closed loop example in NIMH ML.

You just need to set up some internal counting variables in the properties section and update them every time the screen is refreshed (by running a line inside the continue_() function checking whether there has been a pulse and increasing the counter by 1 if received, for instance).

Once your internal counting variable has reached 50 and still within the continue_() function, start the stimulation

trigger(obj.AO);

and once it reaches 60 stop it

stop(obj.AO);

and restart the counter by setting it to 0.

You can use one board for both sending and receiving, in theory.
Re: How to give stimulation while detecting signals?
August 06, 2021 01:37AM
Ming,

Analog input and output of an NI board work independently, so there is no difference whether you use two boards or one.

You want customized control beyond what the framework can provide, so you need to program this yourself. The scene framework (Timing script v2) analyzes input frame by frame, so it is not possible to detect the 50th pulse as soon as it occurs (see this). Timing script v1 does not have a convenient way to count pulses, such as PulseCounter.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.