Difference between revisions of "LabStreamingLayer"

From biophysics
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
*Real-time Data Streaming: LSL allows the continuous and real-time transmission of data from various sources, such as sensors, recording devices, and software applications. This can include EEG, ECG, eye-tracking data, motion capture, and more.
 
*Real-time Data Streaming: LSL allows the continuous and real-time transmission of data from various sources, such as sensors, recording devices, and software applications. This can include EEG, ECG, eye-tracking data, motion capture, and more.
  
*Data Synchronization: LSL provides a mechanism for synchronizing data streams from multiple devices or applications. This synchronization is essential for conducting experiments or analyses that require precise temporal alignment across different data sources.
+
*Data Synchronization: LSL provides a mechanism for synchronizing data streams from multiple devices or applications.
  
*Cross-Platform Support: LSL is platform-independent and can be used on various operating systems, including Windows, macOS, and Linux. This makes it versatile and suitable for a wide range of research environments.
+
*Cross-Platform Support: LSL is platform-independent and can be used on various operating systems, including Windows, macOS, and Linux.
  
*Language Support: LSL offers libraries and bindings for several programming languages, including Python, C/C++, Java, MATLAB (which you are familiar with), and others. This allows researchers to integrate LSL into their existing workflows and data processing pipelines.
+
*Language Support: LSL offers libraries and bindings for several programming languages, including Python, C/C++, Java, MATLAB, and others.
  
 
*Flexible Data Types: It supports various data types, including numeric, string, and marker data, making it adaptable to different types of experiments and data formats.
 
*Flexible Data Types: It supports various data types, including numeric, string, and marker data, making it adaptable to different types of experiments and data formats.
  
*Open Source: LabStreamingLayer is an open-source project, which means it is continuously developed and improved by a community of researchers and developers. This openness encourages collaboration and customization.
+
*Open Source: LabStreamingLayer is an open-source project, which means it is continuously developed and improved by a community of researchers and developers.
  
*Network Capabilities: LSL supports both local data streaming (within a single computer) and network-based streaming, enabling data sharing across different devices and locations.
+
*Network Capabilities: LSL supports both local data streaming (within a single computer) and network-based streaming.
  
*Timestamps: LSL provides high-precision timestamps, allowing researchers to accurately timestamp events and data samples.
+
*Timestamps: LSL provides high-precision timestamps.
  
 
==How to use LSL in Matlab==
 
==How to use LSL in Matlab==
In our biofysica repository in Gitlab we have [https://gitlab.science.ru.nl/marcw/biofysica/-/tree/master/liblsl/liblsl-Matlab?ref_type=heads matlab code] for accessing LSL devices. In the repository there are also examples for how to read the data from these devices. See the [https://gitlab.science.ru.nl/marcw/biofysica/-/blob/master/liblsl/liblsl-Matlab/examples/README.md?ref_type=heads readme.md] file on Gitlab.
+
In our biofysica repository in Gitlab we have [https://gitlab.science.ru.nl/marcw/biofysica/-/tree/master/liblsl/liblsl-Matlab?ref_type=heads matlab code] for accessing LSL devices. In the repository there are also examples for how to read the data from these devices.
  
The following code example checks whether an LSL stream is available for the device '''lslder04''' and the channel '''Digital Events 1''':
+
You can get a list of all available LSL-streams by executing the Matlab command:
 
<pre>
 
<pre>
lslInfo=lsl_resolver('type=''Digital Events @ lslder04'' and name=''Digital Events 1''');
+
lsl_list
streamInfoList=lslInfo.list();
+
</pre>
 +
 
 +
Every stream has a type and a name. With the function '''lsl_resolver''' you can get the LSL info of available streams. You can look for a specific stream by specifying the stream type and/or the name in a string parameter:
 +
<pre>
 +
lsl_resolver('type=''<stream type> @ <hostname>'' and name=''<stream name>''') 
 +
</pre>
 +
 
 +
The hostname is the name of the computer to which a LSL capable device (e.g. eyetrackers) is attached or the name of an embedded computer as is the case for Digital Event Recorders.
 +
 
 +
The following code example checks whether an LSL stream is available for the stream type '''Digital Events''' on host '''lslder04''' and the stream name '''Digital Events 1''':
 +
<pre>
 +
lslInfo = lsl_resolver('type=''Digital Events @ lslder04'' and name=''Digital Events 1''');
 +
streamInfoList = lslInfo.list;
 
if isempty(streamInfoList)
 
if isempty(streamInfoList)
 
   error('no streams found');
 
   error('no streams found');
 
end  
 
end  
 
</pre>
 
</pre>
 
 
 
In this case the '''streamInfoList''' contains only one stream (or none). If you want to find all available streams you can use:
 
In this case the '''streamInfoList''' contains only one stream (or none). If you want to find all available streams you can use:
 
<pre>
 
<pre>
info=lsl_resolver
+
lslInfo = lsl_resolver
streamInfoList = lslInfo.list();
+
streamInfoList = lslInfo.list;
 
</pre>
 
</pre>
  
Line 41: Line 51:
  
 
<pre>
 
<pre>
for i=1:size(streamInfoList ,1)
+
for i = 1:size(streamInfoList ,1)
 
     fprintf('%d: name: ''%s'' type: ''%s''\n',i,streamInfoList{i}.name,streamInfoList{i}.type);
 
     fprintf('%d: name: ''%s'' type: ''%s''\n',i,streamInfoList{i}.name,streamInfoList{i}.type);
 
end
 
end
 
</pre>
 
</pre>
  
You can get the n-th stream by using '''lsl_istream''':
+
You can get the n-th stream in streamInfoList by using '''lsl_istream''':
  
 
<pre>
 
<pre>
eventStream_n=lsl_istream(lslInfo{n});
+
stream_n = lsl_istream(lslInfo{n});
eventStream_m=lsl_istream(lslInfo{m});
+
stream_m = lsl_istream(lslInfo{m});
 
</pre>
 
</pre>
  
The following code create a '''lsl_session''' and add two streams to the session.
+
The following code creates an '''lsl_session''' and add two streams to the session. You can add as many streams as you like.
  
 
<pre>
 
<pre>
ses=lsl_session();
+
mySession = lsl_session();
ses.add_stream(eventStream_n);
+
mySession.add_stream(stream_n);
ses.add_stream(eventStream_m);
+
mySession.add_stream(stream_m);
 
</pre>
 
</pre>
  
You can start a session and stop
+
You can start a session, do your experiment and stop the session and read the data from the streams.
  
 
<pre>
 
<pre>
 +
mySession.start;
 +
% do you experiment
 +
mySession.stop;
 +
data_n = stream_n.read;
 +
data_m = stream_m.read;
 +
</pre>
  
</pre>
+
More information and examples can be found [https://gitlab.science.ru.nl/marcw/biofysica/-/blob/master/liblsl/liblsl-Matlab/examples/README.md?ref_type=heads here] on Gitlab.
 +
 
 +
==Some devices with LSL==
 +
{| class="wikitable"
 +
! Device
 +
! Stream Type
 +
! Stream Name
 +
|-
 +
| Digital Event Recorder
 +
| Digital Events @ <hostname>
 +
| Digital Events X
 +
|-
 +
| Digital Event Recorder
 +
| Markers @ <hostname>
 +
| Digital Markers
 +
|-
 +
| Pupil Labs Eyetracker
 +
| Pupil Capture @ <hostname>
 +
| Pupil Primitive Data - Eye 0
 +
|-
 +
| Pupil Labs Eyetracker
 +
| Pupil Capture @ <hostname>
 +
| Pupil Python Representation - Eye 0
 +
|-
 +
| Pupil Labs Eyetracker
 +
| Pupil Gaze @ <hostname>
 +
| ?
 +
|-
 +
| OptiTrack Eyetracker
 +
| OptiTrack Mocap @ <hostname>
 +
| Labeled Markers
 +
|-
 +
| EyeSeeCAm Eyetracker
 +
| EyeSeeCam @ <hostname>
 +
| ?
 +
|}

Latest revision as of 13:16, 8 February 2024

Introduction

LabStreamingLayer (LSL) is a framework and protocol designed for the real-time streaming of time-series data. It is primarily used in research and scientific applications, especially in fields such as neuroscience, psychology, and physiology, where the collection and synchronization of data from multiple sources are crucial.

  • Real-time Data Streaming: LSL allows the continuous and real-time transmission of data from various sources, such as sensors, recording devices, and software applications. This can include EEG, ECG, eye-tracking data, motion capture, and more.
  • Data Synchronization: LSL provides a mechanism for synchronizing data streams from multiple devices or applications.
  • Cross-Platform Support: LSL is platform-independent and can be used on various operating systems, including Windows, macOS, and Linux.
  • Language Support: LSL offers libraries and bindings for several programming languages, including Python, C/C++, Java, MATLAB, and others.
  • Flexible Data Types: It supports various data types, including numeric, string, and marker data, making it adaptable to different types of experiments and data formats.
  • Open Source: LabStreamingLayer is an open-source project, which means it is continuously developed and improved by a community of researchers and developers.
  • Network Capabilities: LSL supports both local data streaming (within a single computer) and network-based streaming.
  • Timestamps: LSL provides high-precision timestamps.

How to use LSL in Matlab

In our biofysica repository in Gitlab we have matlab code for accessing LSL devices. In the repository there are also examples for how to read the data from these devices.

You can get a list of all available LSL-streams by executing the Matlab command:

lsl_list

Every stream has a type and a name. With the function lsl_resolver you can get the LSL info of available streams. You can look for a specific stream by specifying the stream type and/or the name in a string parameter:

lsl_resolver('type=''<stream type> @ <hostname>'' and name=''<stream name>''')  

The hostname is the name of the computer to which a LSL capable device (e.g. eyetrackers) is attached or the name of an embedded computer as is the case for Digital Event Recorders.

The following code example checks whether an LSL stream is available for the stream type Digital Events on host lslder04 and the stream name Digital Events 1:

lslInfo = lsl_resolver('type=''Digital Events @ lslder04'' and name=''Digital Events 1''');
streamInfoList = lslInfo.list;
if isempty(streamInfoList)
   error('no streams found');
end 

In this case the streamInfoList contains only one stream (or none). If you want to find all available streams you can use:

lslInfo = lsl_resolver
streamInfoList = lslInfo.list;

The following code prints all the types and names of the streams that are found:

for i = 1:size(streamInfoList ,1)
    fprintf('%d: name: ''%s'' type: ''%s''\n',i,streamInfoList{i}.name,streamInfoList{i}.type);
end

You can get the n-th stream in streamInfoList by using lsl_istream:

stream_n = lsl_istream(lslInfo{n});
stream_m = lsl_istream(lslInfo{m});

The following code creates an lsl_session and add two streams to the session. You can add as many streams as you like.

mySession = lsl_session();
mySession.add_stream(stream_n);
mySession.add_stream(stream_m);

You can start a session, do your experiment and stop the session and read the data from the streams.

mySession.start;
% do you experiment
mySession.stop;
data_n = stream_n.read;
data_m = stream_m.read;

More information and examples can be found here on Gitlab.

Some devices with LSL

Device Stream Type Stream Name
Digital Event Recorder Digital Events @ <hostname> Digital Events X
Digital Event Recorder Markers @ <hostname> Digital Markers
Pupil Labs Eyetracker Pupil Capture @ <hostname> Pupil Primitive Data - Eye 0
Pupil Labs Eyetracker Pupil Capture @ <hostname> Pupil Python Representation - Eye 0
Pupil Labs Eyetracker Pupil Gaze @ <hostname> ?
OptiTrack Eyetracker OptiTrack Mocap @ <hostname> Labeled Markers
EyeSeeCAm Eyetracker EyeSeeCam @ <hostname> ?