Specific tasks and event coding

Monkeys Kurt and Pele have been trained and subsequently recorded in three different tasks paradigms:

  • Attentional Task
  • Resting State
  • Receptive Field Mapping

Both monkeys were trained in a detection task paradigm. A trial started when the monkey touched a bar and directed its gaze within the fixation spot on the computer screen. While the monkey kept fixation, two stimuli (4 deg diameter sinusoidal gratings, drifting unidirectionally, 4 deg; of eccentricity) appeared. One of the gratings was cued to be the target stimulus. We used trial-by-trial cueing of selective attention. The general task of the monkey was to release the bar between FIXME: (is this 150 and 650 ms or 100 and 700 ms???) 150 and 650 ms after a change in the target’s orientation. That change in orientation could occur at an unpredictable moment in time. Successful trial completion was rewarded with grape juice. If the monkey released the bar too early or if it moved its gaze out of the fixation window, the trial was immediately aborted and followed by a timeout and a repeat of the trial. Figure 1 shows the experimental protocol and the sequence of the most important trial events.

Monkeys were trained in two variants of the task. One is denominated the far configuration attentional task, in which the stimuli are positioned in two opposite sites of the visual field. One stimulus is contralateral to the recording hemisphere, while the other is ipsilateral to the recording hemisphere, and the close configuration in which, one stimulus is positioned in V1 and V4 overlapped receptive fields, while the other lies in the V1 RF. Examples of both configuration are provided below.

Details of Cortex Trial Event Timing

  1. Cortex initiates the trial and begins a 10 sec interval waiting for the monkey to engage the lever.
  2. If the lever is engaged during the 10 sec interval the program continues, if not the trial is terminated and a new trial is initiated.
  3. Cortex displays the grey fixation spot and commences a 6 sec interval during which the monkey must fixate the spot, if fixation is not achieved the trial is terminated and a new trial initiated.
  4. Once fixation is established there is a fixed interval of 800 ms before stimulus onset.
  5. Following stimulus onset the fixation spot may change color and either stimulus may change shape. The fixation spot may change to yellow or blue. This occurs for KURT at a uniform random interval between 1000 and 1500 ms, and for PELE at a uniform random interval between 800 and 1300 ms after the onset of the stimuli. Stimulus changes are defined by a change in the shape of the drifting grating. This occurs at a uniform random interval between 750 and 5000 ms post-stimulus onset for KURT and between 750 and 4000 ms for Pele (the stimulus change consists of a change in shape of the grating (bending) which evolves over a 100 ms interval as linear → bent → linear). The target and distracter changes are always separated by at least 300 ms in Pele. NOTE: Not all of these events will occur during each trial since the trial may terminate before the planned onset of these events, i.e. the target stimulus may appear before the cue, and thus the trial may terminate before the cue change is scheduled to occur, for example.
  6. When the target stimulus changes the monkey has an interval from 100 to 700 ms to respond. If a response is made within this interval then a correctResponse trigger code is written to the events file and the monkey is rewarded.

Event coding

This code is used in the Cortex CTX file of the task. Details of the stimulation program could be obtained from here

% some 'offset' values
trigdef.trlinf                      = 8192;
trigdef.trlnum                      = 4096;
trigdef.conditionID                 = 18000;

% define whether stiminfo is for target or distracter
trigdef.stimstartframeinfo          = 500 + trigdef.trlinf;
trigdef.stiminfo_T                  = 340 + trigdef.trlinf; % denotes in the event file that the following 2 triggers (X/Y coordinates) correspond to the TARGET
trigdef.stiminfo_D                  = 341 + trigdef.trlinf; % denotes in the event file that the following 2 triggers (X/Y coordinates) correspond to the DISTRACTER

% position information of the stimulus
trigdef.posGain                     = 100;
trigdef.posX                        = 12288;
trigdef.posY                        = 16384;

% error code
trigdef.Error_in_Trial              = 30 + trigdef.trlinf;

% triggers related to behavior
trigdef.noFixationStart             = 201 + trigdef.trlinf; % Fixation was not achieved during the wait for fixation period
trigdef.noLeverDown                 = 203 + trigdef.trlinf; 
trigdef.earlyResponse               = 205 + trigdef.trlinf; % generated when the response has occurred prior to the 500 ms response window from 150 ms post TARGET change to 650 ms  
trigdef.brokeEarlyFixation          = 206 + trigdef.trlinf; % Fixation was broken before the TARGET stimulus change
trigdef.brokeFastFixation           = 208 + trigdef.trlinf; % Fixation was broken after the TARGET stimulus change
trigdef.brokeFixationBeforeResponse = 209 + trigdef.trlinf;
trigdef.correctResponse             = 210 + trigdef.trlinf; % generated when the monkey responds within the response window and can be used to determine reaction time
trigdef.lateResponse                = 211 + trigdef.trlinf; % generated when the response occurs after the TARGET change but prior to the beginning of the response window OR the response was within a window 800 ms after the response window terminated (THIS MAY BE A BUG IN THE CORTEX CODE)
trigdef.noResponse                  = 212 + trigdef.trlinf; % no response was recorded during the trial

% triggers related to stimuli on screen
trigdef.disp_fix_ON                 = 300 + trigdef.trlinf; % Fixation spot ON (This occurs at the very beginning of the trial
                                                            % and represents the start of the baseline period)
trigdef.disp_fix_CHANGE1            = 301 + trigdef.trlinf; % change Fixation to YELLOW (This trigger represents the CUE ONSET)
trigdef.disp_fix_CHANGE2            = 302 + trigdef.trlinf; % change Fixation to BLUE (This trigger represents the CUE ONSET)
trigdef.disp_fix_OFF                = 303 + trigdef.trlinf; % fixation OFF  (This event occurs at the very end of the trial)
trigdef.disp_T0_ON                  = 304 + trigdef.trlinf; % TARGET stim ON
trigdef.disp_T0_CHANGE1             = 305 + trigdef.trlinf; % TARGET change (when it is YELLOW)
trigdef.disp_T0_CHANGE2             = 306 + trigdef.trlinf; % TARGET change (when it is BLUE) 
trigdef.disp_T0_OFF                 = 307 + trigdef.trlinf; % TARGET OFF
trigdef.disp_T1_ON                  = 308 + trigdef.trlinf; % DISTRACTER stim ON 
trigdef.disp_T1_CHANGE1             = 309 + trigdef.trlinf; % DISTRACTER change (when it is BLUE)
trigdef.disp_T1_CHANGE2             = 310 + trigdef.trlinf; % DISTRACTER change (when it is YELLOW)
trigdef.disp_T1_OFF                 = 311 + trigdef.trlinf; % DISTRACTER stim OFF

% some other stuff
trigdef.beginIntertrialInterval     = 400 + trigdef.trlinf;
trigdef.endIntertrialInterval       = 401 + trigdef.trlinf;
trigdef.trialStart                  = 403 + trigdef.trlinf;
trigdef.trialEnd                    = 404 + trigdef.trlinf; 
trigdef.beginWaitForFixation        = 405 + trigdef.trlinf;
trigdef.start_fixation              = 406 + trigdef.trlinf; % denotes that the monkey has achieved Fixation
trigdef.beginWaitForLeverDown       = 407 + trigdef.trlinf;
trigdef.start_LeverDown             = 408 + trigdef.trlinf;
trigdef.beginWaitForResponseEvent   = 409 + trigdef.trlinf;
trigdef.beginBaselineDelay          = 410 + trigdef.trlinf;
trigdef.endBaselineDelay            = 411 + trigdef.trlinf;
trigdef.start_Display               = 411 + trigdef.trlinf;
trigdef.responseEvent               = 413 + trigdef.trlinf; % target change time              
trigdef.rewardStart                 = 414 + trigdef.trlinf;
trigdef.rewardStop                  = 415 + trigdef.trlinf;
trigdef.doubleReward                = 416 + trigdef.trlinf;
trigdef.encodeEyeStart              = 416 + trigdef.trlinf;
trigdef.encodeEyeStop               = 417 + trigdef.trlinf;
trigdef.MAINBEGIN                   = 450 + trigdef.trlinf;
trigdef.MAINEND                     = 451 + trigdef.trlinf;

You can make a visual representation of the trigger codes along the time axis by using the following code. In the figure, you can zoom in on the relevant part of the time axis

load ku_046_02_mt_k_006_ds/events.mat

smp = [event.sample];
val = [event.value];

figure
plot(smp, val, '.');
xlabel('sample number');
ylabel('trigger value');

% also display the textual description of each trigger
fn = fieldnames(trigdef);
for i=1:length(smp)
  for j=1:length(fn)
    if trigdef.(fn{j})==val(i)
      text(smp(i), 0, fn{j});
      fprintf('trigger %d with value %d corresponds to %s\n', i, val(i), fn{j});
    end
  end
end

The following code extracts the trial definition from a given event structure (which belongs to a particular recording session), in combination with a structure array with the trigger definitions (see above). This example extracts for a 'far configuration' session those trials in the 'attend in' condition, where the attended stimulus was presented in the right hemifield. Moreover, trials had to fulfill the following conditions:

  1. both target and distractor had to be present
  2. target change occurred only after attentional cue had been given

If both these conditions are met, a trial was defined to run between the attentional cue + 200 ms, until the earliest stimulus change (could also be a distractor change).

function [trl, event] = trialfun_monkey_general(cfg)

cfg = checkconfig(cfg, 'required', {'event' 'trigdef'});

%define trigger definitions and events locally
event   = cfg.event;
trigdef = cfg.trigdef;

%convert event information to vectors with values and samples
value  = [event.value]';
sample = [event.sample]';

%get start and end indices of the trials
begtrial = find(value == trigdef.trialStart);
endtrial = find(value == trigdef.trialEnd  );

%the following has to do with the fact that recording could start or end in the middle of a trial
%discard the first endsample or last beginsample if this was the case
if endtrial(1)   < begtrial(1),   endtrial(1)   = []; end
if begtrial(end) > endtrial(end), begtrial(end) = []; end

%now loop over all trials and check whether the sequence of triggers
%within the trial are OK
trl = [];
for i = 1:numel(begtrial)
    ok      = true;
    trigval =  value(begtrial(i):endtrial(i)); %all events within this trial
    trigsmp = sample(begtrial(i):endtrial(i));%sample indices of events within this trial

    %this seems to be some hard coded stuff
    tnum_real = trigval(2) - cfg.trigdef.trlnum;
    cnd_real  = trigval(3) - cfg.trigdef.conditionID;
        
    %only allow correct trials
    if ok && any(trigval == trigdef.correctResponse),
        %still ok
    else
        ok = false;
    end
    
    %determine which stimulus is target
    if ok && any(trigval == trigdef.stiminfo_T)
        tmp     = find(trigval == trigdef.stiminfo_T);
        targetX = trigval(tmp+1);
        targetY = trigval(tmp+2);
    end
    
    %determine which stimulus is distractor
    if ok && any(trigval == trigdef.stiminfo_D)
        tmp   = find(trigval == trigdef.stiminfo_D);
        distX = trigval(tmp+1);
        distY = trigval(tmp+2);
    end
    
    %for the 'far' configuration sessions, when targetX>distX the trial
    %belongs to the 'attention in' condition
    if ok && targetX > distX
        %still ok
    else
        ok = false;
    end
    
    %only allow trials in which both the stimulus and distractor were on
    if ok && any(trigval == trigdef.disp_T0_ON) && any(trigval == trigdef.disp_T1_ON),
        %still ok
    else
        ok = false;
    end
    
    %only allow trials in which the attentional cue has been given
    if ok && any(trigval == trigdef.disp_fix_CHANGE1 | trigval == trigdef.disp_fix_CHANGE2)
        indx1  = trigsmp(ismember(trigval, [trigdef.disp_fix_CHANGE1 trigdef.disp_fix_CHANGE2]));
        offset = 200; % hard coded 200 ms offset (assuming fsample to be 1000);
    
        %apparently there could be trials with more than one change
        if numel(indx1)>1, ok = false; end   
    else
        ok = false;
    end
    
    %then find a stimulus or distractor change, whichever comes first 
    if ok && any(trigval == trigdef.disp_T0_CHANGE1 | trigval == trigdef.disp_T0_CHANGE2)
        indx2 = inf;
        indx2 = trigsmp(ismember(trigval, [trigdef.disp_T0_CHANGE1 trigdef.disp_T0_CHANGE2]));
        
        %apparently there could be trials with more than one change
        if numel(indx2)>1, ok = false; end
    else
        ok = false;
    end
    
    if ok && any(trigval == trigdef.disp_T1_CHANGE1 | trigval == trigdef.disp_T1_CHANGE2)
        tmp   = inf;
        tmp   = trigsmp(ismember(trigval, [trigdef.disp_T1_CHANGE1 trigdef.disp_T1_CHANGE2]));
        
        %apparently there could be trials with more than one change
        if numel(tmp)>1, ok = false; end
        indx2 = min(indx2, tmp(1)); %if tmp has >1 element the indexing is inconsequential
        %because the trial will not be accepted anyhow
    else
        %there is no consequence if there is no change in distractor
    end
    
    if ok && indx2 < indx1+offset
        %change in stimulus occurred before cue, or within offset samples after cue
        ok = false;
    end
    
    if ok
        begsample = indx1 + offset;
        endsample = indx2;
        trloffset = -offset;
        newtrl    = [begsample endsample trloffset cnd_real tnum_real];
        trl       = [trl; newtrl];
    end
end

In the attentional task, two experimental configurations were presented. These are the NEAR and FAR configurations. In each configuration 2 stimuli are presented, which are located in the same hemifield for the NEAR configuration, and opposite hemifields for the FAR configuration.

FAR configuration:

For the FAR configuration attention is directed to either:

1) a TARGET stimulus that is randomly assigned to the hemifield contralateral to the grid, in which attention is focused on the stimulus which is presented in the right hemifield (ATTEND CONTRA) and attention ipsilateral or,

2) a TARGET stimulus that is randomly assigned to the hemifield ipsilateral to the grid, in which attention is focused on the stimulus which is presented in the left hemifield (ATTEND CONTRA) and attention ipsilateral (friendly reminder: stimuli in one hemifield are processed in the opposite hemisphere :-)).

In both conditions a DISTRACTOR stimulus is present in the hemifield opposite the TARGET. Additionally conditions are included where only one stimulus is presented. The table below outlines the configuration for these conditions.

For the NEAR configuration attention is manipulated between 2 locations in one visual hemifield. Thus the label of TARGET and DISTRACTOR are randomly assigned between the two locations. Based on the location of our grid in the left hemisphere, these locations are always in the right visual field. The corresponding areas of the recording grid with RFs that match these locations are termed V1a and V1b (See figure).

Like for the FAR configuration, there are conditions where only one of the stimuli is shown. The table below outlines the numbering of these conditions.

The design of the task also include another 2 dimensions (color and temporal relation between TARGET and DISTRACTOR) that are orthogonal to the two conditions of interest, but must be considered in the internal structure of the task. Then, each attentional condition contains the following combination of features between the two additional dimensions:

Target First Target Second
Blue BT1st BT2nd
Yellow YT1st YT2nd

The resulting 8 conditions (4 for attention contralateral/V1a and 4 for attention ipsilateral/V1b) are codified in the Cortex script that controls the presentation of the task. Additionally, there are the 8 additional conditions that resemble the attentional ones but where only one stimulus is presented. The purpose of these conditions is to have an additional contrast between presence and absence of the stimulus. These conditions are used as a control to evaluate visual properties of the stimuli in the RF. Each condition has arbitrarily received a number that label it. During the execution of the script, Cortex randomly selects a condition number and accordingly, creates the proper sequence of events to present for that particular condition. The description and identification number of the conditions are detailed below:

Number Description
1 Fixation
2-3 Not used
4 Att Contralateral/V1a, Target Changes First, Target is Blue
5 Att Ipsilateral/V1b, Target Changes First, Target is Blue
6 Att Contralateral/V1a, Target Changes Second, Target is Blue
7 Att Ipsilateral/V1b, Target Changes Second, Target is Blue
8 Att Contralateral/V1a, Target Changes First, Target is Yellow
9 Att Ipsilateral/V1b, Target Changes First, Target is Yellow
10 Att Contralateral/V1a, Target Changes Second, Target is Yellow
11 Att Ipsilateral/V1b, Target Changes Second, Target is Yellow
12-19 Not used
20 Att Contralateral/V1a, Target is Blue, One Stimulus
21 Att Ipsilateral/V1b, Target is Blue, One Stimulus
22 Att Contralateral/V1a, Target is Blue, One Stimulus
23 Att Ipsilateral/V1b, Target is Blue, One Stimulus
24 Att Contralateral/V1a, Target is Yellow, One Stimulus
25 Att Ipsilateral/V1b, Target is Yellow, One Stimulus
26 Att Contralateral/V1a, Target is Yellow, One Stimulus
27 Att Ipsilateral/V1b, Target is Yellow, One Stimulus

Note that the original trigger values have an offset of 8192, so one should add 8192 to the numbers in the table above to be able to find them back in the trigger sequence.

The Generic Trial Function (see above) generates a trl matrix which contains the condition number of each trial in the 4th column. Yet, it extracts the necessary information (as to whether mark that trial as an interesting one, or not) from the trigger sequence, rather than using the cnd_real trigger. If you run the trialf_monkey_general, you'll see that the 4th column of the trl-matrix only contains even-valued numbers. This is in accordance with what the trialfun was designed to achieve: to extract the 'Attend in' (=Att contralateral) trials. Of course, one could make direct use of the cnd_real trigger in the trialfun as well. An example is provided below:

function [trl, event] = trialfun_monkey_general2(cfg)

cfg = checkconfig(cfg, 'required', {'event' 'trigdef'});

%define trigger definitions and events locally
event   = cfg.event;
trigdef = cfg.trigdef;

%convert event information to vectors with values and samples
value  = [event.value]';
sample = [event.sample]';

%get start and end indices of the trials
begtrial = find(value == trigdef.trialStart);
endtrial = find(value == trigdef.trialEnd  );

%the following has to do with the fact that recording could start or end in the middle of a trial
%discard the first endsample or last beginsample if this was the case
if endtrial(1)   < begtrial(1),   endtrial(1)   = []; end
if begtrial(end) > endtrial(end), begtrial(end) = []; end

%now loop over all trials and check whether the sequence of triggers
%within the trial are OK
trl = [];
for i = 1:numel(begtrial)
    ok      = true;
    trigval =  value(begtrial(i):endtrial(i)); %all events within this trial
    trigsmp = sample(begtrial(i):endtrial(i));%sample indices of events within this trial

    %this seems to be some hard coded stuff
    tnum_real = trigval(2) - cfg.trigdef.trlnum;
    cnd_real  = trigval(3) - cfg.trigdef.conditionID;

    %only allow trials in which only one stimulus was presented
    if ok && any(ismember(cnd_real, cfg.trigdef.trlinf + [20:27]))
        %still ok
    else
        ok = false;
    end
    
    %only allow correct trials
    if ok && any(trigval == trigdef.correctResponse),
        %still ok
    else
        ok = false;
    end
    
    %only allow trials in which the attentional cue has been given
    if ok && any(trigval == trigdef.disp_fix_CHANGE1 | trigval == trigdef.disp_fix_CHANGE2)
        indx1  = trigsmp(ismember(trigval, [trigdef.disp_fix_CHANGE1 trigdef.disp_fix_CHANGE2]));
        offset = 200; % hard coded 200 ms offset (assuming fsample to be 1000);
    
        %apparently there could be trials with more than one change
        if numel(indx1)>1, ok = false; end   
    else
        ok = false;
    end
    
    %then find a stimulus or distractor change, whichever comes first 
    if ok && any(trigval == trigdef.disp_T0_CHANGE1 | trigval == trigdef.disp_T0_CHANGE2)
        indx2 = inf;
        indx2 = trigsmp(ismember(trigval, [trigdef.disp_T0_CHANGE1 trigdef.disp_T0_CHANGE2]));
        
        %apparently there could be trials with more than one change
        if numel(indx2)>1, ok = false; end
    else
        ok = false;
    end
    
    if ok && any(trigval == trigdef.disp_T1_CHANGE1 | trigval == trigdef.disp_T1_CHANGE2)
        tmp   = inf;
        tmp   = trigsmp(ismember(trigval, [trigdef.disp_T1_CHANGE1 trigdef.disp_T1_CHANGE2]));
        
        %apparently there could be trials with more than one change
        if numel(tmp)>1, ok = false; end
        indx2 = min(indx2, tmp(1)); %if tmp has >1 element the indexing is inconsequential
        %because the trial will not be accepted anyhow
    else
        %there is no consequence if there is no change in distractor
    end
    
    if ok && indx2 < indx1+offset
        %change in stimulus occurred before cue, or within offset samples after cue
        ok = false;
    end
    
    if ok
        begsample = indx1 + offset;
        endsample = indx2;
        trloffset = -offset;
        newtrl    = [begsample endsample trloffset cnd_real tnum_real];
        trl       = [trl; newtrl];
    end
end

Using the 4th column in the trl-matrix can be done as follows:

%suppose you have a data-structure in memory
trl = findcfg(data.cfg, 'trl');

%suppose you are interested in the following conditions;
conditions = [4 6 8 10];

cfg        = [];
cfg.trials = find(ismember(trl(:,4),conditions));
cfg.xxx
data = ft_preprocessing(cfg, data) or freq = ft_freqanalysis(cfg, data) or tlck = ft_timelockanalysis(cfg, data);

The aim of this task was to explore the different receptive fields (RFs) in areas V1 and V4 that we were able to record using the electrode grid, in order to locate visual stimuli for the attention task. A classic RF mapping paradigm task was used. The monkey must hold the lever during the complete trial and hold its gaze to a green fixation point at the center of the screen. Monkeys must detect a change in the color of the fixation point and release the lever to obtain reward. A series of unidirectional gratings of 1 deg diameter were presented for 1 second in different regions of the visual field, while the monkey fixate. The figure, shows a set of several positions, arranged in a polar matrix that were tested in one sessions. The subsequent figure shows a particular receptive field in one V1 electrode. The event coding of this task is the same that it is used for the attentional paradigm. The trial function must take in consideration the position of each stimuli.

function [trl, event] = trialfun_monkey_RF(cfg)

cfg = checkconfig(cfg, 'required', {'event' 'trigdef'});

%define trigger definitions and events locally
event   = cfg.event;
trigdef = cfg.trigdef;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
offset  = cfg.offset;
% define a range of values for the subtrials
stimOnsetEventRange = [trigdef.stimOnsetEventLow trigdef.stimOnsetEventHigh]; 
posGain = trigdef.posGain;                           
posX    = trigdef.posX;                            
posY    = trigdef.posY;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%convert event information to vectors with values and samples
value  = [event.value]';
sample = [event.sample]';

%get start and end indices of the trials
begtrial = find(value == trigdef.trialStart);
endtrial = find(value == trigdef.trialEnd  );

%the following has to do with the fact that recording could start or end in the middle of a trial
%discard the first endsample or last beginsample if this was the case
if endtrial(1)   < begtrial(1),   endtrial(1)   = []; end
if begtrial(end) > endtrial(end), begtrial(end) = []; end

%now loop over all trials and check whether the sequence of triggers
%within the trial are OK
trl = [];
for i = 1:numel(begtrial)
    ok      = true;
    trigval = value(begtrial(i):endtrial(i));  %all events within this trial
    trigsmp = sample(begtrial(i):endtrial(i)); %sample indices of events within this trial
       
    %only allow correct trials
    if ok && any(trigval == trigdef.correctResponse),
        %still ok
    else
        ok = false;
    end
        
    %only allow trials in which the stimulus was on
    if ok && any(trigval == cfg.trialdef.stim) 
        %still ok
    else
        ok = false;
    end
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % look for subtrials
    stim_T0_ON    = find(trigval == trigdef.disp_T0_ON);
    stimOnsetInds = find(trigval>=stimOnsetEventRange(1) & trigval<stimOnsetEventRange(2));
    begsample     = trigsmp(stimOnsetInds);
    endsample     = trigsmp(stimOnsetInds) + offset;
    begsamplebl   = trigsmp(stim_T0_ON) - offset;
    endsamplebl   = trigsmp(stim_T0_ON);
    
    stimPosX = ( double(trigval(stimOnsetInds+1)) - double(posX)) / double(posGain);
    stimPosY = ( double(trigval(stimOnsetInds+2)) - double(posY)) / double(posGain);
    
    % decode the condition number
    [tf,loc] = ismember([stimPosX stimPosY],cfg.positions,'rows');
    if tf
      cond = loc;
    else
      ok = false; % unknown position or wrong positions file
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    if ok
      for vv=1:length(stimOnsetInds)
        if endsample(vv) < sample(endtrial(i)) % if last trial too short exclude it!
        % define a trl which contains subtrials samples in position 1-3
        % and baseline in position 4-6, position 7 and 8 are the samples of
        % CORTEX trial and position 9 is the condition (or position in the monitor)
          newtrl    = [begsample(vv) endsample(vv) 0 begsamplebl endsamplebl -offset sample(begtrial(i)) sample(endtrial(i)) cond(vv)];
          trl=[trl; newtrl];
        end
      end
    end
    
end

In this particular set of experiments, monkeys are recorded in a quiet, dark room with no stimulation. Therefore, the data structure obtained from this paradigm does not contain any event and/or trigger. Commonly, resting state recordings are scheduled at the beginning of every week and/or during periods in which the monkey is not motivated to play another task. Eventually, some of these recordings also contains periods in which the monkey falls asleep. This particularity has been exploited in one of the current running projects (P3, Ingrid Niewenhuis).

During the initiation of each trial, one of the stimuli was randomly assigned as the target and the other as the distracter. The monkeys were only rewarded for responses to a change of the target stimulus, as indicated by the cue colour, and thus suppressed responses to the distracter stimulus (Kurt 40-48 mt_k_006, Pele 28 - 39 mt_p_004). It was possible for the target or distracter to change prior to the onset of the cue. In this instance, the monkey was unable to determine which stimulus was the target or distracter, and thus was forced to operate at a chance level. Behavioral analysis revealed that during this pre-cue interval both monkeys spontaneously adopted a preference for the blue stimulus, responding only to changes of the blue grating, while ignoring changes of the yellow grating.

Fig. 1. (A) The monkey fixated the white fixation spot. Upon the appearance of the stimuli, covert spatial attention was deployed to the hemifield containing the blue drifting grating. (B) The fixation spot changed to yellow or blue indicating the stimulus to which covert spatial attention should be deployed. This involved either maintaining attention upon the blue grating or switching to the yellow grating. (C) Target or distracter change shape.

Fig. 2. Upon the change of the fixation spot, four possible scenarios exist. (A) when the blue grating is in the hemifield contralateral to the recording grid and the fixation spot changes to blue the monkey must maintain attention to the blue grating. (B) when the blue grating is in the field contralateral to the recording grid and the fixation spot changes to yellow the monkey must shift attention to the yellow grating. (C) as in (A) the monkey must maintain attention to the blue grating, but in the ipsilateral hemifield. (D) as in (B) the monkey must shift attention to the yellow grating, but from the hemifield ipsilateral to the recording grid.

Based on the four scenarios described in Fig. 2. attentional deployment may be isolated via the following contrast of conditions:

(A + D) - (B + C);

Alternatively, the difference between attentional shifting and maintenance may be revealed via:

(D + B) - (A + C)