feat_matrix1 = BCIw.compute_feature_matrix(eeg_epochs1, fs) [classifier, mu_ft, std_ft, score] = BCIw.train_classifier(feat_matrix0, feat_matrix1, 'SVM') print(str(score * 100) + '% correctly predicted') BCIw.beep() """ 5. USE THE CLASSIFIER IN REAL-TIME""" # Initialize the buffers for storing raw EEG and decisions eeg_buffer = np.zeros((int(fs * buffer_length), n_channels)) filter_state = None # for use with the notch filter decision_buffer = np.zeros((30, 1)) plotter_decision = BCIw.DataPlotter(30, ['Decision']) # 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: while True: """ 3.1 ACQUIRE DATA """ # Obtain EEG data from the LSL stream eeg_data, timestamp = inlet.pull_chunk(timeout=1, max_samples=int( shift_length * fs)) # Only keep the channel we're interested in ch_data = np.array(eeg_data)[:, index_channel]
feature_names = BCIw.get_feature_names(ch_names) """ 3. INITIALIZE BUFFERS """ # Initialize raw EEG data buffer (for plotting) eeg_buffer = np.zeros((int(fs * buffer_length), 1)) filter_state = None # for use with the notch filter # Compute the number of epochs in "buffer_length" (used for plotting) n_win_test = int( np.floor((buffer_length - epoch_length) / shift_length + 1)) # Initialize the feature data buffer (for plotting) feat_buffer = np.zeros((n_win_test, len(feature_names))) # Initialize the plots plotter_eeg = BCIw.DataPlotter(fs * buffer_length, ch_names, fs) plotter_feat = BCIw.DataPlotter(n_win_test, feature_names, 1 / shift_length) """ 3. GET DATA """ # 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 raw EEG and the features while True: """ 3.1 ACQUIRE DATA """ # Obtain EEG data from the LSL stream eeg_data, timestamp = inlet.pull_chunk(timeout=1,
ch_names = [i-2 for i in indexes_channel] # Filter b, a = butter_bandpass(4.0, 35.0, fs, order=4) #%% Initialize the buffers for storing raw EEG and features # Initialize raw EEG data buffer (for plotting) eeg_buffer = np.zeros((fs*eeg_buffer_secs, len(indexes_channel))) experiment.tone(500,500) # compute PSD for eeg_buffer [eeg_buffer_psd, f_ax] = experiment.psd_fft(eeg_buffer, fs) # Initialize the plots plotter_time = BCIw.DataPlotter(fs * eeg_buffer_secs, ch_names, fs) plotter_freq = BCIw.DataPlotter(eeg_buffer_psd.shape[0], ch_names, 1/f_ax[1]) #%% Start pulling data mules_client.flushdata() # Flush old data from MuLES # 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: