By default all signal channels are deconstructed and the number of components is the number of signal channel:
= ica_decompose(eeg) ic, ic_mw, ic_var
Output:
[ Info: Attempting to calculate 19 components.
[ Info: Converged at: 1.0e-6
[ Info: Component 1: percent variance accounted for: 29.94
[ Info: Component 2: percent variance accounted for: 20.0
[ Info: Component 3: percent variance accounted for: 11.25
[ Info: Component 4: percent variance accounted for: 7.9
[ Info: Component 5: percent variance accounted for: 6.05
[ Info: Component 6: percent variance accounted for: 6.04
[ Info: Component 7: percent variance accounted for: 5.68
[ Info: Component 8: percent variance accounted for: 3.95
[ Info: Component 9: percent variance accounted for: 2.45
[ Info: Component 10: percent variance accounted for: 1.46
[ Info: Component 11: percent variance accounted for: 1.13
[ Info: Component 12: percent variance accounted for: 0.83
[ Info: Component 13: percent variance accounted for: 0.73
[ Info: Component 14: percent variance accounted for: 0.68
[ Info: Component 15: percent variance accounted for: 0.47
[ Info: Component 16: percent variance accounted for: 0.44
[ Info: Component 17: percent variance accounted for: 0.41
[ Info: Component 18: percent variance accounted for: 0.32
[ Info: Component 19: percent variance accounted for: 0.27
(!) Components are sorted in the order of decreasing variance accounted for (the higher the value, the higher the component accounts for all the data).
To deconstruct into defined number of components:
= ica_decompose(eeg, n=5) ic, ic_mw, ic_var
To deconstruct selected channels:
= ica_decompose(eeg, ch=1:10, n=5) ic, ic_mw, ic_var
ICA components and weights may be included in the NeroAnalyzer object as embedded components:
add_component!(eeg, c=:ic, v=ic)
add_component!(eeg, c=:ic_mw, v=ic_mw)
(!) 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()
.
To reconstruct the source signal without a specific component(s):
= ica_reconstruct(eeg, ic, ic_mw, ic_idx=[2, 5, 8])
eeg_new preview(eeg, eeg_new)
(!) by default ic_idx
is the list of components that
should be removed during reconstruction.
To reconstruct the source signal keeping only the
selected component(s), use keep=true
option:
= ica_reconstruct(eeg, ic, ic_mw, ch=1:19, ic_idx=1:2, keep=true)
eeg_new preview(eeg, eeg_new)
To use the embedded component for reconstruction:
ica_reconstruct!(eeg, ic_idx=1)
(!) The components must be named :ic
and
:ic_mw
.
To remove the component from the signal:
ica_remove(eeg, ic, ic_mw, ic_idx=1)
(!) ica_remove()
reconstructs the source signal using
only the specified component(s) and subtract the reconstructed signal
from the source.
To plot the components:
= NeuroAnalyzer.plot(eeg, ch=1:19, mono=true, seg=(0, 20))
p1 = NeuroAnalyzer.plot(eeg, ic, mono=true, seg=(0, 20))
p2 = Plots.plot(p1, p2, layout=(2, 1))
p plot_save(p, file_name="images/ica_components.png")
To plot the components power spectrum:
= plot_psd(eeg, ch=1, 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=1:19, ic_idx=2, keep=true);
eeg_new = plot_psd(eeg_new, ch=1, title="signal reconstructed from ICA #02", mono=true)
p3 = ica_reconstruct(eeg, ic, ic_mw, ch=1:19, ic_idx=2);
eeg_new = plot_psd(eeg_new, ch=1, title="signal after removing ICA #02", mono=true)
p4 = Plots.plot(p1, p2, p3, p4, layout=(2, 2))
p plot_save(p, file_name="images/ica_components_psd.png")
To plot the component spectrogram:
= plot_spectrogram(eeg, seg=(0, 10), ch=1, title="original signal")
p1 = plot_spectrogram(eeg, ic, c_idx=2, title="ICA #02")
p2 = ica_reconstruct(eeg, ic, ic_mw, ch=1:19, ic_idx=2, keep=true);
eeg_new = plot_spectrogram(eeg_new, ch=1, title="signal reconstructed from ICA #02")
p3 = ica_reconstruct(eeg, ic, ic_mw, ch=1:19, ic_idx=2);
eeg_new = plot_spectrogram(eeg_new, ch=1, title="signal after removing ICA #02")
p4 = Plots.plot(p1, p2, p3, p4, layout=(2, 2))
p plot_save(p, file_name="images/ica_components_spec.png")
(!) ch
is the channel number; ic_idx
is the
component number.
Plot topographical map of ICA components averaged at time segment [20, 21] seconds:
= plot_icatopo(eeg, ic, ic_mw, seg=(20, 21))
p plot_save(p, file_name="images/ica_topo1.png")
or using embedded components:
= plot_icatopo(eeg, ic_idx=1:10, seg=(20, 21))
p plot_save(p, file_name="images/ica_topo2.png")
EEG has already been filtered at 1 Hz and 40 hz, ECG is in channel 24:
= ica_decompose(eeg, ch=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 24])
ic, ic_mw, ic_var = ica_reconstruct(eeg, ic, ic_mw, ic_idx=1)
eeg_new = NeuroAnalyzer.plot(eeg, ch=[1, 2, 3, 4, 24])
p1 = NeuroAnalyzer.plot(eeg, ic, c_idx=1:4)
p2 = NeuroAnalyzer.plot(eeg_new, ch=1:4)
p3 = Plots.plot(p1, p2, p3, layout=(3, 1))
p plot_save(p, file_name="images/ecg_ica.png")
Output:
[ Info: Converged at: 1.0e-6
[ Info: Component 1: percent variance accounted for: 76.98
[ Info: Component 2: percent variance accounted for: 10.16
[ Info: Component 3: percent variance accounted for: 8.1
[ Info: Component 4: percent variance accounted for: 1.17