滑动平均滤波

滑动平均滤波,窗口长度为6;
滑动平均滤波_第1张图片

matlab窗口长度6进行滤波,输入为512点,输出为507点,最后几个点未进行处理;
滑动平均后,波形中的小波动消失;
滑动平均滤波_第2张图片

用于平滑噪声:
matlab :code

function T1 = huadong( d_temp )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
%author:[email protected]
T=d_temp';
% figure(1)
% plot(T,'-*')
% title('原始数据')
% hold on;

%滑动平滑滤波
L = length(T);
N=6;  % 窗口
k = 0;
m =0 ;
for i = 1:L
    m = m+1;
    if i+N-1 > L
        break
    else
        for j = i:N+i-1
            k = k+1;
            W(k) = T(j) ;
        end
        T1(m) = mean(W);
        k = 0;
    end
end
% plot(T1,'r-o');
%  f_kb=kaibilvbo(d_temp,[1 1 1 1 1 1 ],'1');
%  plot(f_kb,'y-o');
% grid
% legend('原始数据','滑动滤波之后')
end

C语言代码:

void huadong (U16 *InputSig,U16 SigLen,U16 WindowSize,float *OutputSig)
{
    U16 i,j;
    U16 k=-1,m=-1;
    U16 w[6]={0};
    U16 N,L;
    N=WindowSize;
    L=SigLen;
    for(i=0;i
        m+=1;
        if (i+N-1>=L)
          break;
        else{
            for(j=i;j<=N+i-1;j++){
             k+=1;
             w[k]=InputSig[j];
            }
            //求w的均值;
            OutputSig[m] =mean_array_LR( w,0,5 );
            k=-1;
        }
    }
}

PS:同上未处理最后几个点;

function T1 = huadong( d_temp )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here

T=d_temp’;
% figure(1)
% plot(T,’-*’)
% title(‘原始数据’)
% hold on;

%滑动平滑滤波
L = length(T);
% N=6; % 窗口大下
N=20; % 窗口大下
k = 0;
m =0 ;
T1=zeros(1,L);
for i = 1:L
m = m+1;
if i+N-1 > L
break
else
for j = i:N+i-1
k = k+1;
W(k) = T(j) ;
end
T1(m) = mean(W);
k = 0;
end
end

%add last end point:

for i=L-N+2:L
T1(m)=T(i);
m=m+1;
end

% plot(T1,’r-o’);
% f_kb=kaibilvbo(d_temp,[1 1 1 1 1 1 ],’1’);
% plot(f_kb,’y-o’);
% grid
% legend(‘原始数据’,’滑动滤波之后’)

end

你可能感兴趣的:(C,matlab)