Home > chronux_0.5 > pointtimes > binspikes.m

binspikes

PURPOSE ^

bin spikes at a specified frequency sampling i.e. sampling rate 1/sampling

SYNOPSIS ^

function [dN,t]=binspikes(data,Fs,t)

DESCRIPTION ^

 bin spikes at a specified frequency sampling i.e. sampling rate 1/sampling
 eg: 1ms accuracy use sampling = 1000
 Usage: [dN,t]=binspikes(data,Fs,t)
 Inputs:
 data   (data as a structure array of spike times; or as a single column
        vector of spike times)
 Fs     (binning frequency)
 t      (the minimum and maximum times to be used to form the bins - [mint maxt]
            - optional. Default use the spike times themselves to
              determine the location of the bins. 
 Note: the times in data can be in any units. However, it is important
 that all units are chosen consistently. So, if spike times are in secs,
 Fs and t (if present) have to be in Hz and secs respectively. If spike
 times are in number of samples, Fs has to be 1, and t has to be in number
 of samples.
 Outputs:
 dN     (output binned spike counts as a matrix defined on bins starting with the
         earliest spike across all channels and ending with the latest spike)
 t      (lower limit of each bin)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dN,t]=binspikes(data,Fs,t)
0002 % bin spikes at a specified frequency sampling i.e. sampling rate 1/sampling
0003 % eg: 1ms accuracy use sampling = 1000
0004 % Usage: [dN,t]=binspikes(data,Fs,t)
0005 % Inputs:
0006 % data   (data as a structure array of spike times; or as a single column
0007 %        vector of spike times)
0008 % Fs     (binning frequency)
0009 % t      (the minimum and maximum times to be used to form the bins - [mint maxt]
0010 %            - optional. Default use the spike times themselves to
0011 %              determine the location of the bins.
0012 % Note: the times in data can be in any units. However, it is important
0013 % that all units are chosen consistently. So, if spike times are in secs,
0014 % Fs and t (if present) have to be in Hz and secs respectively. If spike
0015 % times are in number of samples, Fs has to be 1, and t has to be in number
0016 % of samples.
0017 % Outputs:
0018 % dN     (output binned spike counts as a matrix defined on bins starting with the
0019 %         earliest spike across all channels and ending with the latest spike)
0020 % t      (lower limit of each bin)
0021 if nargin < 2; error('Need at least two input arguments'); end;
0022 dt=1/Fs;
0023 if isstruct(data);
0024    C=length(data);
0025    fnames=fieldnames(data);
0026    if nargin <3 || isempty(t);
0027        for ch=1:C
0028          eval(['dtmp=data(ch).' fnames{1} ';'])
0029          mintime(ch)=min(dtmp);
0030          maxtime(ch)=max(dtmp);
0031        end
0032        mintime=min(mintime);
0033        maxtime=max(maxtime);
0034        t=mintime:dt:maxtime;
0035    else
0036        for ch=1:C
0037          eval(['dtmp=data(ch).' fnames{1} ';'])
0038 %          mintimech(ch)=min(dtmp);
0039          maxtimech(ch)=max(dtmp);
0040        end
0041        mintime=t(1);
0042        maxtime=t(end);
0043 %        mintimech=min(mintimech);
0044        maxtimech=max(maxtimech);
0045        t=mintime:dt:maxtime;
0046        if maxtimech > max(t); t=[t maxtimech+dt]; end;
0047    end
0048    for ch=1:C;
0049        eval(['dtmp=data(ch).' fnames{1} ';'])
0050        x=histc(dtmp,t);
0051        dN(:,ch)=x(:);
0052    end
0053 else
0054    dtmp=data;
0055    if nargin < 3;
0056       mintime=min(dtmp);
0057       maxtime=max(dtmp);
0058    else
0059       mintime=t(1);
0060       maxtime=t(end);
0061    end
0062    t=mintime:dt:maxtime;
0063    if max(dtmp)>max(t); t=[t maxtime+dt]; end;
0064    x=histc(dtmp,t);
0065    dN=x(:);
0066 end

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