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

Function perform_wavelet_denoising

src/data_handler/data_handler.cpp:607–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605}
606
607int perform_wavelet_denoising (double *data, int data_len, int wavelet, int decomposition_level,
608 int wavelet_denoising, int threshold, int extenstion_type, int noise_level)
609{
610 std::string wavelet_str = get_wavelet_name (wavelet);
611 std::string denoising_str = get_wavelet_denoising_type (wavelet_denoising);
612 std::string threshold_str = get_threshold_type (threshold);
613 std::string extension_str = get_extension_type (extenstion_type);
614 std::string noise_str = get_noise_estimation_type (noise_level);
615 if ((data == NULL) || (data_len <= 0) || (decomposition_level <= 0) || (wavelet_str.empty ()) ||
616 (denoising_str.empty ()) || (threshold_str.empty ()) || (extension_str.empty ()) ||
617 (noise_str.empty ()))
618 {
619 data_logger->error ("Please review arguments.");
620 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
621 }
622
623 denoise_object obj = NULL;
624 double *temp = new double[data_len];
625 try
626 {
627 obj = denoise_init (data_len, decomposition_level, wavelet_str.c_str ());
628 setDenoiseMethod (obj, denoising_str.c_str ());
629 setDenoiseWTMethod (obj, "dwt");
630 setDenoiseWTExtension (obj, extension_str.c_str ());
631 setDenoiseParameters (obj, threshold_str.c_str (), noise_str.c_str ());
632 denoise (obj, data, temp);
633 for (int i = 0; i < data_len; i++)
634 {
635 data[i] = temp[i];
636 }
637 delete[] temp;
638 temp = NULL;
639 denoise_free (obj);
640 obj = NULL;
641 }
642 catch (const std::exception &e)
643 {
644 if (temp)
645 {
646 delete[] temp;
647 temp = NULL;
648 }
649 if (obj)
650 {
651 denoise_free (obj);
652 obj = NULL;
653 }
654 // more likely exception here occured because input buffer is to small to perform wavelet
655 // transform
656 data_logger->error ("Exception in wavelib: {}", e.what ());
657 return (int)BrainFlowExitCodes::INVALID_BUFFER_SIZE_ERROR;
658 }
659 return (int)BrainFlowExitCodes::STATUS_OK;
660}
661
662int get_csp (const double *data, const double *labels, int n_epochs, int n_channels, int n_times,
663 double *output_w, double *output_d)

Callers 2

mainFunction · 0.50

Calls 7

get_wavelet_nameFunction · 0.85
get_threshold_typeFunction · 0.85
get_extension_typeFunction · 0.85
emptyMethod · 0.80
whatMethod · 0.80

Tested by

no test coverage detected