function [bc,fhat,bins]=norm_ref_rule_hist(x) % NORM_REF_RULE_HIST - returns the histogram based PDF for the input data % using the normal reference rule for selcting the bin widths % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % specify the bin width using the normal reference rule for histograms: % s = std(x); n = length(x); h = 3.5*s*(length(x)).^(-1/3); % get the limits, bins, bin centers etc: x_lim_left = min(x)-1; x_lim_rght = max(x)+1; t0 = x_lim_left; tm = x_lim_rght; rng = tm-t0; nbin = ceil(rng/h); bins = t0:h:(nbin*h+t0); % <- the initial bin edges ... bc = bins(1:end-1)+0.5*h; % <- the bin centers ... x(find(xx_lim_rght))=x_lim_rght; vk=histc(x,bins); vk(end)=[]; % normalize: fhat = vk/(n*h);