| 319 | } |
| 320 | |
| 321 | int perform_bandstop (double *data, int data_len, int sampling_rate, double start_freq, |
| 322 | double stop_freq, int order, int filter_type, double ripple) |
| 323 | { |
| 324 | if ((order < 1) || (order > MAX_FILTER_ORDER) || (!data) || (stop_freq <= start_freq) || |
| 325 | (start_freq < 0) || (sampling_rate < 1)) |
| 326 | { |
| 327 | data_logger->error ("Order must be from 1-8 and data cannot be empty. Order:{} , Data:{} , " |
| 328 | "Start Freq:{} , Stop Freq:{}", |
| 329 | order, (data != NULL), start_freq, stop_freq); |
| 330 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 331 | } |
| 332 | |
| 333 | double center_freq = (start_freq + stop_freq) / 2.0; |
| 334 | double band_width = stop_freq - start_freq; |
| 335 | Dsp::Filter *f = NULL; |
| 336 | double *filter_data[1]; |
| 337 | filter_data[0] = data; |
| 338 | |
| 339 | switch (static_cast<FilterTypes> (filter_type)) |
| 340 | { |
| 341 | case FilterTypes::BUTTERWORTH: |
| 342 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 343 | break; |
| 344 | case FilterTypes::BUTTERWORTH_ZERO_PHASE: |
| 345 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 346 | break; |
| 347 | case FilterTypes::CHEBYSHEV_TYPE_1: |
| 348 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 349 | break; |
| 350 | case FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE: |
| 351 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 352 | break; |
| 353 | case FilterTypes::BESSEL: |
| 354 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 355 | break; |
| 356 | case FilterTypes::BESSEL_ZERO_PHASE: |
| 357 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::BandStop<MAX_FILTER_ORDER>, 1> (); |
| 358 | break; |
| 359 | default: |
| 360 | data_logger->error ("Filter type {} is Invalid", filter_type); |
| 361 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 362 | } |
| 363 | |
| 364 | Dsp::Params params; |
| 365 | params[0] = sampling_rate; // sample rate |
| 366 | params[1] = order; // order |
| 367 | params[2] = center_freq; // center freq |
| 368 | params[3] = band_width; |
| 369 | if ((filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1) || |
| 370 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE)) |
| 371 | { |
| 372 | params[3] = ripple; // ripple |
| 373 | } |
| 374 | f->setParams (params); |
| 375 | f->process (data_len, filter_data); |
| 376 | if ((filter_type == (int)FilterTypes::BUTTERWORTH_ZERO_PHASE) || |
| 377 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE) || |
| 378 | (filter_type == (int)FilterTypes::BESSEL_ZERO_PHASE)) |
no test coverage detected