Repository navigation
improve bandpower calculations and cleanup data handling #866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f014dcc
improve bandpower calculations and cleanup data handling
Andrey1994 e417389
Add omitted signal processing and classifier assets
Andrey1994 a3941b9
Avoid Windows max macro in array overflow checks
Andrey1994 3ede827
Accept CI commit hashes in Rust version tests
Andrey1994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,33 @@ | ||
| #include <cmath> | ||
| #include <iostream> | ||
| #include <stdlib.h> | ||
| #include <string> | ||
|
|
||
| #ifdef _WIN32 | ||
| #include <windows.h> | ||
| #else | ||
| #include <unistd.h> | ||
| #endif | ||
|
|
||
| #include "board_shim.h" | ||
| #include "data_filter.h" | ||
|
|
||
| using namespace std; | ||
|
|
||
|
|
||
| int main (int argc, char *argv[]) | ||
| int main () | ||
| { | ||
| BoardShim::enable_dev_board_logger (); | ||
|
|
||
| struct BrainFlowInputParams params; | ||
| int res = 0; | ||
| int board_id = (int)BoardIds::SYNTHETIC_BOARD; | ||
| std::vector<int> eeg_channels = BoardShim::get_eeg_channels (board_id); | ||
| int channel_to_use = eeg_channels[4]; | ||
| // use synthetic board for demo | ||
| BoardShim *board = new BoardShim (board_id, params); | ||
|
|
||
| // Two simultaneous mixtures of non-Gaussian sources: rows are channels, columns are samples. | ||
| const int samples = 1024; | ||
| const double pi = std::acos (-1.0); | ||
| BrainFlowArray<double, 2> data (2, samples); | ||
| for (int i = 0; i < samples; i++) | ||
| { | ||
| double t = i / 256.0; | ||
| double first = std::sin (2.0 * pi * 7.0 * t); | ||
| double second = std::pow (std::sin (2.0 * pi * 13.0 * t), 3); | ||
| data.at (0, i) = first + 0.3 * second; | ||
| data.at (1, i) = 0.2 * first + second; | ||
| } | ||
| try | ||
| { | ||
| board->prepare_session (); | ||
| board->start_stream (); | ||
|
|
||
| #ifdef _WIN32 | ||
| Sleep (10000); | ||
| #else | ||
| sleep (10); | ||
| #endif | ||
|
|
||
| board->stop_stream (); | ||
| BrainFlowArray<double, 2> data = | ||
| board->get_board_data (500, (int)BrainFlowPresets::DEFAULT_PRESET); | ||
| board->release_session (); | ||
|
|
||
| BrainFlowArray<double, 2> data_reshaped (data.get_address (channel_to_use), 5, 100); | ||
| std::tuple<BrainFlowArray<double, 2>, BrainFlowArray<double, 2>, BrainFlowArray<double, 2>, | ||
| BrainFlowArray<double, 2>> | ||
| returned_matrixes = DataFilter::perform_ica (data_reshaped, 2); | ||
| std::cout << std::get<3> (returned_matrixes) << std::endl; | ||
| auto result = DataFilter::perform_ica (data, 2); | ||
| // Component order and sign are arbitrary. | ||
| std::cout << "Recovered " << std::get<3> (result).get_size (0) << " sources from " | ||
| << samples << " samples" << std::endl; | ||
| } | ||
| catch (const BrainFlowException &err) | ||
| { | ||
| BoardShim::log_message ((int)LogLevels::LEVEL_ERROR, err.what ()); | ||
| res = err.exit_code; | ||
| if (board->is_prepared ()) | ||
| { | ||
| board->release_session (); | ||
| } | ||
| std::cerr << err.what () << std::endl; | ||
| return err.exit_code; | ||
| } | ||
|
|
||
| delete board; | ||
|
|
||
| return res; | ||
| return 0; | ||
| } |
75 changes: 75 additions & 0 deletions
75
cpp_package/examples/signal_processing/src/signal_processing_regression.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #include <cmath> | ||
| #include <functional> | ||
| #include <iostream> | ||
| #include <limits> | ||
| #include <stdexcept> | ||
|
|
||
| #include "data_filter.h" | ||
|
|
||
| static void reject (const std::function<void ()> &action) | ||
| { | ||
| try | ||
| { | ||
| action (); | ||
| } | ||
| catch (const BrainFlowException &) | ||
| { | ||
| return; | ||
| } | ||
| throw std::runtime_error ("Expected invalid input to be rejected"); | ||
| } | ||
|
|
||
| int main () | ||
| { | ||
| BrainFlowArray<double, 2> data (2, 256); | ||
| reject ([&] { data.at (-1, 0); }); | ||
| reject ([&] { data.at (0, 256); }); | ||
| reject ([&] { data.get_address (-1); }); | ||
| reject ([&] { data[-1]; }); | ||
| reject ([&] { BrainFlowArray<double, 2> invalid (-1, 256); }); | ||
| reject ( | ||
| [&] { | ||
| DataFilter::get_csp ( | ||
| BrainFlowArray<double, 3> (2, 2, 8), BrainFlowArray<double, 1> (1)); | ||
| }); | ||
| reject ([&] { DataFilter::perform_ica (data, 2, {-1, 1}); }); | ||
| reject ([&] { DataFilter::get_avg_band_powers (data, {-1}, 256, false); }); | ||
| reject ([&] { DataFilter::perform_fft (data.get_raw_ptr (), 256, 0, nullptr); }); | ||
| reject ([&] { DataFilter::get_psd (data.get_raw_ptr (), 256, 256, 0, nullptr); }); | ||
| reject ([&] { DataFilter::perform_wavelet_transform (data.get_raw_ptr (), 256, 3, -1); }); | ||
| reject ( | ||
| [&] { | ||
| DataFilter::perform_inverse_wavelet_transform ( | ||
| std::vector<double> (4), {2, 2}, 8, 3, 2); | ||
| }); | ||
| for (int original_length : | ||
| {4, std::numeric_limits<int>::max () / 2, std::numeric_limits<int>::max ()}) | ||
| reject ( | ||
| [&] | ||
| { | ||
| DataFilter::perform_inverse_wavelet_transform ( | ||
| std::vector<double> (2), {1, 1}, original_length, 0, 1); | ||
| }); | ||
|
|
||
| std::vector<double> input (256); | ||
| for (size_t i = 0; i < input.size (); ++i) | ||
| input[i] = std::sin (0.1 * i); | ||
| auto transform = | ||
| DataFilter::perform_wavelet_transform (input.data (), (int)input.size (), 3, 3); | ||
| std::vector<int> lengths (transform.second, transform.second + 4); | ||
| int total = 0; | ||
| for (int length : lengths) | ||
| total += length; | ||
| std::vector<double> coefficients (transform.first, transform.first + total); | ||
| delete[] transform.first; | ||
| delete[] transform.second; | ||
| auto restored = | ||
| DataFilter::perform_inverse_wavelet_transform (coefficients, lengths, 256, 3, 3); | ||
| for (size_t i = 0; i < input.size (); ++i) | ||
| if (std::abs (input[i] - restored[i]) > 1e-10) | ||
| throw std::runtime_error ("Wavelet round trip failed"); | ||
| lengths[0]++; | ||
| reject ( | ||
| [&] { DataFilter::perform_inverse_wavelet_transform (coefficients, lengths, 256, 3, 3); }); | ||
| std::cout << "Signal-processing binding validation passed." << std::endl; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repository tree contains no
src/signal_processing_regression.cpp, so both Unix and Windows fail while configuring the signal-processing examples before this target can run. The new workflow steps likewise reference five absent Python scripts, an absent C# project, and an absent Java regression class, so merely fixing this C++ source still leaves both CI workflows guaranteed to fail; add the regression assets or remove their targets and invocations.Useful? React with 👍 / 👎.