annotate aim-mat/tools/spikecrosscorrelate.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % support file for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 4 % (c) 2011, University of Southampton
bleeck@3 5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 6 % download of current version is on the soundsoftware site:
bleeck@3 7 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 8 % documentation and everything is on http://www.acousticscale.org
bleeck@3 9
tomwalters@0 10
tomwalters@0 11 function cor=spikecrosscorrelate(data1,data2,sr,window_start,window_stop)
tomwalters@0 12 % calculate the autocorrelation (all interval histogram)
tomwalters@0 13 % for the data in data with the samplerate in sr, but only the time
tomwalters@0 14 % window given my window
tomwalters@0 15
tomwalters@0 16 nr_dat1=length(data1);
tomwalters@0 17 nr_dat2=length(data2);
tomwalters@0 18
tomwalters@0 19 if nr_dat1<2 || nr_dat2<2
tomwalters@0 20 cor=[];
tomwalters@0 21 return
tomwalters@0 22 end
tomwalters@0 23
tomwalters@0 24 cor=zeros(1,round((window_stop-window_start)*sr));
tomwalters@0 25 zeroindx=window_stop*sr;
tomwalters@0 26 for ii=1:nr_dat1
tomwalters@0 27 dat1=data1(ii);
tomwalters@0 28 for jj=1:nr_dat2
tomwalters@0 29 dat2=data2(jj);
tomwalters@0 30 len=(dat2-dat1)*sr;
tomwalters@0 31 indx=round(len);
tomwalters@0 32 if indx < window_stop*sr && indx > window_start*sr
tomwalters@0 33 cor(indx+zeroindx)=cor(indx+zeroindx)+1;
tomwalters@0 34 end
tomwalters@0 35 end
tomwalters@0 36 end