function [e0,e_drop,c0,c_drop] = fitcolor(starttime,dt_efold,dt_color,framehz,ebank,titles)
% [e0,e_drop,c0,c_drop] = fitcolor(starttime,dt_efold,dt_color, framehz,ebank,titles)
% Inputs:
%    starttime from beginning for event in sec
%    dt_efold dtime in seconds for efold fit in lowest filter
%    dt_color dtime in seconds for color gradient fit
%    framehz   sampling rate of filterbank
%    ebank   the  filter bank
%    titles a string for labelling a plot
%  Outputs, zeropoints in db and slopes in time/db 

e_start = fix(starttime*framehz) + 2;
e_end1 = e_start + fix(dt_efold*framehz);
e_end2 = e_start + fix(dt_color*framehz);
e1 = squeeze(ebank(e_start:e_end1,1));
ec = e1 - squeeze(ebank(e_start:e_end1,2));


e_tvec = 0:(e_end1-e_start);
e_tvec = e_tvec/framehz;
e_tvec = reshape(e_tvec,length(e_tvec),1);  % column to vec
p=polyfit(e_tvec,e1,1);
f = polyval(p,e_tvec);
% p is polynomial and first value is slope
d2 = e_end2-e_start;
pc = polyfit(e_tvec(1:d2),ec(1:d2),1);
fc = polyval(pc,e_tvec);

subplot(3,1,1);
plot(e_tvec,e1,'o',e_tvec,f,'-');
title(titles);
subplot(3,1,2);
plot(e_tvec,ec,'o',e_tvec,fc,'-');
e_drop = 1.0/p(1);   % expected negative these are timescales
c_drop = 1.0/pc(1);  % red expected positive again a timescale
% units of output is time/dB  if I mult by 3 I get 3dB drop times 
% (factor of 2 drop times)
e0 = p(2); % zerpoints of fits in db
c0 = pc(2);
