function []=pltevent(trace,timev,fs,ebank,framehz,timestring)
% pltevent plots an event  
%   []=pltevent(trace,timev,fs,ebank,framehz,timestring) 
%   Inputs:
%       trace
%       timev in sec from beginning of file for center of event
%       fs sampling frequency
%       filterbank
%       framehz of filterbank
%       tstring, title string

nfft=1024;
nfwindows=16; % window length in nfft
nwindow=256;
noverlap=200;
dn = noverlap/2;
timei = int32(timev*fs);
ilow = -nfft*nfwindows/4;
ihigh = ilow + nfft*nfwindows;
if (timei + ilow - dn < 0);
    ilow = 1+dn;
    ihigh = ilow + nfft*nfwindows;
end
if (timei > length(trace) - ihigh - dn)
    dx = length(trace) - timei;
    ihigh = dx -dn;
    ilow = ihigh - nfft*nfwindows;
end



    tvec = ilow:ihigh;
    ivec = (int32(ilow):int32(ihigh)) + timei;
    ivec2 = (int32(ilow)-dn:int32(ihigh+dn)) + timei;
    tvec=tvec/fs;
    [S,F,T,P]=spectrogram(trace(ivec2),nwindow,noverlap,nfft,fs,'yaxis');
    %xlim([min(tvec), max(tvec)]);
    subplot(3,1,1);
    
    surf(T-(max(tvec)+min(tvec))/2,F,10*log10(abs(P)),'EdgeColor','none');
    axis xy; axis tight; colormap(jet); view(0,90);
    xlabel('Time (s)');
    ylabel('Frequency (Hz)');
    %T(1)
    title(timestring);
    
    subplot(3,1,2);
    ns = length(tvec);
    plot(tvec,trace(ivec));
    mm = max(abs(trace(ivec)));
    ylim([-mm,mm]);
    xlim([min(tvec),max(tvec)]);
    ylabel('trace');
    xlabel('Time (s)');
    

    if (length(ebank) > 1)
      subplot(3,1,3);
      e_timei = int32(timev*framehz);
      e_tvec = int32(ilow*framehz/fs):int32(ihigh*framehz/fs);
      e_ivec = e_tvec + e_timei;
      e_tvec = e_tvec/framehz;

      color = ebank(e_ivec,1)-ebank(e_ivec,2);
      plot(e_tvec,color);
      xlabel('Time (s)');
      ylabel('color12 (db)');
      xlim([min(tvec),max(tvec)]);
      ylim([min(color),max(color)]);
    end

% you can save the figure with 
% print -depsc filename