| 251 | } |
| 252 | |
| 253 | int perform_bandpass (double *data, int data_len, int sampling_rate, double start_freq, |
| 254 | double stop_freq, int order, int filter_type, double ripple) |
| 255 | { |
| 256 | if ((order < 1) || (order > MAX_FILTER_ORDER) || (!data) || (stop_freq <= start_freq) || |
| 257 | (start_freq < 0) || (sampling_rate < 1)) |
| 258 | { |
| 259 | data_logger->error ("Order must be from 1-8 and data cannot be empty. Order:{} , Data:{} , " |
| 260 | "Start Freq:{} , Stop Freq:{}", |
| 261 | order, (data != NULL), start_freq, stop_freq); |
| 262 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 263 | } |
| 264 | |
| 265 | double center_freq = (start_freq + stop_freq) / 2.0; |
| 266 | double band_width = stop_freq - start_freq; |
| 267 | Dsp::Filter *f = NULL; |
| 268 | double *filter_data[1]; |
| 269 | filter_data[0] = data; |
| 270 | |
| 271 | switch (static_cast<FilterTypes> (filter_type)) |
| 272 | { |
| 273 | case FilterTypes::BUTTERWORTH: |
| 274 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 275 | break; |
| 276 | case FilterTypes::BUTTERWORTH_ZERO_PHASE: |
| 277 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 278 | break; |
| 279 | case FilterTypes::CHEBYSHEV_TYPE_1: |
| 280 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 281 | break; |
| 282 | case FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE: |
| 283 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 284 | break; |
| 285 | case FilterTypes::BESSEL: |
| 286 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 287 | break; |
| 288 | case FilterTypes::BESSEL_ZERO_PHASE: |
| 289 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::BandPass<MAX_FILTER_ORDER>, 1> (); |
| 290 | break; |
| 291 | default: |
| 292 | data_logger->error ("Filter type {} is Invalid. ", filter_type); |
| 293 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 294 | } |
| 295 | |
| 296 | Dsp::Params params; |
| 297 | params[0] = sampling_rate; // sample rate |
| 298 | params[1] = order; // order |
| 299 | params[2] = center_freq; // center freq |
| 300 | params[3] = band_width; |
| 301 | if ((filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1) || |
| 302 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE)) |
| 303 | { |
| 304 | params[3] = ripple; // ripple |
| 305 | } |
| 306 | f->setParams (params); |
| 307 | f->process (data_len, filter_data); |
| 308 | if ((filter_type == (int)FilterTypes::BUTTERWORTH_ZERO_PHASE) || |
| 309 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE) || |
| 310 | (filter_type == (int)FilterTypes::BESSEL_ZERO_PHASE)) |
no test coverage detected