plot_time_series(times, sig)

###################################################################################################
# Compute lagged coherence for an alpha oscillation
# -------------------------------------------------
#
# We can compute lagged coherence with the :func:`~.compute_lagged_coherence` function.
#

###################################################################################################

# Set the frequency range to compute lagged coherence across
f_range = (8, 12)

# Compute lagged coherence
lag_coh_alpha = compute_lagged_coherence(sig, fs, f_range)

# Check the resulting value
print('Lagged coherence = ', lag_coh_alpha)

###################################################################################################
# Compute lagged coherence across the frequency spectrum
# ------------------------------------------------------
#
# Notice that lagged coherence peaks around 10Hz (the frequency of our oscillation).
#
# However, the peak is not very specific to that frequency.
#

###################################################################################################
Exemple #2
0
# Set the frequency range to compute lagged coherence across
f_range = (8, 12)

###################################################################################################
# Apply Lagged Coherence
# ~~~~~~~~~~~~~~~~~~~~~~
#
# Next, we can apply the lagged coherence algorithm to get the average lagged coherence
# across the alpha range.
#

###################################################################################################

# Compute lagged coherence
lag_coh_alpha = compute_lagged_coherence(sig, fs, f_range)

###################################################################################################
# Lagged coherence result
# ~~~~~~~~~~~~~~~~~~~~~~~
#
# The resulting lagged coherence value is bound between 0 and 1, with higher values
# indicating greater rhythmicity in the signal.
#

###################################################################################################

# Check the resulting value
print('Lagged coherence = ', lag_coh_alpha)

###################################################################################################
Exemple #3
0
#
# To do so, let's use the lagged coherence measure. Using lagged coherence, we can measure,
# per channel, the frequency which displays the most rhythmic activity, as well as the score
# of how rhythmic this frequency is. We can do so per location, to map rhythmic activity
# topographically across a range of frequencies.
#

###################################################################################################

# Settings for lagged coherence, as frequency range (start, stop, step)
f_range = (5, 25, 0.25)

###################################################################################################

# Calculate lagged coherence on our example channel data
lcs, freqs = compute_lagged_coherence(sig, fs, f_range, return_spectrum=True)

###################################################################################################

# Visualize lagged coherence across all frequencies
plot_lagged_coherence(freqs, lcs)

###################################################################################################

# Get the most rhythmic frequency and the associated lagged coherence score
max_freq = freqs[np.argmax(lcs)]
max_score = np.max(lcs)

print('The frequency with the greatest rhythmicity is {:1.1f} Hz '\
      'with a lagged coherence score of {:1.2f}.'.format(max_freq, max_score))
for ind in burst_starts:
    sig[ind:ind + burst_samples] += burst_kernel

###################################################################################################

# Plot example signal
plot_time_series(times, sig)

###################################################################################################
#
# Compute lagged coherence for an alpha oscillation
# -------------------------------------------------
#

f_range = (8, 12)
lag_coh_alpha = compute_lagged_coherence(sig, fs, f_range)
print('Lagged coherence = ', lag_coh_alpha)

###################################################################################################
#
# Compute lagged coherence across the frequency spectrum
# ------------------------------------------------------
#
# Notice that lagged coherence peaks around 10Hz (the frequency of our
# oscillation), but it is not very specific to that frequency.
#

lag_coh_by_f, freqs = compute_lagged_coherence(sig,
                                               fs, (1, 40),
                                               return_spectrum=True)