function bursts = findbursts(asdr,asdrbins,windsize,FRthresh,hardthresh)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

if nargin < 5 || isempty(hardthresh)
    hardthresh = 0;
end
if nargin < 4 || isempty(FRthresh)
    FRthresh = 0;
end
if nargin < 3 || isempty(windsize)
    windsize = 100; % samples
end
if nargin < 2
    error('Must provide ASDR data and ASDR bin size')
end


windsamp = ceil(windsize/2); % number of samples in window


[pks locs] = findpeaks(asdr, 'MINPEAKHEIGHT',hardthresh);
bursts = [];

j = 1;
for i = locs
    if i - windsamp >= 1 && i+windsamp <= length(asdr)
        locFR = mean(asdr(i-windsamp:i+windsamp));
        if pks(j) > FRthresh*locFR
            bursts = [bursts; [asdrbins(i) asdr(i)]];
        end
    elseif i - windsamp < 1
        locFR = mean(asdr(1:i+windsamp));
        if pks(j) > FRthresh*locFR
            bursts = [bursts; [asdrbins(i) asdr(i)]];
        end
    elseif i+windsamp > length(asdr)
        locFR = mean(asdr(i-windsamp:end));
        if pks(j) > FRthresh*locFR
            bursts = [bursts; [asdrbins(i) asdr(i)]];
        end
    end
    j = j+1;
end


end

