function b=wild(x,n,m)
%WILD: finds and plots wild points
% b=WILD(x,n,m) finds and plots wild points in x identified
% as exceeding m times the std. dev. of x minus the n-point
% running mean. Series may contain NaN's.
%
% INPUT:   x - input vector
%          n - number of points in running mean
%          m - multiplier for std. dev. of n-point mean
%             
% OUTPUT:  b - index array of bad points

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 11/14/99;10/6/00 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x=x(:);
xx=x;
nn=[1:length(x)];
xfilt=x-boxfilt(x,n);
cutoff=m*stdnan(xfilt);
b=find(abs(xfilt)>cutoff);
%disp(['std = ',num2str(cutoff./m),'   m = ',int2str(m)])
%disp(['number bad points = ',int2str(length(b))])

% clf
% plot(nn(b),xfilt(b),'r+',nn,xfilt)
