File size: 699 Bytes
c1049d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function [inlet, fs, chan] = EEGInitialization()
    % Load the LSL library
    lib = lsl_loadlib();

    % Find a stream of type 'EEG'
    result = {};
    maxAttempts = 1;  % Set a maximum number of attempts to find the stream
    attempts = 0;

    while isempty(result) && attempts < maxAttempts
        result = lsl_resolve_byprop(lib, 'type', 'EEG');
        pause(1);  % Optional: wait for a second before trying again
        attempts = attempts + 1;
    end

    if isempty(result)
        error('Failed to find an EEG stream');
    end

    % Connect to the first found stream
    inlet = lsl_inlet(result{1});
    fs = result{1}.nominal_srate();
    chan = result{1}.channel_count();
end