Specifying bad segments

Hello Experts,

I will like to inquire if I can specify the range of segments to exclude from my data. In other words, instead of manually specifying bad segments, is there a way to specify (more like type) a range of the data that is bad.

I don't believe this is possible: the range duration can be driven by certain objective properties of the data though, such as amplitude, variance, etc.

Thank you. So in other words, I will need to manually specify the bad segment by dragging the slider?

To extend @Sylvain's answer. This is not possible through the GUI.

However, it is possible to indicate bad segments as extended events through scripting by adding information to the events structure: https://neuroimage.usc.edu/brainstorm/Tutorials/EventMarkers#On_the_hard_drive

The example below shows how to add bad segments to a Link to raw file
The added bad segments are from 1s to 2s and 8s to 10s

%% ===== MANUALLY BAD EXTENDED EVENTS (SEGMENTS) =====
    % Load recording file
    sMat = in_bst_data(sFile.FileName, 'F');
    % Index for new event
    iEvt = length(sMat.F.events) + 1;   
    % "bad_" indicates that it will be considered as bad event
    sMat.F.events(iEvt).label = 'bad_manual';
    % Color for the event in the GUI       
    sMat.F.events(iEvt).color = [0.8, 0, 0]; %RGB
    % Times for extended events
    sMat.F.events(iEvt).times = [1, 8; 2, 10]; % [2 x Nevents], first row = start, second row = end
    % Other required fields
    sMat.F.events(iEvt).epochs  = ones(1, size(sMat.F.events(iEvt).times, 2));  
    sMat.F.events(iEvt).channels = cell(1, size(sMat.F.events(iEvt).times, 2));
    sMat.F.events(iEvt).notes    = cell(1, size(sMat.F.events(iEvt).times, 2)); 
    % Save modified file  
    bst_save(file_fullpath(sFile.FileName), sMat, 'v6', 1);

Note that for considering these extended events as bad, the event label has the string "bad_", as indicated in: Tutorials/BadSegments - Brainstorm

Another example for manually creating events can be found here:

1 Like

Thank you for your response
Much appreciated

I seem to be having this error when I use the code. Please help

image

Could you provide more context about the error and how to reproduce it?

Also, you can find more information regarding scripting in Brainstorm in this tutorial:
Tutorials/Scripting - Brainstorm

I just provided the code i wanted to use to apply it in brainstorm. I only changed the portion highlighted in red and tried running it. I got this error

The trouble in the code is that sFiles is not an array structure, but it is a cell array with the file name.

To make the code work, call the functions with the filename:
In lines 12 and 26, substitute sFiles.FileName with sFiles{1}

Keep in mind that:

[The input of the process] can be a cell array of file names (full path, or relative path from the protocol folder), or an array of structures describing the files in the database (returned by a previous call to bst_process).

As described in the scripting tutorial:

Thank you
It worked perfectly!