Home > chronux_code > exploratory > functionestimation > 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. If data
 is in seconds, so must be sig and t. If data is in 
 samples, so must sig and t. The default is seconds.

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

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003