# Record data for mental activity 1 BCIw.beep() # Beep sound eeg_data1, timestamps1 = inlet.pull_chunk(timeout=training_length + 1, max_samples=fs * training_length) eeg_data1 = np.array(eeg_data1)[:, index_channel] # Divide data into epochs eeg_epochs0 = BCIw.epoch(eeg_data0, epoch_length * fs, overlap_length * fs) eeg_epochs1 = BCIw.epoch(eeg_data1, epoch_length * fs, overlap_length * fs) """ 4. COMPUTE FEATURES AND TRAIN CLASSIFIER """ feat_matrix0 = BCIw.compute_feature_matrix(eeg_epochs0, fs) 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>
eeg_data1, timestamps1 = inlet.pull_chunk( timeout=training_length+1, max_samples=fs * training_length) eeg_data1 = np.array(eeg_data1)[:, index_channel] # Divide data into epochs eeg_epochs0 = BCIw.epoch(eeg_data0, epoch_length * fs, overlap_length * fs) eeg_epochs1 = BCIw.epoch(eeg_data1, epoch_length * fs, overlap_length * fs) """ 4. COMPUTE FEATURES AND TRAIN CLASSIFIER """ feat_matrix0 = BCIw.compute_feature_matrix(eeg_epochs0, fs) 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
eeg_data1, timestamps1 = inlet.pull_chunk( timeout=training_length+1, max_samples=fs * training_length) eeg_data1 = np.array(eeg_data1)[:, index_channel] # Divide data into epochs eeg_epochs0 = BCIw.epoch(eeg_data0, epoch_length * fs, overlap_length * fs) eeg_epochs1 = BCIw.epoch(eeg_data1, epoch_length * fs, overlap_length * fs) """ 4. COMPUTE FEATURES AND TRAIN CLASSIFIER """ feat_matrix0 = BCIw.compute_feature_matrix(eeg_epochs0, fs) feat_matrix1 = BCIw.compute_feature_matrix(eeg_epochs1, fs) [classifier, mu_ft, std_ft] = BCIw.train_classifier( feat_matrix0, feat_matrix1, 'SVM') 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.')