Home > chronux_0.5 > pointtimes > isi.m

isi

PURPOSE ^

Calculate the inter-spike-interval histogram

SYNOPSIS ^

function[N,B,E] = isi(data,T,err,Nbins,plt)

DESCRIPTION ^

 Calculate the inter-spike-interval histogram                 
    Usage: [N,B,E] = isi(data,T,err,Nbins,plt)
    
 Input:                                                       
 Note that all times have to be consistent. 

 data   - structure array of spike times  (required)             
 T      - time interval of interest (default all)             
 err    - 0 for no error bars, 1 for jackknife errors
 
 Nbins  - number of bins in the isi                           
                                                              
 Output:                                                      
                                                              
 N      - count in bins                                       
 B      - bin centres                                            
 E      - errorbar (this is 2 sig deviation                   
          calculated using a jackknife over trials)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function[N,B,E] = isi(data,T,err,Nbins,plt)
0002 % Calculate the inter-spike-interval histogram
0003 %    Usage: [N,B,E] = isi(data,T,err,Nbins,plt)
0004 %
0005 % Input:
0006 % Note that all times have to be consistent.
0007 %
0008 % data   - structure array of spike times  (required)
0009 % T      - time interval of interest (default all)
0010 % err    - 0 for no error bars, 1 for jackknife errors
0011 %
0012 % Nbins  - number of bins in the isi
0013 %
0014 % Output:
0015 %
0016 % N      - count in bins
0017 % B      - bin centres
0018 % E      - errorbar (this is 2 sig deviation
0019 %          calculated using a jackknife over trials)
0020 
0021 
0022 if nargin < 1; error('I need data!'); end
0023 data=padNaN(data); % create a zero padded data matrix from input structural array
0024 data=data'; % transposes data to get it in a form compatible with Murray's routine
0025 if nargin < 2; T = [min(data(:,1)) max(max(data))]; end
0026 if nargin < 3; err = 0;end
0027 if nargin < 4; Nbins = -1; end
0028 if nargin < 5; plt = 'r'; end
0029 
0030 if isempty(T); T = [min(min(data)) max(max(data))]; end
0031 if isempty(err); err = 0;end
0032 if isempty(Nbins); Nbins = -1; end
0033 if isempty(plt); plt = 'r'; end
0034 
0035 %  get the number of intervals in each trial and the indices of spike times
0036 %  that are kept
0037 
0038 NT = length(data(1,:)); % number of trials
0039 for n=1:NT
0040   indx = find(data(:,n) >=  T(1) & data(:,n) <=  T(2) ... 
0041                                  & ~isnan(data(:,n)));
0042   if isempty(indx)
0043     NI(n) = 0;
0044   else
0045     NI(n) = length(indx)-1;
0046     index(n).keep=indx;
0047   end 
0048 end
0049 
0050 
0051 % calculate intervals...
0052 
0053 I = zeros(NT,max(NI));
0054 IT = [];
0055 for n=1:NT
0056   I(n,1:NI(n)) = diff(data(index(n).keep,n));
0057   IT = [IT I(n,1:NI(n))];
0058 end
0059 
0060 Mx = max(IT);
0061 if Nbins == -1
0062   Nbins = floor(sum(NI)/30);
0063   Med = median(IT);
0064   Nbins = max(floor(Nbins*Mx/Med),10);
0065 end
0066 
0067 B = linspace(0,Mx,Nbins);
0068 
0069 N = zeros(NT,Nbins);
0070 for n=1:NT
0071   N(n,:) = hist(I(n,1:NI(n)),B);
0072 end
0073 
0074 % answer...
0075 
0076 if NT > 1;Ns = sum(N)/NT;else Ns = N;end
0077 if ~strcmp(plt,'n')
0078   bar(B,NT*Ns);
0079 end
0080 
0081 % Jackknife iver trials to estimate std...
0082 
0083 if NT > 4 && err == 1
0084   MN = 0;
0085   SN = 0;
0086   for n=1:NT
0087     JK = (NT*Ns - N(n,:))/(NT-1);
0088     MN = MN + JK;
0089     SN = SN + JK.^2;   
0090   end  
0091   MN = MN/NT;
0092   SN = SN/NT;
0093   E = sqrt((NT-1)*(SN - MN.^2));
0094   if ~strcmp(plt,'n')
0095     hold on
0096     errorbar(B,NT*Ns,NT*2*E,'r-')
0097     hold off
0098   end
0099 end
0100 N = NT*Ns;
0101 
0102 
0103 
0104 
0105 
0106 
0107 
0108

Generated on Tue 16-Aug-2005 21:33:45 by m2html © 2003