elephant.sta.spike_field_coherence

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:
signalneo AnalogSignal object

‘signal’ contains n analog signals.

spiketrainSpikeTrain or BinnedSpikeTrain

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

**kwargs:

All kwargs are passed to scipy.signal.coherence().

Returns:
coherencecomplex 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.

frequenciesQuantity array

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

Examples

Plot the SFC between a regular spike train at 20 Hz, and two sinusoidal time series at 20 Hz and 23 Hz, respectively.

import numpy as np
import matplotlib.pyplot as plt
import quantities as pq
from quantities import s, ms, mV, Hz, kHz
import neo, elephant

t = pq.Quantity(range(10000),units='ms')
f1, f2 = 20. * Hz, 23. * Hz
signal = neo.AnalogSignal(np.array([
                          np.sin(f1 * 2. * np.pi * t.rescale(s)),
                          np.sin(f2 * 2. * np.pi * t.rescale(s))]).T,
                          units=pq.mV, sampling_rate=1. * kHz)
spiketrain = neo.SpikeTrain(
   range(t[0], t[-1], 50), units='ms',
   t_start=t[0], t_stop=t[-1])
sfc, freqs = elephant.sta.spike_field_coherence(
   signal, spiketrain, window='boxcar')

plt.plot(freqs, sfc[:,0])
plt.plot(freqs, sfc[:,1])
plt.xlabel('Frequency [Hz]')
plt.ylabel('SFC')
plt.xlim((0, 60))
plt.show()

(Source code, png, hires.png, pdf)

../../../_images/elephant-sta-spike_field_coherence-1.png