中值滤波在消除脉冲噪声中的应用以及其Maltab程序

中值滤波是一种可以有效的消除脉冲噪声的滤波算法,其滤波方法是每次取N(一般为奇数)个采样点,然后按照数据的大小进行排序,最后取中间值作为本次滤波的结果。这里分别取N=5和N=11对实测加速度信号进行处理,滤波效果图3-4所示。

从图可以看出,当取11个点时,滤波效果更好。此外在滤波过程中,根据算法原理,需要在每一个采样点进行了一次N点的排序运算(冒泡法排序),因此当信号的数据量较大以及N取值较大时,计算量稍大。

中值滤波算法的相关Matlab程序如下:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qhdata_43_8_201301GT
t=0:0.049*1.024:(0.049*1.024*1953);
t(end)=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear acceleration_Filter cc cs displace maxPress min middleIndex 
clear PeakDetector press_buff startIndex v press
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a0=accele_Raw(99,:);
a0=a0(80:688);
a1=accele_Raw(18,:);
a1=a1(74:684);
a2=accele_Raw(52,:);
a2=a2(24:end);
a=[a0 a1 a2];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%中值滤波
N = 5; 
ind = round(N / 2) - 1; 
len = length( a ); 
a1 = zeros(1, len);
for iter = ( ind + 1) : len - ind
    input = a(1, iter-ind : iter+ind);
    %冒泡法排序。
    for i = 1 : N - 1
        for j = 1 : N - 1
            if(input(1, j) > input(1, j + 1))
                temp = input(1, j);
                input( 1, j) = input(1, j + 1);
                input( 1, j+1) = temp;
            end
        end
    end
    a1(1, iter)  = input(1, ind + 1 );
end
t1=t;
a1((len - ind):end)=[];
t1((len - ind):end)=[];
a1(1:ind)=[];
t1(1:ind)=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clear i ind input iter j len N temp
% clearvars -except t2 a2 a t
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%中值滤波
N = 11; 
ind = round(N / 2) - 1; 
len = length( a ); 
a2 = zeros(1, len);
for iter = ( ind + 1) : len - ind
    input = a(1, iter-ind : iter+ind);
    %冒泡法排序。
    for i = 1 : N - 1
        for j = 1 : N - 1
            if(input(1, j) > input(1, j + 1))
                temp = input(1, j);
                input( 1, j) = input(1, j + 1);
                input( 1, j+1) = temp;
            end
        end
    end
    a2(1, iter)  = input(1, ind + 1 );
end
t2=t;
a2((len - ind):end)=[];
t2((len - ind):end)=[];
a2(1:ind)=[];
t2(1:ind)=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clear i ind input iter j len N temp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,1)
plot(t1,a1)
xlabel('时间/s','fontsize',10.5)
ylabel('加速度/m·s^{-2}','fontsize',10.5)
legend('处理后的加速度信号','Location','SouthWest');
l1=legend('N=5时滤波后的加速度信号');
set(l1,'fontsize',10.5)
axis([0 100 0.5 3.5])
 
subplot(2,1,2)
plot(t2,a2)
xlabel('时间/s','fontsize',10.5)
ylabel('加速度/m·s^{-2}','fontsize',10.5)
legend('处理后的加速度信号','Location','SouthWest');
l1=legend('N=11时滤波后的加速度信号');
set(l1,'fontsize',10.5)
axis([0 100 0.5 3.5])
%%%%%%%%%%%%%%%%%
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JunJun~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值