Algorithm Alley
by Wesley Bylsma


Listing One
% [y]=medianL(x,L) calculates the median over N=2L+1 of x
% INPUT:
%  x - input signal
%  L - interval (N=2L+1)
%
% OUTPUT:
%  y - median of interval N
%
function [y]=medianL(x,L);

% get the signal length
l=length(x);

%extend the end points so that filter window is full
x=[x(1)*ones(1,L),x',x(l)*ones(1,L)]';

%at each data point, sort values in window and pick middle one
for i=1:l,
t=sort(x(L+i-L:L+i+L));
% k <=L
y(i)=t(L+1);
end
y=y';




1


