Skip to content

Commit 6dc1ff2

Browse files
committed
Add MATLAB + LSL test script to Networking Test Kit #1107
1 parent 908f6ea commit 6dc1ff2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
clr;
2+
addpath(genpath('liblsl-Matlab'));
3+
4+
lib = lsl_loadlib(); version = lsl_library_version(lib)
5+
% resolve a stream...
6+
disp('Resolving an EEG stream...');
7+
result = {};
8+
while isempty(result)
9+
result = lsl_resolve_byprop(lib,'type','EEG'); end
10+
11+
% create a new inlet
12+
disp('Opening an inlet...');
13+
inlet = lsl_inlet(result{1});
14+
15+
% Set the time interval for counting samples (in seconds)
16+
timeInterval = 5; % Adjust as needed
17+
18+
% Initialize the sample counter and start time
19+
sampleCount = 0;
20+
startTime = tic;
21+
22+
disp('Now receiving data...');
23+
while true
24+
% get data from the inlet
25+
[vec,ts] = inlet.pull_sample();
26+
% Display data (optional)
27+
% fprintf('%.2f\t',vec);
28+
% fprintf('%.5f\n',ts);
29+
30+
% Increment the sample counter
31+
sampleCount = sampleCount + 1;
32+
33+
% Check if the time interval has elapsed
34+
elapsedTime = toc(startTime);
35+
if elapsedTime >= timeInterval
36+
% Calculate the samples per second (SPS)
37+
samplesPerSecond = sampleCount / elapsedTime;
38+
39+
% Display the result
40+
fprintf('Received %.0f samples in %.2f seconds\n', sampleCount, elapsedTime);
41+
fprintf('Samples per second: %.2f\n', samplesPerSecond);
42+
43+
% Reset the sample counter and start time
44+
sampleCount = 0;
45+
startTime = tic;
46+
end
47+
end

0 commit comments

Comments
 (0)