| 188 | } |
| 189 | |
| 190 | int perform_highpass (double *data, int data_len, int sampling_rate, double cutoff, int order, |
| 191 | int filter_type, double ripple) |
| 192 | { |
| 193 | if ((order < 1) || (order > MAX_FILTER_ORDER) || (!data) || (cutoff < 0) || (sampling_rate < 1)) |
| 194 | { |
| 195 | data_logger->error ( |
| 196 | "Order must be from 1-8 and data cannot be empty. Order:{} , Data:{} , Cutoff:{}", |
| 197 | order, (data != NULL), cutoff); |
| 198 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 199 | } |
| 200 | |
| 201 | Dsp::Filter *f = NULL; |
| 202 | double *filter_data[1]; |
| 203 | filter_data[0] = data; |
| 204 | |
| 205 | switch (static_cast<FilterTypes> (filter_type)) |
| 206 | { |
| 207 | case FilterTypes::BUTTERWORTH: |
| 208 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 209 | break; |
| 210 | case FilterTypes::BUTTERWORTH_ZERO_PHASE: |
| 211 | f = new Dsp::FilterDesign<Dsp::Butterworth::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 212 | break; |
| 213 | case FilterTypes::CHEBYSHEV_TYPE_1: |
| 214 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 215 | break; |
| 216 | case FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE: |
| 217 | f = new Dsp::FilterDesign<Dsp::ChebyshevI::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 218 | break; |
| 219 | case FilterTypes::BESSEL: |
| 220 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 221 | break; |
| 222 | case FilterTypes::BESSEL_ZERO_PHASE: |
| 223 | f = new Dsp::FilterDesign<Dsp::Bessel::Design::HighPass<MAX_FILTER_ORDER>, 1> (); |
| 224 | break; |
| 225 | default: |
| 226 | data_logger->error ("Filter type {} is Invalid", filter_type); |
| 227 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 228 | } |
| 229 | Dsp::Params params; |
| 230 | params[0] = sampling_rate; // sample rate |
| 231 | params[1] = order; // order |
| 232 | params[2] = cutoff; // cutoff |
| 233 | if ((filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1) || |
| 234 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE)) |
| 235 | { |
| 236 | params[3] = ripple; // ripple |
| 237 | } |
| 238 | f->setParams (params); |
| 239 | f->process (data_len, filter_data); |
| 240 | if ((filter_type == (int)FilterTypes::BUTTERWORTH_ZERO_PHASE) || |
| 241 | (filter_type == (int)FilterTypes::CHEBYSHEV_TYPE_1_ZERO_PHASE) || |
| 242 | (filter_type == (int)FilterTypes::BESSEL_ZERO_PHASE)) |
| 243 | { |
| 244 | reverse_array (data, data_len); |
| 245 | f->process (data_len, filter_data); |
| 246 | reverse_array (data, data_len); |
| 247 | } |
no test coverage detected