4 IIRFilter::IIRFilter(
unsigned int dim, std::vector<double>& fb_coeffs, std::vector<double>& ff_coeffs,
const std::string& error_prefix)
6 std::cerr <<
"This IIRFilter constructure is obsolated method." << std::endl;
11 if(fb_coeffs.size() != dim + 1|| ff_coeffs.size() != dim + 1){
12 std::cout <<
"[" <<
m_error_prefix <<
"]" <<
"IIRFilter coefficients size error" << std::endl;
15 for(std::vector<double>::iterator it = fb_coeffs.begin(); it != fb_coeffs.end(); it++){
18 for(std::vector<double>::iterator it = ff_coeffs.begin(); it != ff_coeffs.end(); it++){
37 if((A.size() != dim && A.size() != dim + 1) || B.size() != dim + 1) {
38 std::cout <<
"[" <<
m_error_prefix <<
"]" <<
"IIRFilter coefficients size error" << std::endl;
46 if (A.size() == dim) {
49 for(std::vector<double>::iterator it = A.begin(); it != A.end(); it++){
50 if (it == A.begin()) {
52 std::cout <<
"[" <<
m_error_prefix <<
"]" <<
"IIRFilter : parameter A[0] is not 1.0 !!!" << std::endl;
59 for(std::vector<double>::iterator it = B.begin(); it != B.end(); it++){
70 std::vector<double> fb_coeffs(3), ff_coeffs(3);
71 const double omega = 2 * 3.14159265 * f_cutoff / hz;
72 const double alpha = std::sin(omega) / (2 * Q);
73 const double denom = 1 + alpha;
75 fb_coeffs[1] = -2 * std::cos(omega) / denom;
76 fb_coeffs[2] = (1 - alpha) / denom;
77 ff_coeffs[0] = (1 - std::cos(omega)) / 2 / denom;
78 ff_coeffs[1] = (1 - std::cos(omega)) / denom;
79 ff_coeffs[2] = (1 - std::cos(omega)) / 2 / denom;
106 double reset_val = initial_input / sum_ff_coeffs;
117 double feedback, filtered;
bool setParameterAsBiquad(const double f_cutoff, const double Q, const double hz)
Simple user interface of setParameter.
std::vector< double > m_ff_coefficients
std::string m_error_prefix
double passFilter(double input)
passFilter
bool setParameter(int dim, std::vector< double > &A, std::vector< double > &B)
Set parameters Y[n] = B[0] * X[n] + B[1] * X[n-1] + ... + B[dim] * X[n-dim] - A[1] * Y[n-1] ...
void reset(double initial_input=0.0)
std::vector< double > m_fb_coefficients
void getParameter(int &dim, std::vector< double > &A, std::vector< double > &B)
IIRFilter(const std::string &error_prefix="")
Constructor.
std::deque< double > m_previous_values