function jittered_data = jitter(data,d)

% JITTER -- adds noise to (discrete) data to prevent overlap in plots
%
%   jittered_data = jitter(data)
%   jittered_data = jitter(data,d)
%
%   DATA may be any numerical array. JITTERED_DATA is an array of
%   the same shape. The added noise is uniform b/n -D and +D.
%   D must be a positive scalar. When not supplied it defaults to 0.1.
%
%   Example:
%     x = round(rand(100,1)*3)+1 ; y = round(rand(100,1)*2)+1 ;
%     plot(x,jitter(y),'.') ;   figure;plot(x,y,'.') ;
%
% See also ADD_NOISE.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2000/05/01 19:20 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

if (nargin<2)
  d = 0.1 ;   % default
end

noise = (rand(size(data)) .* 2*d) - d ;
jittered_data = data + noise ;

%% Return JITTERED_DATA
%%%%% End of JITTER.M

