Reading stim channels with masking

Hello Team Brainstorm,

Is there a possibility to read the stim channel for example in Neuromag systems STL101 using a mask.

I have to adjust the values in the stim channel to get the correct output from STL101 channel.

Like we have the function in MNE:
events = mne.find_events(raw, stim_channel='STI 014', mask=4)

Thank you for your help.

Hi @saltwater, Could you provide more information on the kind of adjustment needed for the imported values? It may be possible that there are functions already in Brainstorm to do so.

Edit, if possible provide an example


  • Triggers from my script should fall within the range 1 to 255 (low byte).
  • Button presses are recorded in the next higher byte.
  • But all codes are combined (summed) in the data files in the STI101 channel.
  • To retrieve the desired triggers and button presses separately, I need to apply masks during event extraction.


  • To extract triggers, I use a mask of 255 (0xFF hexadecimal).
  • To retrieve button presses, I use a mask of 65280 (0xFF00 hexadecimal).

Load raw data from Neuromag system
raw ='your_raw_data.fif', preload=True)

Extract triggers with mask = 255 (0xFF hexadecimal)
triggers = mne.find_events(raw, stim_channel='STI 014', mask=255)

Extract button presses with mask = 65280 (0xFF00 hexadecimal)
button_presses = mne.find_events(raw, stim_channel='STI 014', mask=65280)

In MNE-Python, the mne.find_events() function is used to extract events from a raw data file, typically from the stim channel. The mask parameter in this function allows you to filter the events based on their values.


  1. Extracting Events: The mne.find_events() function scans the stim channel of the raw data and identifies points where events occur. These events are usually represented as integer values in the stim channel, with each value corresponding to a specific event marker (e.g., onset of a stimulus, button press, etc.).

  2. Applying the Mask: The mask parameter is a bitmask that specifies which bits in the event values should be considered when filtering events. It allows you to selectively include or exclude events based on certain criteria.

  3. Filtering Events: When you provide a mask value, mne.find_events() uses it to filter the event values before returning them. Only the events that match the specified criteria defined by the mask are included in the output.


  • Suppose your event values are 8-bit binary numbers.
  • You want to extract events of type A, which have the 3rd and 4th bits set to 1.
  • You also want to extract events of type B, which have the 6th and 7th bits set to 1.

You can define masks to filter events of type A and type B accordingly:

  • For type A events: mask = 12 (binary: 00001100)
  • For type B events: mask = 192 (binary: 11000000)

Hopefully the above explanation helps.

With these options, if the recording has events 3 and 768. Are both are converted to 3?


Only 3 will be returned and 768 will be ignored in the list of your triggers. (255 as mask)

If you use the mask as 65280 then 3 will be ignored and 768 will be returned.

This option of reading events from a channel using mask is now added in the Read from channel
(commit: 0b210f3)


It has the same behaviour as mne.find_events()

1 Like

Oh wow! Awesome.
Thank you so much, this is amazing.