Skip to content

Tutorial 3: Generate your own data streams using MATLAB

mgbleichner edited this page Dec 23, 2016 · 13 revisions

LSL provides the possibility to easily generate your own data and marker streams. [Here] (https://github.com/sccn/labstreaminglayer/wiki/ExampleCode.wiki) you can find examples for how to send or receive data for several programming languages including C, C++, Python, MATLAB, Java and C#. We will use here some MATLAB examples to convey the general principle.


For this tutorial you need

The LSL App can be downloaded from the ftp as .zip files.


  • 'Unlink' all apps that are currently running.
  • Start LabRecorder.exe
  • Start MATLAB

First we send a random stream of data of the type EEG.

  • In MATLAB, change to ./MATLAB viewer/liblsl-Matlab/examples
  • Open the SendData.m script
  • This shows how a stream is created and how data can be send to the stream
  • In this case the stream has the name ‘BioSemi’, the type ‘EEG’, has 8 channels, and streams random data at 100Hz
  • Run the script
  • In the Lab Recorder you should see the ‘BioSemi’ stream
  • Record a short piece of data and load it again into MATLAB (see next lines)
    • While the script is running MATLAB is not responsive for anything else
    • You can stop the execution of the script with 'Control-C'

Now we send a marker stream.

  • Open the SendStringMarker.m script. This shows how an irregular marker stream can be used, e.g. for sending event trigger
  • Run the script
  • In the LabRecorder you should see the stream ‘MyMarkerStream’
  • Record a short piece of data and load it again into MATLAB (see next lines)
  • While the script is running MATLAB is not responsive for anything else
  • You can stop the execution of the script with 'Control-C'

Now we adapt the SendStringMarker script so that we have a small experiment. Send 15 tones (use beep.m) with an increasing ITI (start with 500msec between the first and the second tone and increase by 100 msec)

  • Send an individual marker (including the trial number) for each tone
  • Use the ‘Input’ function to interrupt the script after it has been started. This allows you to start the LabRecorder after the stream was established and before the actual experiment is started
  • ‘Link’ the AudioCaptureWin stream again
  • In the LabRecorder you should now see two streams
  • Start the recording and continue the experiment script
  • Analyze the data in MATLAB as before (you might need to change to the ‘MATLAB Import‘ folder)
  • Check for the marker stream whether the time difference between two successive markers is as expected. You can also epoch your data using EEGlab to visualize the relationship between the marker and sound onset.

The timing of this experiment will be rather poor as the pause.m function does not provide accurate timing.

Clone this wiki locally