| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef EI_EEG_HPP |
| #define EI_EEG_HPP |
|
|
| #include "edge-impulse-sdk/dsp/ei_dsp_handle.h" |
| #include "edge-impulse-enterprise/eeg/eeg.hpp" |
|
|
| |
| #include "model-parameters/coeffs.hpp" |
|
|
| |
| class eeg_wrap : public ei::eeg_processor { |
| public: |
| void* operator new(size_t size) { |
| return ei_malloc(size); |
| } |
| void operator delete(void* ptr) { |
| ei_free(ptr); |
| } |
| using ei::eeg_processor::eeg_processor; |
| }; |
|
|
| class eeg_class : public DspHandle { |
| public: |
| int print() override { |
| ei_printf("EEG processor: channels=%zu\n", eeg.num_channels); |
| return ei::EIDSP_OK; |
| } |
|
|
| int extract( |
| ei::signal_t *signal, |
| ei::matrix_t *output_matrix, |
| void *config_ptr, |
| const float frequency, |
| ei_impulse_result_t *result) override |
| { |
| using namespace ei; |
| |
| ei_dsp_config_eeg_t& config = *((ei_dsp_config_eeg_t*)config_ptr); |
| size_t floats_per_inc = eeg.win_inc_samples * eeg.num_channels; |
| assert(signal->total_length >= floats_per_inc); |
| int out_idx = 0; |
| for (size_t i = 0; i <= signal->total_length - floats_per_inc; i += floats_per_inc) { |
| matrix_t temp(eeg.win_inc_samples, eeg.num_channels); |
| signal->get_data(i, floats_per_inc, temp.buffer); |
| |
| matrix_t psd_mat(eeg.num_channels, eeg.epoch_samples / 2, output_matrix->buffer + out_idx); |
| eeg.stream(&temp, psd_mat); |
| out_idx += psd_mat.rows * psd_mat.cols; |
| } |
| return EIDSP_OK; |
| } |
|
|
| eeg_class(ei_dsp_config_eeg_t* config, float frequency) |
| : eeg(frequency, |
| config->axes, |
| config->scale_axes, |
| config->motion_sensitivity, |
| (const float*)ei::eeg::filter_coeff, |
| (const float*)ei::eeg::filter_zi, |
| ei::eeg::num_sections, |
| (const float*)ei::eeg::tapers, |
| ei::eeg::num_tapers, |
| (size_t)(frequency * config->epoch_length), |
| true) |
| { |
| |
| } |
|
|
| ~eeg_class() {} |
|
|
| |
| static DspHandle* create(void* config, float frequency); |
|
|
| void* operator new(size_t size) { |
| return ei_malloc(size); |
| } |
|
|
| void operator delete(void* ptr) { |
| ei_free(ptr); |
| } |
| private: |
| eeg_wrap eeg; |
| }; |
|
|
| DspHandle* eeg_class::create(void* config_in, float frequency) { |
| auto config = reinterpret_cast<ei_dsp_config_eeg_t*>(config_in); |
| return new eeg_class(config, frequency); |
| } |
|
|
| #endif |
|
|