def simulate_bci_signal(fs, chunk_size=8, verbose=False): # setup stream info = StreamInfo(name='NFBLab_data', type='', channel_count=1, nominal_srate=fs) channels = info.desc().append_child("channels") channels.append_child("channel").append_child_value("name", 'BCI') print('Stream info:\n\tname: {}, fs: {}Hz, channels: {}'.format( info.name(), int(info.nominal_srate()), ['BCI'])) outlet = StreamOutlet(info) print('Now sending data...') # prepare main loop start = time() counter = chunk_size x = x_base = np.ones((chunk_size, 1)) n_chunks = 0 # main loop while True: while time() - start < counter / fs: sleep(1 / fs) if np.random.randint(0, fs / chunk_size / 2) == 0: x = x_base * np.random.randint(0, 2 + 1) outlet.push_chunk(x) n_chunks += 1 counter += chunk_size if verbose: # print('counter time: {:.2f}\ttime: {:.2f}'.format(counter/fs, time() - start)) if n_chunks % 50 == 0: print('Chunk {} was sent'.format(n_chunks))
def simulate_bci_signal(fs, verbose=False): """ :param fs: sampling frequency :param verbose: if verbose == True print info """ # setup stream info = StreamInfo(name='NFBLab_data', type='', channel_count=1, nominal_srate=fs) channels = info.desc().append_child("channels") channels.append_child("channel").append_child_value("name", 'BCI') print('Stream info:\n\tname: {}, fs: {}Hz, channels: {}'.format( info.name(), int(info.nominal_srate()), ['BCI'])) outlet = StreamOutlet(info) print('Now sending data...') # prepare main loop start = time() counter = 0 # main loop while True: while time() - start < counter / fs: sleep(1 / fs) x = 1 - int((counter % 1501) < 250) outlet.push_sample([x]) counter += 1 if verbose: if counter % fs == 0: print(x)
def __init__(self, info: pylsl.StreamInfo, plt: pg.PlotItem): super().__init__(info) # calculate the size for our buffer, i.e. two times the displayed data bufsize = (2 * math.ceil(info.nominal_srate() * plot_duration), info.channel_count()) self.buffer = np.empty(bufsize, dtype=self.dtypes[info.channel_format()]) empty = np.array([]) # create one curve object for each channel/line that will handle displaying the data self.curves = [pg.PlotCurveItem(x=empty, y=empty, autoDownsample=True) for _ in range(self.channel_count)] for curve in self.curves: plt.addItem(curve)