Phase Clustering

Initialize NeuroAnalyzer
using NeuroAnalyzer
import CairoMakie
# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of
# NeuroAnalyzer figures: remove it
delete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)
using DataFrames
NeuroAnalyzer.progress_bar = false

# resting-state EEG, EEG channels only, 10-second epochs
eeg = load_neuro("files/eeg/eeg.hdf")
eeg = keep_channel(eeg; ch = "eeg")
e10 = epoch(eeg; ep_len = 10)
# theta band (4-8 Hz): the dominant rhythm of this recording
e10_theta = NeuroAnalyzer.filter(e10;
                                 ch = "eeg",
                                 fprototype = :butterworth,
                                 ftype = :bp,
                                 cutoff = (4, 8),
                                 order = 4)

# visual ERP recording: epochs time-locked to the stimulus s71
erp = import_recording("files/eeg/s1_faces.vhdr")
NeuroAnalyzer.filter!(erp;
                      ch = "eeg",
                      fprototype = :butterworth,
                      ftype = :hp,
                      cutoff = 0.1,
                      order = 4)
e71 = epoch(erp;
            marker = "s71",
            offset = 0.5,
            ep_len = 2.5)
e71_theta = NeuroAnalyzer.filter(e71;
                                 ch = "eeg",
                                 fprototype = :butterworth,
                                 ftype = :bp,
                                 cutoff = (4, 8),
                                 order = 4)

Phase clustering measures synchronization of oscillatory activity between brain regions (ISPC) or across trials (ITPC). It quantifies how consistently neural oscillations align in phase (timing), regardless of amplitude. This is crucial for understanding functional connectivity and temporal coordination in the brain.

General idea

If oscillations of two areas are phase synchronized → they are functionally connected (transferring information between these two regions):

  • Timing (phase) is important, not amplitude.
  • Consistency in phase difference is important (relative phase is irrelevant).
Feature ISPC ITPC
Definition Phase clustering between channels Phase clustering across trials
Purpose Functional connectivity Reproducibility of phase
Range 0 (random) to 1 (perfect) 0 (random) to 1 (perfect)
Sensitivity Volume conduction Trial number, frequency
Best Use Hypothesis testing Event-related synchronization

Inter-Site Phase Clustering

Inter-Site Phase Clustering (ISPC) measures the consistency of phase differences between two EEG channels over time. It reflects how synchronized the oscillatory activity is between two brain regions.

Phase Synchronization: If two regions are functionally connected, their oscillations will have consistent phase relationships.

Phase-Invariant: ISPC depends only on the relative phase between channels, not their absolute phase or amplitude.

Sensitivity to Volume Conduction: ISPC can be influenced by common sources (e.g., volume conduction from deep structures), leading to spurious synchrony.

ISPC is computed as the absolute value of the mean complex phase difference between two channels:

\[ \text{ISPC} = \vert \frac{\sum_{t=1}^n \left( e^{i \Delta \phi_t} \right)}{n} \vert \]

where \(\Delta \phi_t = (\phi_j - \phi_k)_t\) is the phase difference between two channels at time \(t\).

The result ranges from 0 (random phases) to 1 (perfect phase clustering).

Interpretation

  • ISPC = 0: Phase differences are random (no synchronization).
  • ISPC = 1: Perfect phase clustering (consistent synchronization).
  • ISPC values between 0 and 1: Indicate varying degrees of phase synchronization.

ISPC for Close vs. Distant Channels:

  • Close channels (e.g., adjacent electrodes) often show higher ISPC due to volume conduction or shared sources.
  • Distant channels reflect true functional connectivity if ISPC is significant after accounting for volume conduction.

Practical Considerations

  • Volume Conduction: ISPC can be inflated by common sources (e.g., volume conduction from deep structures). Use surrogate data or control analyses to account for this.
  • Best for Hypothesis Testing: ISPC is ideal for testing specific hypotheses about phase synchronization between regions.

The phase is only meaningful for a narrow-band signal, so the signals are band-pass filtered first, here in the theta band (4–8 Hz); the phases are obtained using the Hilbert transform.

ispc() with two objects calculates the ISPC between pairs of channels: ch1[i] of obj1 with ch2[i] of obj2, over the samples of the epochs ep1 and ep2:

ch1 = ["Fp1", "C3", "O1"]
ch2 = ["Fp2", "C4", "O2"]
ic = ispc(e10_theta,
          e10_theta;
          ch1 = ch1,
          ch2 = ch2,
          ep1 = 1,
          ep2 = 1)
DataFrame(pair = ch1 .* "-" .* ch2,
          ispc = ic.ispcv[:, 1],
          angle_rad = ic.ispca[:, 1])
3×3 DataFrame
Row pair ispc angle_rad
String Float64 Float64
1 Fp1-Fp2 0.184595 2.64553
2 C3-C4 0.617776 -0.20898
3 O1-O2 0.697468 -0.0614728

Tip: the channels are paired in the order given: ch1[i] with ch2[i]; a channel may be repeated, e.g. ch1 = ["O1", "O1"], ch2 = ["O2", "Fp1"] pairs one seed channel with two others. With exclude_bads enabled, pairs containing a bad channel are removed.

The output also contains the signal difference (sd), the phase difference (phd) and the phases of both signals (s1ph, s2ph), which are shown by plot_ispc():

s_o1 = e10_theta.data[get_channel(e10_theta; ch = "O1"), :, 1][:]
s_o2 = e10_theta.data[get_channel(e10_theta; ch = "O2"), :, 1][:]
plot_ispc(e10_theta.epoch_time,
          s_o1,
          s_o2;
          ispcv = ic.ispcv[3, 1],
          ispca = ic.ispca[3, 1],
          sd = ic.sd[3, :, 1],
          phd = ic.phd[3, :, 1],
          s1ph = ic.s1ph[3, :, 1],
          s2ph = ic.s2ph[3, :, 1],
          unit = "μV")

The phase difference between O1 and O2 stays mostly close to 0 (ISPC ≈ 0.7), with occasional phase slips where the amplitude is low.

With a single object, ispc() calculates the ISPC of all pairs of channels (channels × channels × epochs):

m = ispc(e10_theta; ch = "eeg")
plot_matrix(m.ispcv[:, :, 1];
            xlabels = labels(e10_theta),
            ylabels = labels(e10_theta),
            title = "ISPC (4-8 Hz), epoch 1")

The posterior and temporal channels, which share the dominant theta rhythm, have the highest ISPC; volume conduction contributes to it, especially for neighbouring channels (the diagonal is set to 0).

Inter-Trial Phase Clustering

Inter-Trial Phase Clustering (ITPC) measures the consistency of phase angles across multiple trials (epochs) for a single channel at a specific time point. It reflects how reproducible the oscillatory phase is across trials.

Trial Sensitivity: ITPC is biased upwards for small numbers of trials: for random phases its expected value is about \(\sqrt{\pi / (4n)}\) (e.g. 0.18 for 25 trials, 0.09 for 100 trials), so ITPC values must be compared between conditions with equal numbers of trials (or converted to Rayleigh’s Z).

Frequency Dependence: Higher frequencies require more trials to achieve reliable ITPC estimates.

ITPC is computed as the absolute value of the mean complex phase across trials:

\[ \text{ITPC}(t) = \left\vert \frac{1}{n} \sum_{k=1}^{n} e^{i \phi_k(t)} \right\vert \]

where \(\phi_k(t)\) is the phase angle at time \(t\) in trial \(k\) and \(n\) is the number of trials.

The result ranges from 0 (random phases across trials) to 1 (perfect phase clustering across trials).

Interpretation

  • ITPC = 0: Phase angles are uniformly distributed across trials (no consistency).
  • ITPC = 1: Phase angles are perfectly clustered across trials (high reproducibility).
  • ITPC values between 0 and 1: Indicate varying degrees of phase consistency.

Phase Angle Distributions:

  • Clustered phases (e.g., all vectors pointing in the same direction) indicate consistent timing of oscillatory processes.
  • Uniformly spread phases indicate random timing across trials.

Phases are plotted using polar coordinates, mean phase angle is a vector, which length represents average synchrony.

Rayleigh’s Z: Used to compare ITPC across subjects with different trial numbers:

\[ Z = n \times \text{ITPC}^2 \]

where \(n\) is the number of trials.

Higher \(Z\) indicates stronger phase clustering.

Comparing ITPC

  • Clustered Phases: Indicate consistent timing of oscillatory processes across trials.
  • Uniformly Spread Phases: Indicate random timing across trials.

ITPC requires epochs time-locked to an event, here the visual stimulus s71 (100 trials), filtered in the theta band. itpc() calculates the ITPC, Rayleigh’s Z and the mean phase angle at a time point (in seconds) for each channel:

for t in [-0.3, 0.15, 0.25]
    it = itpc(e71_theta; ch = "O2", t = t)
    println("t = ", t, " s: ITPC = ", round(it.itpcv[1]; digits = 2),
            ", Z = ", round(it.itpcz[1]; digits = 1))
end
t = -0.3 s: ITPC = 0.1, Z = 1.0
t = 0.15 s: ITPC = 0.61, Z = 37.5
t = 0.25 s: ITPC = 0.62, Z = 38.3

Before the stimulus the phases are random (ITPC close to the chance level of about 0.09 for 100 trials), after the stimulus they are strongly clustered.

The phases of the trials at 200 ms and their mean vector:

it = itpc(e71_theta; ch = "O2", t = 0.2)
plot_itpc(it.itpcph[1, :];
          itpcv = it.itpcv[1],
          itpca = it.itpca[1],
          title = "O2, 200 ms")

itpc_spec() calculates the ITPC at each frequency and time point (using wavelet convolution of the unfiltered epochs):

sp = itpc_spec(e71;
               ch = "O2",
               flim = (2, 30),
               nfrq = 29)
plot_itpc_spec(e71.epoch_time,
               sp.f,
               sp.itpcs;
               title = "ITPC, O2")

The phase locking is strongest at 4–6 Hz around 0–500 ms. At low frequencies the wavelets are long, so the ITPC is smeared in time (here it appears to start before the stimulus); the lowest frequencies are also affected by edge effects at the beginning and end of the epoch.

Applications

ISPC

  • Functional Connectivity: Identify synchronized brain regions during tasks or resting states.
  • Task-Related Synchrony: Study how phase synchronization changes with cognitive or motor tasks.
  • Clinical Research: Investigate abnormal phase synchronization in disorders like epilepsy or schizophrenia.

ITPC

  • Event-Related Synchronization: Measure how phase alignment changes time-locked to stimuli (e.g., stimulus onset, response).
  • Cognitive Processes: Study oscillatory dynamics during attention, memory, or decision-making.
  • Comparing Experiments: Use ITPC to compare phase consistency across different conditions or groups.

Practical Considerations

  • Trial Number: ITPC is biased upwards for small numbers of trials. Ensure equal trial counts when comparing ITPC across conditions or groups, or use Rayleigh’s Z.
  • Frequency Dependence: Higher frequencies (e.g., gamma) require more trials for reliable estimates.

Mean phase angle:

ISPC measure is phase-invariant: