MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / main

Function main

python_package/examples/tests/denoising.py:15–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13
14
15def 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
57if __name__ == "__main__":

Callers 1

denoising.pyFile · 0.70

Calls 12

prepare_sessionMethod · 0.95
start_streamMethod · 0.95
stop_streamMethod · 0.95
release_sessionMethod · 0.95
BoardShimClass · 0.90
get_eeg_channelsMethod · 0.65
log_messageMethod · 0.45

Tested by

no test coverage detected