| 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 | |