def lagged_coherence(x, frange, Fs, N_cycles=3, f_step=1, return_spectrum=False):
"""
Quantify the rhythmicity of a time series using lagged coherence.
Return the mean lagged coherence in the frequency range as an
estimate of rhythmicity.
As in Fransen et al. 2015
Parameters
----------
x : array-like 1d
voltage time series
f_range : (low, high), Hz
frequency range for narrowband signal of interest, used to find
zerocrossings of the oscillation
Fs : float
The sampling rate (default = 1000Hz)
N_cycles : float
Number of cycles of the frequency of interest to be used in lagged coherence calculate
f_step : float, Hz
step size to calculate lagged coherence in the frequency range.
return_spectrum : bool
if True, return the lagged coherence for all frequency values. otherwise, only return mean
fourier_or_wavelet : string {'fourier', 'wavelet'}
NOT IMPLEMENTED. ONLY FOURIER
method for estimating phase.
fourier: calculate fourier coefficients for each time window. hanning tpaer.
wavelet: multiply each window by a N-cycle wavelet
Returns
-------
rhythmicity : float
mean lagged coherence value in the frequency range of interest
"""
# Identify Fourier components of interest
freqs = np.arange(frange[0],frange[1]+f_step,f_step)
# Calculate lagged coherence for each frequency
F = len(freqs)
lcs = np.zeros(F)
for i,f in enumerate(freqs):
lcs[i] = _lagged_coherence_1freq(x, f, Fs, N_cycles=N_cycles, f_step=f_step)
if return_spectrum:
return lcs
else:
return np.mean(lcs)
评论列表
文章目录