def mp_acquisition(state): print(' * acquisition * Feedback from within process.') print(' * acquisition * Current state: %s.' % state.value) print(' * acquisition * Acquisition will start soon.') # Callback function for OpenBCI class to handle samples. def handle_sample(sample): if freqs is not None: # Get data point (value) form the first channel (index '0'). smp = sample.channel_data[channel] # Filter fist sample (place in list with the index '0'). smp_flted = frt.filterIIR(smp, 0) # Detect ssvep state (stimulus is the subject looking at). ssvep_state = srt.ssvep_detect(smp_flted) # Let the inreface know that the data is streaming. if board.streaming: streaming.set() # Quit program, stop and disconnect board. if terminate.is_set(): print(' * acquisition * Disconnect signal sent...') streaming.clear() board.disconnect() with open(output_path, 'at') as f: save = csv.writer(f) if freqs is not None: save.writerow([sample.id, smp, smp_flted, ssvep_state]) else: save.writerow([sample.id] + sample.channel_data + [state.value]) if freqs is not None: # Create an object for filtering in real-time. frt = flt.FltRealTime() # SSVEP detection in real-time. srt = svp.SSVEPRealTime(fs=250, window_len=250, freqs=freqs, window_kind='nooverlap') print(' * acquisition * Output file preparation...') if header is not None: with open(output_path, 'w') as f: save = csv.writer(f) save.writerow(header) print(' * acquisition * Modules for OpenBCI real time set...') board = bci.OpenBCIBoard(port=port) print(' * acquisition * Starting streaming...') board.start_streaming(handle_sample) board.disconnect()
def func_blink_det(blink_det, blinks_num): def plotData(sample): # get sample form the first channel (index '0') smp = sample.channel_data[channel] # filter fist sample (place in list with the index '0') smp_flted = frt.filterIIR(smp, 0) # detect all blinks (signal amplifications above 60uV) brt.blink_detect(smp_flted, 60) # report it the new blink is spotted if brt.new_blink: if brt.blinks_num == 1: # First detected blink is in fact artifact from filter # settling. Correct blink number by subtracting 1. # First "blink" successfully detected - device is connected. connected.set() print('CONNECTED. Speller starts detecting blinks.') else: blink_det.put(brt.blinks_num) blinks_num.value = brt.blinks_num print('BLINK!') # online plotting using matplotlib blit # prt.frame_plot(smp_flted) # quit_program program, stop and disconnect board if quit_program.is_set(): print('Disconnect signal sent...') board.disconnect() with open(csv_filename, 'at') as f: save = csv.writer(f) save.writerow([smp, smp_flted, brt.blinks_num]) # save.writerow([sample.id] + sample.channel_data) if __name__ == '__main__': # filtering in real time object creation frt = flt.FltRealTime() # blink detection in real time object creation brt = blk.BlinkRealTime() # plotting in real time object creation # prt = pltmod.OnlinePlot(samples_per_frame=2) print('modules for OpenBCI real time set...') port = '/dev/ttyUSB0' baud = 115200 board = bci.OpenBCIBoard(port=port, baud=baud) print('starting streaming...') board.start_streaming(plotData) board.disconnect()
def func_ssvep_det(ssvep_state): def handle_sample(sample): # get data point (value) form the first channel (index '0') smp = sample.channel_data[channel] # filter fist sample (place in list with the index '0') smp_flted = frt.filterIIR(smp, 0) # detect ssvep state (which stimulus is the subject looking at) ssvep_state = srt.ssvep_detect(smp_flted) # srt.ssvep_detect(smp_flted, 95) # quit_program program, stop and disconnect board if quit_program.is_set(): print('Disconnect signal sent...') board.disconnect() # It can even simulate saving with open(csv_filename, 'at') as f: save = csv.writer(f) save.writerow([smp, smp_flted, srt.ssvep_state]) # save.writerow([sample.id] + sample.channel_data) if __name__ == '__main__': # filtering in real time object creation frt = flt.FltRealTime() # blink detection in real time object creation srt = slt.SSVEPRealTime(window_kind='nooverlap', window_len=1000) print('modules for OpenBCI real time set...') port = '/dev/ttyUSB0' baud = 115200 board = bci.OpenBCIBoard(port=port, baud=baud) print('starting streaming...') board.start_streaming(plotData) board.disconnect()
# MAIN CHANNEL (OpenBCI board) channel = 0 ############################################################################### # # OPENBCI AQUIRING PROCESS # ############################################################################### def plotData(sample): # get sample form the first channel (index '0') smp = sample.channel_data[channel] # filter fist sample (place in list with the index '0') smp_flted = frt.filterIIR(smp, 0) print(smp_flted) # filtering in real time object creation frt = flt.FltRealTime() port = '/dev/ttyUSB0' baud = 115200 board = bci.OpenBCIBoard(port=port, baud=baud) print('starting streaming...') board.start_streaming(plotData) board.disconnect()