例子是IIR的5阶实现:
如果要使用,直接修改参数,和阶数即可;
#include <algorithm>
#include <mutex>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
class IIR{
private:
const int NL = 5;
const double b[5] = {0.3, -3., 6, -3., 1};
const int DL = 5;
const double a[5] = { 1, -3., 6, -3, 1};
std::vector<double> coefs;
public:
IIR() {
coefs.resize(DL);
};
double filter(double value)
{
double current_Y = b[0] * value + coefs[0];
for (int i = 1; i < DL; i++)
{
coefs[i - 1] = b[i] * value + coefs[i] - a[i] * current_Y;
}
return current_Y;
}
};