Home > chronux_code > conditioning > 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 (if present t) 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      (bin centers)

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 (if present t) 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      (bin centers)
0021 if nargin < 3; error('Need all 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+dt;
0035    else;
0036        mintime=t(1);
0037        maxtime=t(end);
0038        t=mintime:dt:maxtime;
0039    end;
0040    for ch=1:C;
0041        eval(['dtmp=data(ch).' fnames{1} ';'])
0042        dN(:,ch)=histc(dtmp,t);
0043    end;
0044 else;
0045    dtmp=data;
0046    if nargin < 3;
0047       mintime=min(dtmp);
0048       maxtime=max(dtmp);
0049       t=mintime:dt:maxtime+dt;
0050    else;
0051       mintime=t(1);
0052       maxtime=t(end);
0053       t=mintime:dt:maxtime;
0054    end
0055    dN=histc(dtmp,t);
0056 end;

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