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)
Exemple #2
0
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))
Exemple #3
0
    def __init__(self, info: pylsl.StreamInfo):
        # create an inlet and connect it to the outlet we found earlier.
        # max_buflen is set so data older the plot_duration is discarded
        # automatically and we only pull data new enough to show it

        # Also, perform online clock synchronization so all streams are in the
        # same time domain as the local lsl_clock()
        # (see https://labstreaminglayer.readthedocs.io/projects/liblsl/ref/enums.html#_CPPv414proc_clocksync)
        # and dejitter timestamps
        self.inlet = pylsl.StreamInlet(info, max_buflen=plot_duration,
                                       processing_flags=pylsl.proc_clocksync | pylsl.proc_dejitter)
        # store the name and channel count
        self.name = info.name()
        self.channel_count = info.channel_count()
		print "MAC address (%s) is not defined..." %macAddress
		print "connecting to BITalino(%s)..." 
	except ValueError:
		print "MAC address (%s) is not defined..." %macAddress
		print "connecting to BITalino(%s)..." 
	
# Set battery threshold
device.battery(batteryThreshold)
# Read BITalino version
print device.version()
print "connected to BITalino(%s)" %macAddress
print "creating Signal stream..."
info = StreamInfo('BiTalino','BiTalino',+len(acqChannels),samplingRate,'float32','myuid34234');
# next make an outlet
outlet = StreamOutlet(info)
print"created Signal stream : %s" %info.name()
print("starting acquisition...")
# Start Acquisition
device.start(samplingRate, acqChannels)
# Read samples
while 1:
	data=device.read(nSamples)
	print data
 	outlet.push_sample(data[0][defaultChannel+1:])

# Turn BITalino led on
device.trigger(digitalOutput)
# Stop acquisition
device.stop()
# Close connection
outlet.close()