()
| 12 | |
| 13 | |
| 14 | def main(): |
| 15 | BoardShim.enable_dev_board_logger() |
| 16 | DataFilter.enable_dev_data_logger() |
| 17 | |
| 18 | params = BrainFlowInputParams() |
| 19 | #board_id = BoardIds.MUSE_2_BOARD |
| 20 | board_id = BoardIds.SYNTHETIC_BOARD.value |
| 21 | board = BoardShim(board_id, params) |
| 22 | board.prepare_session() |
| 23 | board.start_stream() |
| 24 | BoardShim.log_message(LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread') |
| 25 | time.sleep(5) |
| 26 | data = board.get_board_data() |
| 27 | board.stop_stream() |
| 28 | board.release_session() |
| 29 | |
| 30 | eeg_channels = BoardShim.get_eeg_channels(board_id) |
| 31 | df = pd.DataFrame(np.transpose(data)) |
| 32 | plt.figure() |
| 33 | df[eeg_channels].plot(subplots=True) |
| 34 | plt.savefig('before_processing.png') |
| 35 | |
| 36 | df_wavelets = pd.DataFrame(np.transpose(data)) |
| 37 | df_peaks = pd.DataFrame(np.transpose(data)) |
| 38 | |
| 39 | for count, channel in enumerate(eeg_channels): |
| 40 | DataFilter.detrend(data[channel], DetrendOperations.CONSTANT) |
| 41 | DataFilter.remove_environmental_noise(data[channel], BoardShim.get_sampling_rate(board_id), NoiseTypes.FIFTY_AND_SIXTY) |
| 42 | # idea is to remove some components with noise and local extremas |
| 43 | # todo https://github.com/brainflow-dev/brainflow/issues/538 |
| 44 | data[channel] = DataFilter.restore_data_from_wavelet_detailed_coeffs(data[channel], WaveletTypes.DB4, 6, 4) |
| 45 | df_wavelets[channel] = data[channel] |
| 46 | # try different params for lag, influence and threshold, more info here https://stackoverflow.com/a/22640362 |
| 47 | # you can also try it wo wavelets |
| 48 | df_peaks[channel] = DataFilter.detect_peaks_z_score(data[channel], lag=20, influence=0.1, threshold=3.5) |
| 49 | |
| 50 | plt.figure() |
| 51 | df_wavelets[eeg_channels].plot(subplots=True) |
| 52 | plt.savefig('wavelets.png') |
| 53 | |
| 54 | plt.figure() |
| 55 | df_peaks[eeg_channels].plot(subplots=True) |
| 56 | plt.savefig('peaks.png') |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |
no test coverage detected