()
| 13 | |
| 14 | |
| 15 | def main(): |
| 16 | BoardShim.enable_dev_board_logger() |
| 17 | |
| 18 | # use synthetic board for demo |
| 19 | params = BrainFlowInputParams() |
| 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(10) |
| 26 | data = board.get_current_board_data(500) |
| 27 | board.stop_stream() |
| 28 | board.release_session() |
| 29 | |
| 30 | # demo how to convert it to pandas DF and plot data |
| 31 | eeg_channels = BoardShim.get_eeg_channels(board_id) |
| 32 | df = pd.DataFrame(np.transpose(data)) |
| 33 | plt.figure() |
| 34 | df[eeg_channels].plot(subplots=True) |
| 35 | plt.savefig('before_processing.png') |
| 36 | |
| 37 | # demo for denoising, apply different methods to different channels for demo |
| 38 | for count, channel in enumerate(eeg_channels): |
| 39 | # first of all you can try simple moving median or moving average with different window size |
| 40 | if count == 0: |
| 41 | DataFilter.perform_rolling_filter(data[channel], 3, AggOperations.MEAN.value) |
| 42 | elif count == 1: |
| 43 | DataFilter.perform_rolling_filter(data[channel], 3, AggOperations.MEDIAN.value) |
| 44 | # if methods above dont work for your signal you can try wavelet based denoising |
| 45 | # feel free to try different parameters |
| 46 | else: |
| 47 | DataFilter.perform_wavelet_denoising(data[channel], WaveletTypes.BIOR3_9, 3, |
| 48 | WaveletDenoisingTypes.SURESHRINK, ThresholdTypes.HARD, |
| 49 | WaveletExtensionTypes.SYMMETRIC, NoiseEstimationLevelTypes.FIRST_LEVEL) |
| 50 | |
| 51 | df = pd.DataFrame(np.transpose(data)) |
| 52 | plt.figure() |
| 53 | df[eeg_channels].plot(subplots=True) |
| 54 | plt.savefig('after_processing.png') |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |
no test coverage detected