medfilt.m
来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 37 行
M
37 行
%FUNCTION: N-point median filter. y=medfilt(x,N)
function y=medfilt(x,N);
%% PURPOSE : select the medium point of each N consecutive sequence, N=3,5 or 7
%% input: x is the input and N is the order; if N is absent, default value is 3.
%% output: y is the median filter output.
if nargin<2
N=3;
end
x=x(:)';
xlens=length(x);
N2=round((N-1)/2);
if xlens>(N-1)
z=[zeros(1,N2) x zeros(1,N2)];
% interpolate the beginning portion
for i=1:N2
z(i)=2*x(i)-x(i+1);
end
% interpolate the ending portion
for i=1:N2
z(i+xlens+N2)=2*x(xlens+1-i)-x(xlens-i);
end
% find the median point
for i=(N2+1) : (xlens+N2)
a=z(i-N2:i+N2);
y(i-N2)=median(a);
end
else
y=x;
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?