function motif_detector(et,tol)
%description: input arguments are a vector of event times and a tolerance for matches;  finds the interevent intervals; those that are sufficiently similar are considered matches
%

ieis=diff(et)

ieis=repmat(ieis,length(ieis),1)

ieist=ieis'

a=ieis-ieist

%account for the diagonal
a(1



% 
% % temporal_tolerance=15
% % %amplitude_tolerance=;
% % 
% % spont_peaks=zeros(1,10000);
% % b=rand(1,10000);
% % spont_peaks(find(b>.995))=1;
% % indds=find(spont_peaks);
% % intervulls=diff(indds)
% % 
% % global zed
% % zed={}
% % 
% % for k=1:length(spont_peaks)-1   %don't consider anything subsequent to the last peak
% %     zed{k}=[];
% %     for m=1:length(spont_peaks)-k   
% %         if abs(g(k)-g(k+m))<temporal_tolerance,zed{k}=[zed{k};m+k];,end
% %     end
% % end
% % 
% % zed
% 
% %a different approach -- feb 6 2005 ---------------------------------------
% 
% % 1) open, remove 60 Hz
% tic
% close all
% filename_to_read='patch20050113T180249.hdf'
% trial_to_read=1;
% event_detection_threshold=-10
% number_clusters_permitted=50%ceil(number_events_detected/20);
% global file_data
% file_data=generic_hdf_reader(filename_to_read,trial_to_read);
% %figure(1)
% %plot(file_data)
% f_d=file_data(size(file_data,1)-(250000-1):end,:);
% aa=size(f_d)
% bb=f_d(:,1);
% assignin('base','a',bb)
% %---------------
% % Y=bb;
% % N = length(Y);
% % Y(1) = [];
% % power = abs(Y(1:N/2)).^2;
% % nyquist = 1/2;
% % freq = (1:N/2)/(N/2)*nyquist;
% % figure(10)
% % plot(freq,power), grid on
% % xlabel('cycles/sample?')
% % title('Periodogram')
% % period = 1./freq;
% % figure(11)
% % plot(period,power), grid on
% % ylabel('Power')
% % xlabel('Period(Samples?/Cycle)')
% % [mp,index] = max(power);
% % period(index)
% % %------------
% % g=fft(bb);
% % figure(5),plot(bb)
% % figure(6),plot(g)
% % Pgg= g.* conj(g);
% % % %Pgg()=0;
% % figure(7), plot(Pgg)
% % 
% % % 2) smooth w/ moving average
% % % 3) find peaks
% % % 4) take amplitude and time since previous event as the two characteristics defining each peak
% % [amplitudes,timessinceprevious]=event_detector(f_d(:,2),event_detection_threshold);
% % amplitudes=abs(amplitudes(2:end));
% % uno=size(amplitudes)
% % %amplitudes=log(amplitudes);
% % dos=size(amplitudes)
% % % imaginaries=zeros(1,length(amplitudes));
% % % imaginaries(~isreal(amplitudes))=1;
% % % amplitudes(isreal(amplitudes))
% % amplitudes=amplitudes/min(amplitudes)
% % amplitudes=log(amplitudes)
% % for remover=1:50
% %     [val,ind]=min(amplitudes);
% %     amplitudes(ind)=[];
% %     timessinceprevious(ind)=[];
% % end
% % tres=size(amplitudes)
% % %timessinceprevious(find(imaginaries))=[];
% % aa=size(amplitudes)
% % amplitudes=amplitudes*(max(timessinceprevious)/max(amplitudes))
% % bb=size(timessinceprevious)
% % figure(2)
% % plot(timessinceprevious,amplitudes,'ro')
% % 
% % % 5) cluster the points, check clustering
% % clustersfound=clusterdata([amplitudes,timessinceprevious],number_clusters_permitted)
% % % 
% % % %checking the clusters
% % figure(3)
% % axis([min(timessinceprevious) max(timessinceprevious) min(amplitudes) max(amplitudes) ])
% % for i=1:length(clustersfound)
% %     text(timessinceprevious(i),amplitudes(i),num2str(clustersfound(i)))
% %     hold on
% % end
% % 
% % % 6) find sequences in the successive cluster identities
% % %suffix tree?
% % match_matrix=[];
% % for j=1:length(clustersfound)
% %     for k =1:length(clustersfound)
% %         if clustersfound(j)==clustersfound(k)
% %             match_matrix(j,k)=1;
% %         end
% %     end
% % end
% % colormap(gray)
% % figure(15)
% % imagesc(match_matrix)
% % toc