Object Type:	autocorr

Description:	Computes the auto-correlation of a spike train
		A histogram containing the count of
		events for each bin is constructed.

Author:		D. Jaeger, Caltech (9/92)
		revised for Genesis v2.2 11/99

------------------------------------------------------------------------------

ELEMENT PARAMETERS

DataStructure:	doac_type  [in genesis/src/device/spike_struct.h]

Size:		100 bytes

Fields:		num_bins	(int) number of bins in histogram
		binwidth	(float) binwidth in sec
		reset_mode	(int) 0 or 1	
		threshold	(float) input amplitude triggering spike event
		*acarray	(int)	histogram array containing data
		nospks		(int) number of spikes from source
		*sptimes	(float) array of spike times from source
		curridx		(int) internal indexing
		calcidx		(int) internal indexing
		maxspikes	(int) internal boundary condition
		wintime		(float) internal boundary condition
		dont		(int) internal condition
		allocated	(int) internal condition


------------------------------------------------------------------------------

SIMULATION PARAMETERS

Function:	Doac  [in genesis/src/device/acxc.c]
Classes:	datanal

Actions:	PROCESS		update *sptimes, *acarray, nospks
		RESET		if reset_mode = 0, empties *sptimes but not
					*acarray
				if reset_mode = 1, empties *sptimes and
					recreates *acarray

Messages:	SPIKE : signal amplitude from source 

------------------------------------------------------------------------------

Notes:
		User must setfield num_bins and binwidth (in sec) so
	that a data array is created on RESET. The input is assumed to
	cross the amplitude given in the threshold field only for one 
	timestep to generate a spike. Vm is not to be used as an input field.
	Valid inputs may be derived from random, neutral or spike objects.
		An internal spike time buffer is set up for a maximal
	spike rate of 1000 events / second. A greater density of spikes
	will lead missed events in the histogram. 
		The auto-corrlation histogram is updated with each timestep.
	However, the first results will only be available after the
	simulation time has reached the value of num_bins * binwidth.
	This is due to the fact that any spike needs to be correlated
	with other spikes across a time window of this duration.
		The data are stored in *acarray and can be accessed with
	a getfield command (see example). 

Example:	

create autocorr /ac
setfield ^ binwidth 0.002 num_bins 200 threshold 0.5

/* this example uses random object for input */
create random /input
setfield ^ min_amp 1 max_amp 1 rate {in1_rate} reset 1 reset_value 0
addmsg /input1 /ac SPIKE state

/* To display data on a graph, use this function after creating the graph */
function plotac(source, dest, pname, color)
    str source,dest,color
    int maxbin
 
    int i,barval
 
    maxbin = {getfield {source}, num_bins}
    setfield {dest} xmax {maxbin}
    call {dest} RESET
 
    for(i=0; i < maxbin; i = i + 1)
       	barval = {getfield {source}, acarray[{i}]}
       	addpts {dest} -plotname {pname} -color {color} {i} 0
        addpts {dest} -plotname {pname} -color {color} {i} {barval}
       	addpts {dest} -plotname {pname} -color {color} {{i}+1} 0
    end
end
		    
See also:  crosscorr, interspike, peristim, Scripts/examples/spike/spikes.g
