function isihist( isis, binwidth )
% plot histogram of isis
% isis: vector of interspike intervals
% binwidth: optional width to be used for the isi bins

    if nargin < 2
        nperbin = 200;  % average number of data points per bin
        bins = length( isis )/nperbin;  % number of bins
        binwidth = max( isis )/bins;
        if binwidth < 5e-4   % half a millisecond
            binwidth = 5e-4;
        end
    end
    bins = 0.5*binwidth:binwidth:max(isis);
    % histogram:
    [ nelements, centers ] = hist( isis, bins );
    % normalization (integral = 1):
    nelements = nelements / sum( nelements ) / binwidth;
    % plot:
    bar( 1000.0*centers, nelements );
    xlabel( 'ISI [ms]' )
    ylabel( 'p(ISI) [1/s]')
    % annotation:
    misi = mean( isis );
    sdisi = std( isis );
    disi = sdisi^2.0/2.0/misi^3;
    text( 0.5, 0.6, sprintf( 'mean=%.1f ms', 1000.0*misi ), 'Units', 'normalized' )
    text( 0.5, 0.5, sprintf( 'std=%.1f ms', 1000.0*sdisi ), 'Units', 'normalized' )
    text( 0.5, 0.4, sprintf( 'CV=%.2f', sdisi/misi ), 'Units', 'normalized' )
    %text( 0.5, 0.3, sprintf( 'D=%.1f Hz', disi ), 'Units', 'normalized' )
end

