Stall GetSecs Time

Hi PTB Community,


In my experiment I have breaks that occur after a certain amount of trials designed to "pause" the experiment (turn on and off EEG recording). However, I don't have something that subtracts the time occupied by the break from the experiment run time. Since my code outputs out time vectors into a log file, after every break there is a large difference between times made up of the duration of the break. I want to figure out a way to pause the time until a keypress is registered. So far, I have a function I call "mykb" that checks for this key press and is called in the break code, and looks like this:


function mykb

letter1=KbName('z');

while 1

    [keyIsDown,secs,keyCode]=KbCheck;

    if keyIsDown && keyCode(letter1)

        break

    end

end


The thing is, in my break code I also want it to stall the time until a key press is detected. The break code looks like this:


%% CHECK FOR BREAKS %%

        if ((mod(trialCounter,15) == 1) && (trialCounter ~= 1)) %dividing trialCounter by 15, and checking if the remainder of 1 (this checks for every trial one after every 15 trials pass)

            if strcmp(expType,'EEG')==1

                breakStartEvent = GetSecs;

                NetStation('Event',codes.breakStart,breakStartEvent,stimulus.codeDur,codes.breakStart,codes.codeVals.breakStart);

                NetStation('StopRecording');

            end

                text = 'Wait for experimenter...';

                Screen('FillRect',stimulus.window,backgroundColor);

                drawCenteredText(stimulus.window,stimulus.rect,text,textColor,44,defaultFont);

                Screen('Flip',stimulus.window);

                fprintf('Waiting for z-key to resume...\n');

                WaitSecs(.1); %needed for mykb to be called without moving on (there is a slight delay before mykb is called, therefore we need a slight wait)

                mykb;

            if strcmp(expType,'EEG')==1

                NetStation('StartRecording');

                breakEndEvent = GetSecs;

                NetStation('Event',codes.breakEnd,breakEndEvent,stimulus.codeDur,codes.breakEnd,codes.codeVals.breakEnd);

            end

            block = block+1; %move to next block

        end


Is there any way to stall the actual run time using by WaitSecs without having to set up break time anchors that subtract from time points I extract using GetSecs past the break? Does WaitSecs somehow have a drift free approach that can work with my function mykb?


Thanks PTB community for all the help so far! I would appreciate any insights or ideas offered :)


I'm not 100% sure what problem you are having. But from your brief description I think you're going at the solution in the wrong way. You almost always want to store GetSecs the way it returns and only in the analysis script subtract values off. Otherwise you risk having errors make the timeline completely useless.

In order to help you solve your problem I'm going to need a bit more information about what you're trying to accomplish.


Are you having a problem with your log file or your NetStation event stamps?
Are you trying to line up things between the log file and the EEG?






Justin

On Wed, Sep 14, 2016 at 1:04 AM, rkopstick@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Hi PTB Community,


In my experiment I have breaks that occur after a certain amount of trials designed to "pause" the experiment (turn on and off EEG recording). However, I don't have something that subtracts the time occupied by the break from the experiment run time. Since my code outputs out time vectors into a log file, after every break there is a large difference between times made up of the duration of the break. I want to figure out a way to pause the time until a keypress is registered. So far, I have a function I call "mykb" that checks for this key press and is called in the break code, and looks like this:


function mykb

letter1=KbName('z');

while 1

[keyIsDown,secs,keyCode]= KbCheck;

if keyIsDown && keyCode(letter1)

break

end

end


The thing is, in my break code I also want it to stall the time until a key press is detected. The break code looks like this:


%% CHECK FOR BREAKS %%

if ((mod(trialCounter,15) == 1) && (trialCounter ~= 1)) %dividing trialCounter by 15, and checking if the remainder of 1 (this checks for every trial one after every 15 trials pass)

if strcmp(expType,'EEG')==1

breakStartEvent = GetSecs;

NetStation('Event',codes. breakStart,breakStartEvent, stimulus.codeDur,codes. breakStart,codes.codeVals. breakStart);

NetStation('StopRecording');

end

text = 'Wait for experimenter...';

Screen('FillRect',stimulus. window,backgroundColor);

drawCenteredText(stimulus. window,stimulus.rect,text, textColor,44,defaultFont);

Screen('Flip',stimulus.window) ;

fprintf('Waiting for z-key to resume...\n');

WaitSecs(.1); %needed for mykb to be called without moving on (there is a slight delay before mykb is called, therefore we need a slight wait)

mykb;

if strcmp(expType,'EEG')==1

NetStation('StartRecording');

breakEndEvent = GetSecs;

NetStation('Event',codes. breakEnd,breakEndEvent, stimulus.codeDur,codes. breakEnd,codes.codeVals. breakEnd);

end

block = block+1; %move to next block

end


Is there any way to stall the actual run time using by WaitSecs without having to set up break time anchors that subtract from time points I extract using GetSecs past the break? Does WaitSecs somehow have a drift free approach that can work with my function mykb?


Thanks PTB community for all the help so far! I would appreciate any insights or ideas offered :)



Hi Justin,

Plainly put the task pauses the EEG recording during breaks. However the time for GetSecs keeps on going. I want the run time to also "pause", so when I continue to output files into the log file, it doesn't include the difference of breaks in between.

Does that make sense?

Ryan
I understand what you're asking for. But in order to help I need to know what you hope to achieve. The solution you're asking for in all likelihood will not solve your problem (because for example, there is an unknown delay on the EGI side between asking to start/stop and actually starting/stopping so even if you know how long PTB paused for you won't know how long the EGI paused).

Psychtoolbox has it's own consistent clock. The EGI netstation has it's own consistent clock. Those work fine. Because you have a problem with that and you're asking for a way to change the PTB clock it implies you're trying to synchronize the two systems.

In order to help I need to know what your goal is. That is: What do you need to have synchronized? Why do you want them to be the same and exactly what are you trying compare between the two systems? Stimulus display? Behavioural Responses? Key presses? Event labels? Eye movements?

There are a great many different things you can do, but there are also a great many different hidden problems. Synchronizing two independent computers at the millisecond level (as required by EEG) is not simple. Depending on the solution different problems (some of them hidden/insidious) can arise.



Justin


On Thu, Sep 15, 2016 at 1:33 AM, rkopstick@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Hi Justin,


Plainly put the task pauses the EEG recording during breaks. However the time for GetSecs keeps on going. I want the run time to also "pause", so when I continue to output files into the log file, it doesn't include the difference of breaks in between.

Does that make sense?

Ryan