%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  一维均值滤波       2013年10月14日  zhengrui  %
%  vec_out: 输出向量, 一维行向量
%  vec_in： 输入向量，一维行向量
%  w：      滤波窗口半径
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function vec_out = meanfilter(vec_in, w)
dim_vec = length(vec_in);
%判断w是否超出整个点数一半，w表示滤波窗口半径
if w>floor((dim_vec-1)/2)
    disp 'w input error!It shoule be [1...floor((dim_vec-1)/2]！'
    return
end

vec_out = zeros(1, dim_vec);
for i=1:dim_vec
    if i>w & i<=dim_vec-w
    vec_out(i) = mean(vec_in((i-w):(i+w)));
    else
    vec_out(i) = vec_in(i);
    end
end
end

