Master LSL with mbtStreamer – some practical examples

  • hyperscanning
  • how-to
  • LSL
  • multimodal
  • synchronization

Synchronizing different physiological and behavioral data can be a challenge. Especially when you want your setup to be light and mobile. That’s where wireless connection, such as LSL, comes in handy!

An EEG study often includes collecting different data modalities, to better understand the person’s behavior.

Alongside EEG, researchers use various sensors to capture other physiological signals. Unique device specifications and sampling rates make precise timing challenging.

Another important aspect is synchronizing EEG data with an external stimulus. Neural responses triggered by specific events can happen within milliseconds after that event. Precise synchronization ensures that the observed neural response accurately reflects the brain’s reaction.

About LabStreamingLayer

One of the easiest ways to synchronize data from multiple systems is by using LabStreamingLayer – LSL. It’s a wireless protocol that handles both networking and time-synchronization of all data streams.

LSL uses standard Internet protocol to send and receive data. With LSL you can synchronize streams from devices or apps connected to the same network (WAN or LAN).

Check out the list of LSL supported apps and hardware.

You can stream continuous data such as EEG, or you can stream participant’s responses to a stimulus in the form of markers.

It’s also possible to send triggers via LSL when presenting a stimulus in a presentation software. This trigger is then used to detect time-locked brain responses – ERPs (event related potentials).

EEG signals with an embedded trigger sent via LSL
EEG stream synched with a trigger stream. Each event represents the time point at which a (visual) stimulus was presented. After this stimulus, a neural response appears in the form of an ERP.

In this blog, we’ll first give a simple example on how to open an LSL stream and send some data through that stream. We’ll focus on sending a trigger with a stimulus, but any other data type can be sent the same way (EEG sample, video frame, audio recording, etc.)

Send a trigger using LSL

Programs used for presenting stimuli are called exactly that – presentation software. Some presentation software that you might know are Psychtoolbox (Matlab), PsychoPy (Python), Neurobs Presentation, E-Prime and so on.

In all these programs, and more, you can add an LSL library which allows you to then program sending the triggers.

Neurobs Presentation for example supports LSL by default, so you don’t have to do any additional coding.

Check out our blog on Neurobs Presentation and LSL.

Code example

For this example, we wrote a pseudo-code to show how LSL programing looks like in different software.

First, we need to import the LSL library. You can download the library package from github, for a program of your choosing.

library = lsl_loadlib()

Then, we need to give some information about the stream. You can include:

  • Name of the LSL stream.
  • Stream type refers to content type of the stream. For example, this can be set to ‘EEG’, ‘Markers’ etc.
  • NominalSrate is the sampling rate we expect from the data.
  • Info about channel count, channel format, source ID and so on. But we won’t do this in the example.

Once we define stream info, we open the stream outlet.

info = lsl_streaminfo(library, 'Stimuli trigger stream', 'Markers')
outlet = lsl_outlet(info)

Before defining our condition loop, we want to load a certain stimulus. You can load an image or audio recording for example.

stimulus = load_stim("stimulus file")

We’ll define an endless loop in our example, since the condition of the loop varies depending on the task paradigm. In this loop, we keep presenting the stimulus indefinitely and sending a trigger each time.

To send a trigger, all you need to do is push the trigger name/label through the opened outlet.

while true
stimulus.present()
outlet.push_sample("trigger label")
end

For a practical use case on how to code LSL into your study paradigm, you can check out our blog on sending LSL triggers from PsychoPy in Stroop task.

Include triggers in EEG data

Once you open an LSL outlet, the stream is visible on the network.

You can visualize and record triggers in mbtStreamer software, which is used for communicating with our mobile EEG devices. All streams get recorded synchronously in one XDF file.

mbtStreamer software for recording and visualizing EEG and Trigger stream
mbtStreamer software when you connect your mobile EEG device. By default, EEG data is streamed via LSL, but you can include any other stream in the recording. You can do this by simply checking the stream in the list of all available LSL streams. We selected EEG and trigger streams for the recording. You can also visualize triggers alongside EEG data during recording.

Now that we’ve covered how to stream triggers via LSL, it’s easier to understand how any data type can be streamed in the same fashion.

In mbtStreamer software, we stream EEG data by default. There’s no need to do any additional coding on that part. This is also the case for many other apps and devices.

Hyperscanning using LSL

We mentioned that any stream can be detected and recorded with EEG data. This also covers Hyperscanning studies! Here, you’d record multiple EEG signals collected with mbt devices.

You can record streams from different devices in one file, as long as all PCs are on the same network.

Hyperscanning setup with EEG devices, including mbtStreamer recording software.
Let’s say you are measuring EEGs on 5 participants at the same time. Each device is connected to one PC, so you can view EEG data from each participant. If these 5 PCs are all on the same network, you will be able to detect 5 EEG streams on every PC! Just select one PC to be the recording one.

Our devices are completely wireless, so this setup doesn’t need any wiring, extra units, black boxes and so on. However, this can come with a price.

When using too many Bluetooth devices in the same room, interference can occur and cause data loss. EEG stream usually implies a lot of channels + high sampling frequency.

That’s why we developed a dedicated device mode for Hyperscanning studies. We made sure to lower data throughput via Bluetooth, while still keeping the high resolution of EEG data and precise synchronization.

All PRO line devices support Hyperscanning mode, so feel free to contact us if you’d like to know more!

Recommended reading