How to use Lab Streaming Layer (LSL) for data streaming for NIRS

Monday, 08 de February de 2021

How to use Lab Streaming Layer (LSL) for data streaming for NIRS

Real Time Data Streaming with LSL

In this article you can find instructions on how to receive data in real time via LSL, for the purpose of implementing your own real time analysis. If you are interested in a real time analysis solution, consider Turbo Satori, a dedicated fNIRS BCI and Neurofeedback software, which is available for purchase. NIRx does not provide custom scripts/support in how to analyze the data in real time.

Lab Streaming Layer (LSL) is protocol that consists of a collection of libraries and tools that allow for real-time data and triggering streaming as well as multi-modal time-synchronization. The communication can be controlled using different programming languages (C, C++, Python, Java, C#, Matlab) and under different platforms (Mac, Windows, Unix). LSL requires that any software sending or receiving data is on the same network (could be the same computer, for example).

LSL with Aurora and NIRStar

NIRx allows users to stream data in real time using LSL. Both raw data and hemoglobin concentration data are streamed. For more information on the structure of the streamed data, refer to the NIRStar and Aurora manuals.

The LSL stream is automatically enabled in Aurora - the user doesn't need to do anything to turn the stream on. 

The LSL stream must be enabled in NIRStar. To do so, navigate to 'Configure Hardware>Data Streaming'. Under 'Lab Streaming Layer', toggle the 'Enable LSL Streaming' button. 

Any triggers that are received in NIRStar and Aurora are sent out on an LSL stream called 'NIRStar Triggers'. Note that the triggers are sampled at the same rate as the fNIRS data. 

-

Implementing Real Time Data Streaming with LSL

To download the LSL library for streaming data in various applications, see the github repository here. 

-

We provide instructions for streaming NIRx data in MATLAB below.

-

  1. Download the MATLAB LSL repository here
  2. Unzip the folder, and place it in your Matlab path.
  3. Download the latest build, compatible with your OS, here
  4. Unzip and place all folders from this download within the liblsl-Matlab/bin folder.
  5. Run the build_mex.m file contained in the liblsl-Matlab folder. This will take a couple of minutes to run.
  6. Open the file 'ReceiveData.m'  in the 'liblsl-Matlab/examples' folder.
  7. On line 9 change lsl_resolve_byprop(lib,'type','EEG'); to lsl_resolve_byprop(lib,'type','NIRS'); 
  8. Line 20 specifies that the data is printed up to 2 decimal points. You can modify the number of decimal points printed by changing the '2' to an integer of your choice.
  9. Open your LSL stream (i.e. start to record data with NIRStar or Aurora; LSL streaming must be manually enabled in NIRStar, is automatically enabled in Aurora).
  10. Run the  'ReceiveData.m' file and see your data stream in the Command Window!

If using a mac and you run into an error, according to the LSL Matlab Github repository:

"On MacOS, you may still get an error similar to Invalid MEX-file [...] lsl_loadlib_.mexmaci64; Reason: image not found.. To fix this run the following command in a Terminal window from within the liblsl-Matlab directory: install_name_tool -add_rpath "@loader_path/" bin/lsl_loadlib_.mexmaci64"

 Source and original post: Nirx Help Center

The content published here is the exclusive responsibility of the authors.

Autor: