function burstiness(fid_prefix,hpr,starthour,endhour)

fpath = ['C:\Users\USER\Documents\mingfaifong\' fid_prefix '\'];
spath = [fpath 'figures\'];
load([fpath fid_prefix '_nowaveform.SS'],'-mat');

if nargin<2
    hpr = 24;
end
if nargin<3
    starthour = 0;
end
if nargin<4
    endhour = ceil(max(SS.time)/3600);
end

n_subplots = ceil((endhour-starthour)/hpr);
% binsize_options_secs = [1,2,5,10,30,1*60,2*60,5*60,10*60,30*60,1*3600];
% binsize_options = [1,2,5,10,30,1,2,5,10,30,1];
% binsize_units = {'sec','sec','sec','sec','sec','min','min','min','min','min','hr'};

[evt_times evt_text] = get_events(fid_prefix);

SS.ASDR(1,0,0); %from 1 second bins
asdr_times = SS.asdr(:,1);
asdr_1sec = SS.asdr(:,2);

%binsize = 60; %seconds
binsize = 3600; %seconds

for j = 1:round(max(asdr_times)/binsize)
    ind = asdr_times > (j-1)*binsize & asdr_times <=j*binsize;
    asdr_sort = sort(asdr_1sec(ind));
    f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
    BI(j) = (f15-0.15)/0.85;
end

close all;
figure('units','normalized','outerposition',[0 0 1 1])    
h_tight = tight_subplot(n_subplots,1,[.08 .04],[.15 .08],[.1 .01]);

for i_subplot = 1:n_subplots
    axes(h_tight(i_subplot));
    save([fpath fid_prefix '_BI.mat']);
    plot(asdr_times,asdr_1sec/max(asdr_1sec),'Color',[.8 .8 .8],'LineWidth',0.25);
    hold on;
    plot(binsize/2:binsize:(j-0.5)*binsize,BI,'Color',[0 0 0],'LineWidth',2.5);
    fid_suffix = 'BI';
    %fid_suffix = 'BI_1min';
    
    axis([((i_subplot-1)*hpr+starthour)*3600 ((i_subplot*hpr)+starthour)*3600 0 1]);
    set(gca,'FontSize',11,'TickDir','out','TickLength',[0.002 0.025],...
        'XTick',[((i_subplot-1)*hpr+starthour)*3600:3600:((i_subplot*hpr)+starthour)*3600],...
        'XTickLabel',[(i_subplot-1)*hpr+starthour:1:(i_subplot*hpr)+starthour],...
        'Ytick',[0:0.2:1]);
    set(gcf,'Clipping','off')
    grid on;
    
    evt_lim = xlim;
    evt_ind = find(evt_times>=evt_lim(1) & evt_times<evt_lim(2));
    if evt_ind
        for m = evt_ind(1):evt_ind(end)
            plot([evt_times(m) evt_times(m)],[0 1],'--r');
            text(evt_times(m)+(hpr*.005)*3600,.9,evt_text{m},'Color','r','FontSize',8);
        end
    end

    switch i_subplot
        case 1
            xlabel(''); ylabel('');
            text(((hpr-7.75)+starthour)*3600,1.2,'grey line is normalized ASDR for 1 sec bins','Color',[0.5 0.5 0.5],'FontSize',8);
        case round(n_subplots/2)
             xlabel(''); ylabel('Burstiness Index','FontSize',14);
        case n_subplots
            xlabel([10,'Time (hours)'],'FontSize',14);
            ylabel('');
        otherwise
            xlabel(''); ylabel('');
    end


%    keyboard
    print('-depsc',[spath fid_prefix '_' fid_suffix '.eps']);
    print('-dpng',[spath fid_prefix '_' fid_suffix '.png']);
    saveas(gcf,[spath fid_prefix '_' fid_suffix '.fig'],'fig');
 end