function [p,c]=bump1(x,y,ht)

% BUMP1       1D "bump hunting".
%
%             Example: data=snmd(1000,[0.75 0.25]',[1 1/3]',[0 3/2]');
% 		       h=hns(data,'knorm');
% 		       x = -5:0.1:5;
%		       y = kdest1d(x,data,'knorm',h);
%		       [p,c]=bump1(x,y,0.01);
%                      plot(x,y); hold on; plot(p(:,1),p(:,2),'x'); 
%
%	      [P,C] = BUMP1(X,Y) locates all "bumps" in the curve 
%             defined by (X,Y).  Bump locations are in P and bump 
%             count is in C.  HT (optional) can be used to ignore 
%             bumps below a threshold height, namely HT*max_height.
%             The default is HT=0.
%
%             C.C. Beardah (based on an original by S. Westwood) (1997)

if nargin == 2,
  ht = 0;
end

maxy=max(y);
d1=diff(y);
n=length(d1);
d2=d1(1:n-1);
d3=d1(2:n);
i=find((d2.*d3)<0)+1;
j=find(y(i)>(maxy*ht));
i=i(j);
xpoint=x(i);
t=0;

for k=1:length(i),
  ind=i(k);
  test = y((ind-1):(ind+1));
  if (test(1) < test(2)) & (test(3) < test(2)), 
    t = t + 1;
    p(t,1) = x(ind);
    p(t,2) = y(ind);
  end;
end;

c = size(p,1);