Home > chronux_1_15 > spikesort > utility > datatools > rasterize.m

rasterize

PURPOSE ^

RASTERIZE Converts a list of events into a binary time series.

SYNOPSIS ^

function raster = rasterize(events, Fs, T)

DESCRIPTION ^

RASTERIZE         Converts a list of events into a binary time series.
   RASTER = RASTERIZE(EVENTS) takes a vector EVENTS containing a list of
   indices and returns a binary vector RASTER with ones in locations
   given by EVENTS.  E.g., RASTERIZE([1 5]) => [1 0 0 0 1].
 
   RASTER = RASTERIZE(EVENTS,FS) specifies a sampling frequency FS;
   values in EVENTS are multiplied by FS and rounded to obtain indices
   into RASTER; e.g., RASTERIZE([0.1, 0.47], 10) => [1 0 0 0 1].
   RASTERIZE(EVENTS) is equivalent to RASTERIZE(EVENTS,1).

   RASTER = RASTERIZE(EVENTS,FS,T) specifies a total time T, so that
   RASTER is length FS*T (events outside of this interval are ignored).
   The default value is the maximum of EVENTS.

   The array returned for RASTER is a row vector of type LOGICAL.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function raster = rasterize(events, Fs, T)
0002 %RASTERIZE         Converts a list of events into a binary time series.
0003 %   RASTER = RASTERIZE(EVENTS) takes a vector EVENTS containing a list of
0004 %   indices and returns a binary vector RASTER with ones in locations
0005 %   given by EVENTS.  E.g., RASTERIZE([1 5]) => [1 0 0 0 1].
0006 %
0007 %   RASTER = RASTERIZE(EVENTS,FS) specifies a sampling frequency FS;
0008 %   values in EVENTS are multiplied by FS and rounded to obtain indices
0009 %   into RASTER; e.g., RASTERIZE([0.1, 0.47], 10) => [1 0 0 0 1].
0010 %   RASTERIZE(EVENTS) is equivalent to RASTERIZE(EVENTS,1).
0011 %
0012 %   RASTER = RASTERIZE(EVENTS,FS,T) specifies a total time T, so that
0013 %   RASTER is length FS*T (events outside of this interval are ignored).
0014 %   The default value is the maximum of EVENTS.
0015 %
0016 %   The array returned for RASTER is a row vector of type LOGICAL.
0017 
0018 %%%%% Deal with Fs & T ...
0019 if (nargin > 1),  events = round(events*Fs);  end
0020 
0021 if (nargin > 2),  len = Fs*prod(T);  
0022 else,             len = max(events);  
0023 end
0024 
0025 events(events>len) = [];
0026 
0027 %%%%% Make the logical raster
0028 raster = repmat(logical(0), 1, round(len));
0029 raster(round(events)) = 1;

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003