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

Function main

cpp_package/examples/signal_processing/src/transforms.cpp:20–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20int main (int argc, char *argv[])
21{
22 BoardShim::enable_dev_board_logger ();
23
24 struct BrainFlowInputParams params;
25 int res = 0;
26 // use synthetic board for demo
27 BoardShim *board = new BoardShim ((int)BoardIds::SYNTHETIC_BOARD, params);
28
29 try
30 {
31 board->prepare_session ();
32 board->start_stream ();
33
34#ifdef _WIN32
35 Sleep (10000);
36#else
37 sleep (10);
38#endif
39
40 board->stop_stream ();
41 BrainFlowArray<double, 2> data = board->get_current_board_data (128);
42 board->release_session ();
43 std::cout << "Original data:" << std::endl << data << std::endl;
44
45 // apply filters
46 int sampling_rate = BoardShim::get_sampling_rate ((int)BoardIds::SYNTHETIC_BOARD);
47 std::vector<int> eeg_channels =
48 BoardShim::get_eeg_channels ((int)BoardIds::SYNTHETIC_BOARD);
49 int data_count = data.get_size (1);
50 for (int i = 0; i < eeg_channels.size (); i++)
51 {
52 // demo for wavelet transform
53 // std::pair of coeffs array in format[A(J) D(J) D(J-1) ..... D(1)] where J is a
54 // decomposition level, A - app coeffs, D - detailed coeffs, and array which stores
55 // length for each block, len of this array is decomposition_length + 1
56 std::pair<double *, int *> wavelet_output = DataFilter::perform_wavelet_transform (
57 data.get_address (eeg_channels[i]), data_count, (int)WaveletTypes::DB3, 3);
58 // you can do smth with wavelet coeffs here, for example denoising works via thresholds
59 // for wavelet coefficients
60 std::cout << "approximation coefficients:" << std::endl;
61 for (int i = 0; i < wavelet_output.second[0]; i++)
62 {
63 std::cout << wavelet_output.first[i] << " ";
64 }
65 std::cout << std::endl;
66 std::cout << "first block of detailed coefficients:" << std::endl;
67 for (int i = wavelet_output.second[0];
68 i < wavelet_output.second[0] + wavelet_output.second[1]; i++)
69 {
70 std::cout << wavelet_output.first[i] << " ";
71 }
72 std::cout << std::endl;
73
74 double *restored_data = DataFilter::perform_inverse_wavelet_transform (
75 wavelet_output, data_count, (int)WaveletTypes::DB3, 3);
76
77 std::cout << "Original data:" << std::endl;

Callers

nothing calls this directly

Calls 15

enable_dev_board_loggerFunction · 0.85
get_sampling_rateFunction · 0.85
get_sizeMethod · 0.80
whatMethod · 0.80
print_one_rowFunction · 0.70
prepare_sessionMethod · 0.65
start_streamMethod · 0.65
stop_streamMethod · 0.65
release_sessionMethod · 0.65
is_preparedMethod · 0.65
sleepFunction · 0.50

Tested by

no test coverage detected