Frequency Domain

Initialize NeuroAnalyzer
using NeuroAnalyzer
eeg = load("files/eeg.hdf");

Frequency domain analysis converts time-domain signals (raw EEG/MEG data) into the frequency domain to examine the power distribution across different frequency components. This analysis is fundamental for understanding brain oscillations and identifying characteristic rhythms.

Key Concepts

  • Frequency Bands:
    • Delta (0.5-4 Hz)
    • Theta (4-8 Hz)
    • Alpha (8-12.5 Hz)
    • Beta (12.5-30 Hz)
    • Gamma (30-100 Hz) - High-level cognitive processing
  • Power Spectral Density (PSD): Shows how signal power is distributed across frequencies
  • Peak Frequency: The frequency with maximum power within a band
  • Band Power: Total power within a specific frequency range

Frequency Range and Band Calculations

Getting range of frequencies and Nyquist frequency:

hz, nyq = freqs(eeg)
length(hz)
128001

hz will contain a vector of frequencies; nyq is the Nyquist frequency.

Calculating band frequency range:

band_frq(eeg; band = :alpha)
(8.0, 13.0)

Tip: Band range is truncated is Nyquist frequency based on EEG sampling rate (128.0) is lower than the band range, e.g. gamma range (30.0-150.0 Hz) is truncated to: 30.0-127.9 Hz for 128 Hz signal.

Power Analysis

Calculating signal total power:

total_power(eeg;
            ch = ["Fp1", "Fp2"])
2×1 Matrix{Float64}:
 11.469288574374753
  4.735783288961288

Calculating band power for the alpha range:

band_power(eeg;
           ch = ["Fp1", "Fp2"],
           flim = (8, 12.5))
# or
band_power(eeg;
           ch = ["Fp1", "Fp2"],
           flim = band_frq(eeg;
                           band = :alpha))
2×1 Matrix{Float64}:
 1.1522559346257222
 0.33722618161617135

Calculating maximum frequency of the beta band:

mp_data = band_mpower(eeg;
                      ch = "eeg",
                      flim = band_frq(eeg; band = :beta),
                      method = :fft)
mfrq = mp_data.maxfrq
plot_bar(mfrq[1:19, 1];
         glabels = labels(eeg)[1:19],
         xlabel = "Channels",
         ylabel = "Frequency [Hz]",
         title = "Maximum β band frequency\n[epoch: 1]")

(!) band_mpower() returns mean band power (mbp), peak frequency of the band (maxfrq) and power (maxbp) and amplitude (maxba) at the peak frequency.

Calculating peak frequency of the alpha band:

peak_frq(eeg;
         ch = ["Fp1", "Fp2"],
         flim = band_frq(eeg; band = :alpha))
2×1 Matrix{Float64}:
 8.0
 8.0

Calculating power at the peak frequency of the alpha band:

peak_pow(eeg;
         ch = ["Fp1", "Fp2"],
         flim = band_frq(eeg; band = :alpha))
2×1 Matrix{Float64}:
 0.352435436932334
 0.12369810929271681

Calculating amplitude at the peak frequency of the alpha band:

peak_amp(eeg;
         ch = ["Fp1", "Fp2"],
         flim = band_frq(eeg; band = :alpha))
2×1 Matrix{Float64}:
 0.5936627299505453
 0.35170742001373356