feat_buffer = np.zeros((n_win_test, len(names_of_features))) # Initialize the plots plotter_eeg = BCIw.dataPlotter(params['sampling frequency']*eeg_buffer_secs, params['names of channels'], params['sampling frequency']) plotter_feat = BCIw.dataPlotter(n_win_test, names_of_features, 1/float(shift_secs)) #%% Start pulling data mules_client.flushdata() # Flush old data from MuLES BCIw.beep() # Beep sound # The try/except structure allows to quit the while loop by aborting the # script with <Ctrl-C> print(' Press Ctrl-C in the console to break the While Loop') try: # The following loop does what we see in the diagram of Exercise 1: # acquire data, compute features, visualize the raw EEG and the features while True: """ 1- ACQUIRE DATA """ eeg_data = mules_client.getdata(shift_secs, False) # Obtain EEG data from MuLES eeg_data = eeg_data[:,[index_channel ,-1]] # Keep only one electrode (and the STATUS channel) for further analysis eeg_buffer = BCIw.updatebuffer(eeg_buffer, eeg_data) # Update EEG buffer
myo_client = ClientMyo(myo_ip, myo_port) time.sleep(2) # Set some parameters shift_secs = args.win_test_secs - args.overlap_secs # Training loop (Now it is a loop because we have feedback!!) loops_done = 0 training_acc = 0.0 while ((loops_done < args.max_feedback_loops) and (training_acc < args.training_accuracy_threshold)): # Record data for mental activity 0 BCIw.beep() eeg_data0 = mules_client.getdata(args.training_secs) # Record data for mental activity 1 BCIw.beep() eeg_data1 = mules_client.getdata(args.training_secs) # Divide data into epochs eeg_epochs0 = BCIw.epoching( eeg_data0, round(args.win_test_secs * params['sampling frequency']), round(args.overlap_secs * params['sampling frequency'])) eeg_epochs1 = BCIw.epoching( eeg_data1, round(args.win_test_secs * params['sampling frequency']), round(args.overlap_secs * params['sampling frequency']))
mules_client = mules.MulesClient(mules_ip, mules_port) # Device parameters params = mules_client.getparams() #%% Set the experiment parameters training_secs = 20 win_test_secs = 1 # Length of the Test Window in seconds overlap_secs = 0.7 # Overlap between two consecutive Test Windows shift_secs = win_test_secs - overlap_secs eeg_buffer_secs = 30 # Size of the EEG data buffer (duration of Testing section) #%% Record training data # Record data for mental activity 0 BCIw.beep() eeg_data0 = mules_client.getdata(training_secs) # Record data for mental activity 1 BCIw.beep() eeg_data1 = mules_client.getdata(training_secs) # Divide data into epochs eeg_epochs0 = BCIw.epoching(eeg_data0, win_test_secs * params['sampling frequency'], overlap_secs * params['sampling frequency']) eeg_epochs1 = BCIw.epoching(eeg_data1, win_test_secs * params['sampling frequency'], overlap_secs * params['sampling frequency']) #%% Compute features
params = mules_client.getparams() fs = params['sampling frequency'] #%% Set the experiment parameters training_secs = 20 win_test_secs = 1 # Length of the Test Window in seconds overlap_secs = 0.7 # Overlap between two consecutive Test Windows shift_secs = win_test_secs - overlap_secs eeg_buffer_secs = 30 # Size of the EEG data buffer (duration of Testing section) #%% Record training data # Record data for mental activity 0 BCIw.beep() eeg_data0 = mules_client.getdata(training_secs) # Record data for mental activity 1 BCIw.beep() eeg_data1 = mules_client.getdata(training_secs) # Divide data into epochs eeg_epochs0 = BCIw.epoching(eeg_data0, win_test_secs * params['sampling frequency'], overlap_secs * params['sampling frequency']) eeg_epochs1 = BCIw.epoching(eeg_data1, win_test_secs * params['sampling frequency'], overlap_secs * params['sampling frequency']) #%% Compute features feat_matrix0 = BCIw.compute_feature_matrix(eeg_epochs0, params['sampling frequency'])