| 15 | |
| 16 | |
| 17 | int 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 (10000); |
| 34 | #else |
| 35 | sleep (10); |
| 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 | // calc band powers |
| 44 | json board_descr = BoardShim::get_board_descr (board_id); |
| 45 | int sampling_rate = (int)board_descr["sampling_rate"]; |
| 46 | int fft_len = DataFilter::get_nearest_power_of_two (sampling_rate); |
| 47 | std::vector<int> eeg_channels = board_descr["eeg_channels"]; |
| 48 | // for synthetic board second channel is a sine wave at 10 Hz, should see big alpha |
| 49 | int channel = eeg_channels[1]; |
| 50 | // optional - detrend |
| 51 | DataFilter::detrend ( |
| 52 | data.get_address (channel), data.get_size (1), (int)DetrendOperations::LINEAR); |
| 53 | std::cout << "Data after detrend:" << std::endl << data << std::endl; |
| 54 | int psd_len = 0; |
| 55 | std::pair<double *, double *> psd = |
| 56 | DataFilter::get_psd_welch (data.get_address (channel), data.get_size (1), fft_len, |
| 57 | fft_len / 2, sampling_rate, (int)WindowOperations::HANNING, &psd_len); |
| 58 | // calc band power |
| 59 | double band_power_alpha = DataFilter::get_band_power (psd, psd_len, 7.0, 13.0); |
| 60 | double band_power_beta = DataFilter::get_band_power (psd, psd_len, 14.0, 30.0); |
| 61 | std::cout << "alpha/beta:" << band_power_alpha / band_power_beta << std::endl; |
| 62 | delete[] psd.first; |
| 63 | delete[] psd.second; |
| 64 | } |
| 65 | catch (const BrainFlowException &err) |
| 66 | { |
| 67 | BoardShim::log_message ((int)LogLevels::LEVEL_ERROR, err.what ()); |
| 68 | res = err.exit_code; |
| 69 | if (board->is_prepared ()) |
| 70 | { |
| 71 | board->release_session (); |
| 72 | } |
| 73 | } |
| 74 |
nothing calls this directly
no test coverage detected