一、用matlab设计巴特沃茨滤波器
%1 低通
fd = 10;%hz 截止频率
fs = 167;%hz 采样频率
wn = fd/(0.5*fs);
%butter 第一个参数为阶数,下面使用的是一阶
[a b]= butter(1,wn,'low')
%2 高通
fd = 10;%hz 截止频率
fs = 167;%hz 采样频率
wn = fd/(0.5*fs);
[c d]= butter(1,wn,'high')
%小测试
t = 0:1/fs:1;
x = cos(2*pi*45*t);
y = filter(a, b,x);
plot(t,y,'r-');hold on;
plot(t,x,'b-');
grid on;
二、在c++中使用滤波器系数
Eigen::Vector3d bufferLow(const Eigen::Vector3d vec) {
static Eigen::Vector3d yn_1(0,0,0), xn_1(0,0,0);
static const double ac[] = { 0.1599 , 0.1599 };
static const double bc[] = { 1.0000 , -0.6801 };
Eigen::Vector3d yn = ac[0] * vec + ac[1] * xn_1 - bc[1] * yn_1 ;
yn_1 = yn;
xn_1 = vec;
return yn;
}
Eigen::Vector3d bufferHig(const Eigen::Vector3d vec) {
static Eigen::Vector3d yn_1(0, 0, 0), xn_1(0, 0, 0);
static const double ac[] = { 0.8401, - 0.8401 };
static const double bc[] = { 1.0000 , -0.6801 };
Eigen::Vector3d yn = ac[0] * vec + ac[1] * xn_1 - bc[1] * yn_1;
yn_1 = yn;
xn_1 = vec;
return yn;
}