NeuroAnalyzer tutorials: Analyze EEG (2)

Frequencies, Nyquist frequency:

hz, nyq = freqs(eeg)

Channels stats:


Calculate signal total power:


Calculate band power:

band_power(eeg, frq_lim=(8, 12.5))

Calculate maximum frequency of a band power:

_, mfrq, _ = band_mpower(eeg, ch=get_channel(eeg, type="eeg"), frq_lim=band_frq(eeg, band=:alpha))
p = plot_bar(mfrq[1:19, 1], xlabels=labels(eeg)[1:19], ylabel="Frequency [Hz]", title="Maximum α band frequency\n[epoch: 1]")
plot_save(p, file_name="images/alpha-maxfrq.png")

Calculate frontal alpha asymmetry index:

# left
ch_left = channel_cluster(eeg, cluster=:f1)
# or
ch_left = channel_pick(eeg, p=[:left, :frontal])
# right
ch_right = channel_cluster(eeg, cluster=:f2)
# or
ch_right = channel_pick(eeg, p=[:right, :frontal])

# alpha frequency
alpha = band_frq(eeg, band=:alpha)

# asymmetry index
band_asymmetry(eeg, frq_lim=alpha, ch1=ch_left, ch2=ch_right)

Calculate covariance matrix:


Calculate correlation matrix


Calculate auto-covariance:

acov(eeg, lag=20, norm=false)

Calculate cross-covariance:

cc, lags = xcov(eeg, lag=20, demean=true)

eeg1 = filter(eeg, fprototype=:butterworth, ftype=:bs, cutoff=(45, 55), order=8)
eeg2 = filter(eeg, fprototype=:butterworth, ftype=:bs, cutoff=(45, 55), order=12)
cc, lags = xcov(eeg1, eeg2, ch1="F3", ch2="F4", ep1=1, ep2=1, lag=20, demean=true, norm=true)

Mutual information:

m = mutual_information(eeg, ch=get_channel(eeg, type="eeg"))
plot_matrix(m[:, :, 1], xlabels=labels(eeg)[1:19], ylabels=labels(eeg)[1:19])


e, _, _ = entropy(eeg, ch=get_channel(eeg, type="eeg"))
plot_bar(e[:, 1], labels=labels(eeg)[1:19], seriestype=:bar, title="Entropy, epoch 1")

Signal stats:

e = epoch_stats(eeg)


ispc(eeg, eeg, ch1=get_channel(eeg, type="eeg")[1:5], ch2=get_channel(eeg, type="eeg")[6:10], ep1=1, ep2=1)


pli(eeg, eeg, ch1="F3", ch2="F4", ep1=1, ep2=1)

Amplitude Envelope Correlation:

env_cor(eeg, eeg, ch1="F3", ch2="F4", ep1=1, ep2=2)

Perform discrete wavelet transform (DWT) and continuous wavelet transform (CWT):

dw_trans(e10, wt=wavelet(WT.haar), type=:sdwt)
cw_trans(e10, wt=wavelet(Morlet(π), β=2))

SNR (signal-to-noise) may be estimated from epoched EEG signal.

snr, hz = snr(eeg)
p = plot(hz, snr[1, :], label="ch 1", xlabel="Frequency [Hz]", ylabel="SNR")
p = plot!(hz, snr[2, :], label="ch 2")
p = plot!(hz, snr[3, :], label="ch 3")
p = plot!(hz, snr[4, :], label="ch 4")
plot_save(p, file_name="images/eeg_snr.png")