Changes

Jump to navigation Jump to search
1,552 bytes added ,  13:34, 23 January 2023
no edit summary
Line 103: Line 103:  
     print(timestamp, sample)
 
     print(timestamp, sample)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Matlab ===
 +
Please, read the instructions on the GitHub labstreaminglayer website (https://github.com/labstreaminglayer/liblsl-Matlab) on how to prepare Matlab to work with LSL. You can either use the latest release for your Matlab version, or if that doesn't workout well, build it from the source files. Make sure to add the liblsl-Matlab folder to your path recursively to make it available to your own scripts.
 +
 +
A short example for sending lsl streaming data:
 +
<syntaxhighlight lang="matlab" line>
 +
%% instantiate the library
 +
disp('Loading library...');
 +
lib = lsl_loadlib();
 +
 +
% make a new stream outlet
 +
disp('Creating a new streaminfo...');
 +
info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');
 +
 +
disp('Opening an outlet...');
 +
outlet = lsl_outlet(info);
 +
 +
% send data into the outlet, sample by sample
 +
disp('Now transmitting data...');
 +
while true
 +
    outlet.push_sample(randn(8,1));
 +
    pause(0.01);
 +
end
 +
</syntaxhighlight>
 +
 +
A short example for sending lsl streaming data:
 +
<syntaxhighlight lang="matlab" line>
 +
%% instantiate the library
 +
disp('Loading the library...');
 +
lib = lsl_loadlib();
 +
 +
% resolve a stream...
 +
disp('Resolving an EEG stream...');
 +
result = {};
 +
while isempty(result)
 +
    result = lsl_resolve_byprop(lib,'type','EEG'); end
 +
 +
% create a new inlet
 +
disp('Opening an inlet...');
 +
inlet = lsl_inlet(result{1});
 +
 +
disp('Now receiving data...');
 +
while true
 +
    % get data from the inlet
 +
    [vec,ts] = inlet.pull_sample();
 +
    % and display it
 +
    fprintf('%.2f\t',vec);
 +
    fprintf('%.5f\n',ts);
 +
end</syntaxhighlight>

Navigation menu