一种去掉偶尔产生不规则极端数值点的滤波方法

1,matlab代码
close all; clc;
clear all;
st=200:-4:1; %采集150个数据,每次减1
st=zeros(1,200)+10; %采集150个数据,每次减1
%y = awgn(x,SNR,SIGPOWER)信噪比SNR以dB为单位;如果SIGPOWER是数值,则其代表以dBW为单位的信号强度;如果SIGPOWER为'measured',则函数将在加入噪声之前测定信号强度
St_noise=awgn(st,10,'measured');
figure; plot(st); hold on;
plot(St_noise); hold off;

% #define NZEROS 2
% #define NPOLES 2
GAIN=1.804169259e+02; %GAIN=180;

xv=zeros(1,3);
yv=zeros(1,3);
【一种去掉偶尔产生不规则极端数值点的滤波方法】
for i=1:length(St_noise)
xv(1)=xv(2);
xv(2) = xv(3);
xv(3)=St_noise(i)/GAIN;

disp(xv(2));
disp(xv(3));
yv(1)=yv(2);
yv(2) = yv(3);
yv(3)=(xv(1) + xv(3)) + 2 * xv(2) + ( -0.8008026467 * yv(1)) + ( 1.7786317778 * yv(2));
St_iir(i)= yv(3);
end
figure; plot(st); hold on;
plot(St_iir(1:length(St_iir))); hold off;
2,C语言写法
#define NZEROS 2
#define NPOLES 2
#define GAIN 1.804169259e+02
static float xv[NZEROS+1], yv[NPOLES+1];
static void filterloop()
{
for (; ; )
{
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = next input value / GAIN;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (xv[0] + xv[2]) + 2 * xv[1]+ ( -0.8008026467 * yv[0]) + ( 1.7786317778 * yv[1]);
next output value = https://www.it610.com/article/yv[2];
}
}

    推荐阅读