sta - Spike-triggered average

Functions to calculate spike-triggered average and spike-field coherence of analog signals.

elephant.sta.spike_field_coherence(signal, spiketrain, **kwargs)[source]

Calculates the spike-field coherence between a analog signal(s) and a (binned) spike train.

The current implementation makes use of scipy.signal.coherence(). Additional kwargs will will be directly forwarded to scipy.signal.coherence(), except for the axis parameter and the sampling frequency, which will be extracted from the input signals.

The spike_field_coherence function receives an analog signal array and either a binned spike train or a spike train containing the original spike times. In case of original spike times the spike train is binned according to the sampling rate of the analog signal array.

The AnalogSignal object can contain one or multiple signal traces. In case of multiple signal traces, the spike field coherence is calculated individually for each signal trace and the spike train.

Parameters:
signal : neo AnalogSignal object

‘signal’ contains n analog signals.

spiketrain : SpikeTrain or BinnedSpikeTrain

Single spike train to perform the analysis on. The binsize of the binned spike train must match the sampling_rate of signal.

Returns:
coherence : complex Quantity array

contains the coherence values calculated for each analog signal trace in combination with the spike train. The first dimension corresponds to the frequency, the second to the number of the signal trace.

frequencies : Quantity array

contains the frequency values corresponding to the first dimension of the ‘coherence’ array

elephant.sta.spike_triggered_average(signal, spiketrains, window)[source]

Calculates the spike-triggered averages of analog signals in a time window relative to the spike times of a corresponding spiketrain for multiple signals each. The function receives n analog signals and either one or n spiketrains. In case it is one spiketrain this one is muliplied n-fold and used for each of the n analog signals.

Parameters:
signal : neo AnalogSignal object

‘signal’ contains n analog signals.

spiketrains : one SpikeTrain or one numpy ndarray or a list of n of either of these.

‘spiketrains’ contains the times of the spikes in the spiketrains.

window : tuple of 2 Quantity objects with dimensions of time.

‘window’ is the start time and the stop time, relative to a spike, of the time interval for signal averaging. If the window size is not a multiple of the sampling interval of the signal the window will be extended to the next multiple.

Returns:
result_sta : neo AnalogSignal object

‘result_sta’ contains the spike-triggered averages of each of the analog signals with respect to the spikes in the corresponding spiketrains. The length of ‘result_sta’ is calculated as the number of bins from the given start and stop time of the averaging interval and the sampling rate of the analog signal. If for an analog signal no spike was either given or all given spikes had to be ignored because of a too large averaging interval, the corresponding returned analog signal has all entries as nan. The number of used spikes and unused spikes for each analog signal are returned as annotations to the returned AnalogSignal object.

Examples

>>> signal = neo.AnalogSignal(np.array([signal1, signal2]).T, units='mV',
...                                sampling_rate=10/ms)
>>> stavg = spike_triggered_average(signal, [spiketrain1, spiketrain2],
...                                 (-5 * ms, 10 * ms))