Welcome! Log In Create A New Profile

Advanced

Stimulate duration is not equal to that set in code

Posted by Ming 
Stimulate duration is not equal to that set in code
April 16, 2021 12:57AM
I use the 6229 DAQ board, but I found the stimulate_duration is much longer than what I wanted.


fix1 = SingleTarget(joy_);
fix1.Target = CentPoint;
fix1.Threshold = 3;

holdCent = WaitThenHold(fix1);
holdCent.HoldTime = time_centHold;

stim1 = ClosedLoopStimulator(holdCent);
stim1.Channel = 1;
stim1.Waveform = [5 5 5 5 0 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0]';
stim1.Frequency = 4000;
tc = TimeCounter(stim1);
tc.Duration = 200;

but the output simulate duration is always 220ms. I tried to set duration at 170 or 180, but the output simulation duration is still not the same as I set. What's the reason lead to the consequence?
Re: Stimulate duration is not equal to that set in code
April 16, 2021 06:16AM
Please explain what you are trying to do with this code first. Do you understand what ClosedLoopStimulator does?

What is the stimulation duration you think you set and how did you measure the actual duration? I guess you meant "stimulation" when you said "simulation".
Re: Stimulate duration is not equal to that set in code
April 18, 2021 09:31PM
Sorry, I made a spell mistake, I want to express "stimulation". I wanted to do DBS (deep brain stimulation) on monkeys when they do behavioral tasks. I used the oscilloscope to measure the stimulate duration. The measurement result is showed in attachment.
Attachments:
open | download - pic_20210419092559.jpg (281.2 KB)
Re: Stimulate duration is not equal to that set in code
April 19, 2021 09:29AM
What I asked about was not the purpose of your study but the task scene you tried to build with the code. For example, you can say you want the subject to see the fixation cue for 500 ms and then maintain the fixation until a 200-ms stimulation is delivered or something like that.

The stimulation is working exactly as you programmed, so, unless you tell me what you actually intended to do, I cannot know what your complaint is about. ClosedLoopStimulator is not for the stimulation of a fixed duration, so I think you misunderstood something. Try Stimulator instead.

Is your ground connected to AO GND correctly? Why is the signal going down over time?
Re: Stimulate duration is not equal to that set in code
April 22, 2021 01:03AM
I'm sorry for my misunderstanding. I want to give the electric stimulation after the joystick back to he center and before the next visual stimuli is showed on the screen, that is, during this two period, about 200 ms. I use the joystick instead of eyetrack. I have used the Stimulator function but the oscilloscope showed stimulation only once, it shows the continuous stimulation only when I use ClosedLoopStimulator function. I checked the connection previously, the ground connected to AO GND correctly. I will check it again later. Thank you!
Re: Stimulate duration is not equal to that set in code
April 22, 2021 04:42PM
You seem to think that the voltage output is controlled by CPU moment to moment. That is not the case. As a general purpose machine, a Windows PC cannot provide that kind of timing accuracy that stimulation output requires, which is why a dedicated device, like the analog output board, is necessary. Also the waveform data should be preloaded in the device buffer to avoid delay in generating output. What NIMH ML does is just to tell the NI board when to start the stimulation. The rest is handled by the board.

Neither Stimulator nor ClosedLoopStimulator controls the stimulation duration by time. What determines the duration is the length of the waveform that you provide. Since the frequency of your waveform is 4000, you need a waveform of 800 data points to deliver a 200-ms stimulation. This long waveform will quickly increase the data file size, so I suggest using a MAT file.

The code you showed above does not work as you expected. Stimulation is supposed to be delivered after the joystick moves to the center, so two scenes are needed. First, prepare a waveform data like the following.
y = repmat([5 5 5 5 0 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0]',40,1);
fs = 4000;
save('waveform1.mat','y','fs');
Then you can write a script like this.
fix1 = SingleTarget(joy_);
fix1.Target = CentPoint;
fix1.Threshold = 3;
holdCent = WaitThenHold(fix1);
holdCent.WaitTime = 10000;
holdCent.HoldTime = time_centHold;
scene1 = create_scene(holdCent);

stim1 = Stimulator(null_);
stim1.Channel = 1;
stim1.Waveform = 'waveform1.mat';
scene2 = create_scene(stim1);

run_scene(scene1);
if holdCent.Success
    run_scene(scene2);
end
Re: Stimulate duration is not equal to that set in code
April 24, 2021 10:16PM
I got the correct waveform by following your script! Thanks a million!

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.