%%function [xthresh,n,x]=d2chist(data,x,sigma);
%%By Joakim Lindblad 2000-01-25
%% one sigma per data point allowed

function [xthresh,n,x]=d2chist(data,x,sigma);

data=data(:); %make vector

if length(sigma)==1 %%only one sigma, conv is much faster
  
  n = hist(data,x);
  xx= mirror(x);
  g = d2gauss(xx,x(1),sigma);
  n = conv2(n,g,'same');
  
else
  
  sigma=sigma(:);
  n = zeros(size(x));
  
  for i=1:length(data)
    n=n+d2gauss(x,data(i),sigma(i));
  end

end

[y,xmax]=max(n); %max
xthresh=x(xmax)




