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!'); return; 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...
0037 
0038 NT = length(data(1,:));
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   end 
0047 end
0048 
0049 
0050 % calculate intervals...
0051 
0052 I = zeros(NT,max(NI));
0053 IT = [];
0054 for n=1:NT
0055   I(n,1:NI(n)) = diff(data(1:(NI(n)+1,n)));
0056   IT = [IT I(n,1:NI(n))];
0057 end
0058 
0059 Mx = max(IT);
0060 if Nbins == -1
0061   Nbins = floor(sum(NI)/30);
0062   Med = median(IT);
0063   Nbins = max(floor(Nbins*Mx/Med),10);
0064 end
0065 
0066 B = linspace(0,Mx,Nbins);
0067 
0068 N = zeros(NT,Nbins);
0069 for n=1:NT
0070   N(n,:) = hist(I(n,1:NI(n)),B);
0071 end
0072 
0073 % answer...
0074 
0075 if NT > 1;Ns = sum(N)/NT;else;Ns = N;end
0076 if ~strcmp(plt,'n')
0077   bar(B,NT*Ns);
0078 end
0079 
0080 % Jackknife iver trials to estimate std...
0081 
0082 if NT > 4 & err == 1
0083   MN = 0;
0084   SN = 0;
0085   for n=1:NT
0086     JK = (NT*Ns - N(n,:))/(NT-1);
0087     MN = MN + JK;
0088     SN = SN + JK.^2;   
0089   end  
0090   MN = MN/NT;
0091   SN = SN/NT;
0092   E = sqrt((NT-1)*(SN - MN.^2));
0093   if ~strcmp(plt,'n')
0094     hold on
0095     errorbar(B,NT*Ns,NT*2*E,'r-')
0096     hold off
0097   end
0098 end
0099 N = NT*Ns;
0100 
0101 
0102 
0103 
0104 
0105 
0106 
0107

Generated on Tue 24-Aug-2004 15:55:33 by m2html © 2003