using NeuroAnalyzer
using Plots
= load("files/eeg.hdf");
eeg trim!(eeg, seg=(0, 20), remove_epochs=false)
[ Info: Loaded: EEG (24 × 308480 × 1; 1204.996 s)
Load data:
using NeuroAnalyzer
using Plots
= load("files/eeg.hdf");
eeg trim!(eeg, seg=(0, 20), remove_epochs=false)
[ Info: Loaded: EEG (24 × 308480 × 1; 1204.996 s)
Deconstruct all EEG channels into defined number (3) of components:
= ica_decompose(eeg, ch="eeg", n=3) ic, ic_mw, ic_var
m[ Warning: The input signal should be cleaned from major artifacts and HP filtered at 1-2 Hz prior to ICA decomposition.
[ Info: Attempting to calculate 3 components
[ Info: Training will end when W change = 0.99 or after 900 steps
[ Info: Data will be demeaned and pre-whitened
m[ Info: Converged at: 1.0e-6
[96m[ Info: Component 1: percent variance accounted for: 67.72
[ Info: Component 2: percent variance accounted for: 23.11
[ Info: Component 3: percent variance accounted for: 4.74
(ic = [-0.026692780410890453 -0.018673454696686142 … -0.015671755031536654 0.00042524428068336714; -0.39926373345400895 -0.34341611285617535 … 0.1008001374158447 0.0025435847965964453; -0.37786050478876715 -0.3222469492639225 … 0.04213585455906553 0.000809439803878764],
ic_mw = [-11.536166812831665 1.7982705234945318 -1.7999494060521604; 7.750143830744576 0.9501120154799216 -119.49806521002101; … ; -15.229340925564426 -0.112948883911168 -1.5797014326707677; -18.96818499568274 0.1425248753995763 -1.6517217809028022],
ic_var = [67.71693439502857, 23.10766356442069, 4.739722690363568],)
(!) Components are sorted in the order of decreasing variance accounted for (the higher the value, the higher the component accounts for all the data).
(!) By default, 100 iterations per each tolerance value ([0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 0.5, 0.9, 0.99]
); hence the default 100 iterations gives 900 steps.
ICA components and weights may be included in the NeroAnalyzer object as embedded components:
= deepcopy(eeg)
eeg_ic add_component!(eeg_ic, c=:ic, v=ic)
add_component!(eeg_ic, c=:ic_mw, v=ic_mw)
(!) Embedded components are removed from the object when the signal data is altered in any way.
(!) Embedded components are saved with the signal data when using save()
.
Reconstruct the source signal without a specific component(s):
ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=[1, 3])
(!) By default ic_idx
is the list of components that should be removed during reconstruction.
Reconstruct the source signal keeping only the selected component(s), use keep=true
option:
ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=1:2, keep=true)
Use the embedded component for reconstruction:
ica_reconstruct(eeg_ic, ch="eeg", ic_idx=1)
(!) The components must be named :ic
and :ic_mw
.
Reconstruct using external components:
ica_remove(eeg, ic, ic_mw, ch="eeg", ic_idx=1)
(!) ica_remove()
reconstructs the source signal using only the specified component(s) and subtract the reconstructed signal from the source.
Plot the components:
= NeuroAnalyzer.plot(eeg, ch="eeg", mono=true, seg=(0, 20), title="EEG channels")
p1 = NeuroAnalyzer.plot(eeg, ic, mono=true, seg=(0, 20), title="ICA components")
p2 plot(p1, p2, layout=(2, 1)) Plots.
Plot the components power spectrum:
= plot_psd(eeg, ch="Fp1", title="original signal", mono=true)
p1 = plot_psd(eeg, ic, c_idx=2, title="ICA #02", mono=true)
p2 = ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=2, keep=true)
eeg_new = plot_psd(eeg_new, ch="Fp1", title="signal reconstructed from ICA #02", mono=true)
p3 = ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=2)
eeg_new = plot_psd(eeg_new, ch="Fp1", title="signal after removing ICA #02", mono=true)
p4 plot(p1, p2, p3, p4, layout=(2, 2)) Plots.
Plot the component spectrogram:
= plot_spectrogram(eeg, seg=(0, 10), ch="Fp1", title="original signal")
p1 = plot_spectrogram(eeg, ic, c_idx=2, title="ICA #02")
p2 = ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=2, keep=true);
eeg_new = plot_spectrogram(eeg_new, ch="Fp1", title="signal reconstructed from ICA #02")
p3 = ica_reconstruct(eeg, ic, ic_mw, ch="eeg", ic_idx=2);
eeg_new = plot_spectrogram(eeg_new, ch="Fp1", title="signal after removing ICA #02")
p4 plot(p1, p2, p3, p4, layout=(2, 2)) Plots.