NeuroAnalyzer tutorials: Analyze EEG (2)

Frequencies, Nyquist frequency:

hz, nyq = freqs(eeg)

Channels stats:


Calculate signal total power:


Calculate band power:

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

Calculate maximum frequency of a band power:

_, mfrq, _ = band_mpower(eeg, ch=1:19, f=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 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, channel1=1, channel2=1, epoch1=1, epoch2=1, lag=20, demean=true, norm=true)

Mutual information:

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


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

Coherence over time:

c, msc, ic = tcoherence(eeg, eeg)

eeg_alpha = filter(eeg, fprototype=:butterworth, ftype=:bp, cutoff=band_frq(eeg, band=:alpha), order=8)
# O1 vs O2
c, msc, ic = tcoherence(eeg_alpha, eeg_alpha, channel1=9, channel2=10, epoch1=1, epoch2=2)
p = plot(eeg, c, c_idx=1, ep=1, scale=false)
plot_save(p, file_name="images/tcoh.png")

Coherence over frequencies:

# O1 vs O2, alpha range
c, msc, f = fcoherence(eeg, eeg, channel1=9, channel2=10, epoch1=1, epoch2=1, frq_lim=band_frq(eeg, band=:alpha))
plot(f[:, :, 1], c[:, :, 1])

Signal stats:

e = epoch_stats(eeg)


ispc(eeg, eeg, channel1=1:5, channel2=6:10, epoch1=1, epoch2=1)


pli(eeg, eeg, channel1=1, channel2=2, epoch1=1, epoch2=1)

Amplitude Envelope Correlation:

env_cor(eeg, eeg, channel1=3, channel2=4, epoch1=10, epoch2=10)

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")