function oo=filtmedian(dd,rm)
   
ii = find(~isnan(dd));

oo = repmat(nan,size(dd));

[x,y] = meshgrid(1:size(dd,2),1:size(dd,1));

for kk=1:prod(size(dd))
   r = sqrt((x-x(kk)).^2 + (y-y(kk)).^2);
   jj = ii(find(r(ii)<rm));
   if length(jj)>1
      oo(kk) = median(dd(jj));
   end
end
