


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
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)

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 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 mintime=zeros(1,C); 0028 maxtime=zeros(1,C); 0029 for ch=1:C 0030 eval(['dtmp=data(ch).' fnames{1} ';']) 0031 mintime(ch)=min(dtmp); 0032 maxtime(ch)=max(dtmp); 0033 end 0034 mintime=min(mintime); 0035 maxtime=max(maxtime); 0036 else 0037 % maxtimech=zeros(1,C); 0038 % for ch=1:C 0039 % eval(['dtmp=data(ch).' fnames{1} ';']) 0040 % % mintimech(ch)=min(dtmp); 0041 % maxtimech(ch)=max(dtmp); 0042 % end 0043 mintime=t(1); 0044 maxtime=t(end); 0045 % mintimech=min(mintimech); 0046 % maxtimech=max(maxtimech); 0047 % if maxtimech > max(t); t=[t maxtimech+dt]; end; 0048 end 0049 t=linspace(mintime,maxtime,1+(maxtime-mintime)/dt); 0050 for ch=1:C; 0051 eval(['dtmp=data(ch).' fnames{1} ';']) 0052 x=histc(dtmp,t); 0053 dN(:,ch)=x(:); 0054 end 0055 else 0056 dtmp=data; 0057 if nargin < 3; 0058 mintime=min(dtmp); 0059 maxtime=max(dtmp); 0060 else 0061 mintime=t(1); 0062 maxtime=t(end); 0063 end 0064 t=linspace(mintime,maxtime,1+(maxtime-mintime)/dt); 0065 if max(dtmp)>max(t); t=[t maxtime+dt]; end; 0066 x=histc(dtmp,t); 0067 dN=x(:); 0068 end