Lab streaming layer is a system for synchronizing streaming data for real-time streaming, recording, and analysis of biodata. The
openbci_pylsl program uses Python to establish an LSL stream that can be received using scripts in Matlab. Follow the steps below to learn how to setup and begin using Matlab for real-time data analysis.
This post will show you how straightforward is to set up the new lab streaming layer from Python to Matlab by following the detailed instructions explained in the OpenBCI repository file. Moreover, and then explain the various ways you can use LSL to perform experiments or record data.
OpenBCI LSL Setup
Before you follow the setup instructions from the “Read me” file, you must have previously downloaded the following programs and files:
- Python (either version 2.7 or 3.5)
- OpenBCI_MATLAB files from GitHub.
For further information, please go to the OpenBCI_MATLAB repository on GitHub, which explains step by step the commands that you need to follow to obtain an OpenBCI data stream directly into Matlab. Moreover, it explains various ways you can use LSL to perform experiments or record data.
Getting a stream into Matlab can be done in two steps:
- Start a stream with the
- Receive the stream with an LSL script in Matlab
Start streaming in Python
Once you have plugged in your dongle and powered up your OpenBCI Board, you can freely navigate to the Matlab-Python directory on your command line, and enter the following command:
python openbci_pylsl.py -p "PORT"
Some board parameters and information related to the serial port will appear on the command line. After the board initialization, you are ready to start streaming! Isn’t it that straightforward?
The commands to control the streaming are also pretty intuitive:
- To begin streaming type
- To stop streaming type
- To disconnect from the serial port type
Receive the stream in MATLAB
The data stream from you board should now be pushed into the lab streaming layer. The next step is to receive this data in Matlab by running the “ReceiveData” script.
Congratulations! If you are using eight channels and see nine columns plenty of numbers in your Command Window you better feel lucky. You received the streaming from Python in Matlab! The EEG Data appears from the first to the eighth column, whereas the last column displays the time in milliseconds. If you want a use the auxiliary data from the OpenBCI board you can also change the code and save it in a Matlab variable.
Monitoring in Matlab
Wait! You might want to monitor your stream in Matlab before you deploy any scripts in order to make sure that the biodata is correctly streaming into Matlab, right? OpenBCI LSL files include the
vis_stream function to bring up the Matlab Visualizer Toolbox written by Christian Kothe at UCSD.
Voilà! Here you have your brain waves! Now you can work with them. Besides, you can change the scale with the up-down arrows on your keyboard.
If you want to stop streaming or disconnect from the serial port just come back to the command line in Python and type
/stop function or
Potential uses of LSL
You should experiment with different methods of working with the output of
inlet.pull_sample(). You can add to that while loop to call a variety of different scripts while you collect data. You can also experiment with parallel computing in Matlab to allow the lab streaming layer to run in the background while running other scripts.
You can save the streaming data in a vector and work with the EEG data directly in Matlab without having to use Processing.