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

Function main

cpp_package/examples/signal_processing/src/denoising.cpp:17–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17int main (int argc, char *argv[])
18{
19 BoardShim::enable_dev_board_logger ();
20
21 struct BrainFlowInputParams params;
22 int res = 0;
23 int board_id = (int)BoardIds::SYNTHETIC_BOARD;
24 // use synthetic board for demo
25 BoardShim *board = new BoardShim (board_id, params);
26
27 try
28 {
29 board->prepare_session ();
30 board->start_stream ();
31
32#ifdef _WIN32
33 Sleep (5000);
34#else
35 sleep (5);
36#endif
37
38 board->stop_stream ();
39 BrainFlowArray<double, 2> data = board->get_board_data ();
40 board->release_session ();
41 std::cout << "Original data:" << std::endl << data << std::endl;
42
43 // apply filters
44 std::vector<int> eeg_channels = BoardShim::get_eeg_channels (board_id);
45 for (int i = 0; i < eeg_channels.size (); i++)
46 {
47 switch (i)
48 {
49 // for demo apply different methods to different channels
50 case 0:
51 DataFilter::perform_rolling_filter (data.get_address (eeg_channels[i]),
52 data.get_size (1), 3, (int)AggOperations::MEDIAN);
53 break;
54 case 1:
55 DataFilter::perform_rolling_filter (data.get_address (eeg_channels[i]),
56 data.get_size (1), 3, (int)AggOperations::MEAN);
57 break;
58 default:
59 // if moving average and moving median dont work well for your signal you can
60 // try wavelet based denoising, feel free to try different wavelet functions and
61 // decomposition levels
62 DataFilter::perform_wavelet_denoising (data.get_address (eeg_channels[i]),
63 data.get_size (1), (int)WaveletTypes::BIOR3_9, 3,
64 (int)WaveletDenoisingTypes::SURESHRINK, (int)ThresholdTypes::HARD,
65 (int)WaveletExtensionTypes::SYMMETRIC,
66 (int)NoiseEstimationLevelTypes::FIRST_LEVEL);
67 break;
68 }
69 }
70 std::cout << "Data after denoising:" << std::endl << data << std::endl;
71 }
72 catch (const BrainFlowException &err)
73 {
74 BoardShim::log_message ((int)LogLevels::LEVEL_ERROR, err.what ());

Callers

nothing calls this directly

Calls 15

enable_dev_board_loggerFunction · 0.85
get_sizeMethod · 0.80
whatMethod · 0.80
prepare_sessionMethod · 0.65
start_streamMethod · 0.65
stop_streamMethod · 0.65
get_board_dataMethod · 0.65
release_sessionMethod · 0.65
is_preparedMethod · 0.65
sleepFunction · 0.50
get_eeg_channelsFunction · 0.50
perform_rolling_filterFunction · 0.50

Tested by

no test coverage detected