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

Function main

python_package/examples/tests/transforms.py:7–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6
7def main():
8 BoardShim.enable_dev_board_logger()
9
10 # use synthetic board for demo
11 params = BrainFlowInputParams()
12 board_id = BoardIds.SYNTHETIC_BOARD.value
13 sampling_rate = BoardShim.get_sampling_rate(board_id)
14 board = BoardShim(board_id, params)
15 board.prepare_session()
16 board.start_stream()
17 BoardShim.log_message(LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
18 time.sleep(10)
19 data = board.get_current_board_data(256)
20 board.stop_stream()
21 board.release_session()
22
23 eeg_channels = BoardShim.get_eeg_channels(board_id)
24 # demo for transforms
25 for count, channel in enumerate(eeg_channels):
26 print('Original data for channel %d:' % channel)
27 print(data[channel])
28 # demo for wavelet transforms
29 # wavelet_coeffs format is[A(J) D(J) D(J-1) ..... D(1)] where J is decomposition level, A - app coeffs, D - detailed coeffs
30 # lengths array stores lengths for each block
31 wavelet_coeffs, lengths = DataFilter.perform_wavelet_transform(data[channel], WaveletTypes.DB5, 3)
32 app_coefs = wavelet_coeffs[0: lengths[0]]
33 detailed_coeffs_first_block = wavelet_coeffs[lengths[0]: lengths[1]]
34 # you can do smth with wavelet coeffs here, for example denoising works via thresholds
35 # for wavelets coefficients
36 restored_data = DataFilter.perform_inverse_wavelet_transform((wavelet_coeffs, lengths), data[channel].shape[0],
37 WaveletTypes.DB5, 3)
38 print('Restored data after wavelet transform for channel %d:' % channel)
39 print(restored_data)
40
41 # demo for fft, len of data must be a power of 2
42 fft_data = DataFilter.perform_fft(data[channel], WindowOperations.NO_WINDOW.value)
43 # len of fft_data is N / 2 + 1
44 restored_fft_data = DataFilter.perform_ifft(fft_data)
45 print('Restored data after fft for channel %d:' % channel)
46 print(restored_fft_data)
47
48
49if __name__ == "__main__":

Callers 1

transforms.pyFile · 0.70

Calls 15

prepare_sessionMethod · 0.95
start_streamMethod · 0.95
stop_streamMethod · 0.95
release_sessionMethod · 0.95
BoardShimClass · 0.90
get_sampling_rateMethod · 0.65
get_eeg_channelsMethod · 0.65
perform_fftMethod · 0.65

Tested by

no test coverage detected