function output=slidingmed(input,window)
    output=NaN(size(input));
    for n=window+1:length(input)-window
        win=input(n-window:n+window);
        if sum(~isnan(win))>window/20
            output(n)=median(win(~isnan(win)));
        end
    end
end