Basic operations

Editing NEURO objects

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

Removing object from memory:

eeg = nothing

Copying to a new object:

eeg = load("files/eeg.hdf")
eeg_new = deepcopy(eeg)

Tip: Do not use eeg_new = eeg as all operations on eeg_new will also affect eeg (see Julia deepcopy() for more details).

All operations and their parameters are stored within the object. Showing the last 5 processing operations:

history(eeg)[1:5]

Tip: operations are stored in descending chronological order. Use history(eeg)[end:-1:1] to show the oldest operations first.

Any metadata can be extracted or modified via HEADER structure:

eeg.header.recording[:file_name]
"eeg.hdf"

Adding a note:

add_note!(eeg,
          note = "This is a test description.")

Viewing the note:

view_note(eeg)
"This is a test description."

Deleting note:

delete_note!(eeg)

Showing properties:

header(eeg)
              Data type: EEG
            File format: EDF
            Source file: eeg.hdf
         File size [MB]: 52044.49
       Memory size [MB]: 50.8
                Subject:  528004  SIT 52, 20220831-122227-{d589f756-53fc-4f1b-915d-6e3b8c1560ad}
              Recording: EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
        Recording notes: 
         Recording date: 31.08.22
         Recording time: 12:32:53
     Sampling rate (Hz): 256
Signal length [samples]: 256001
Signal length [seconds]: 1000.0039
     Number of channels: 24
              Epochs ID: 
       Number of epochs: 1
 Epoch length [samples]: 256001
 Epoch length [seconds]: 1000.0039
         Reference type: physical
         Line frequency: 50 Hz
                Markers: no
      Channel locations: yes
 Number of EEG channels: 19

Showing object properties, all channels details will also be shown (number, label, type, unit and bad status):

info(eeg)

Getting basic channels statistics:

NeuroAnalyzer.describe(eeg)
< EEG, 24 × 256001 × 1 (1000.00390625 s) >
ch  label           type        unit    range     mean      sd        min       Q1        median    Q3        max       
1   Fp1             EEG         μV      62.72     0.05      3.4       -32.56    0.0       0.0       5.46      30.16     
2   Fp2             EEG         μV      50.08     0.08      2.19      -28.64    0.06      0.06      3.54      21.44     
3   F3              EEG         μV      56.35     0.06      2.87      -32.4     -0.02     -0.02     4.49      23.95     
4   F4              EEG         μV      80.63     0.05      1.6       -49.64    0.05      0.05      2.37      31.0      
5   C3              EEG         μV      91.25     0.09      3.85      -50.81    0.02      0.02      6.28      40.44     
6   C4              EEG         μV      57.68     0.08      2.34      -32.4     0.05      0.05      3.75      25.28     
7   P3              EEG         μV      70.26     0.06      4.65      -28.04    -0.04     -0.04     7.68      42.22     
8   P4              EEG         μV      69.95     0.08      4.78      -30.95    0.02      0.02      7.95      38.99     
9   O1              EEG         μV      70.79     0.1       5.02      -28.39    0.01      0.01      8.35      42.4      
10  O2              EEG         μV      67.46     0.05      5.12      -28.42    -0.01     -0.01     8.49      39.05     
11  F7              EEG         μV      100.79    0.07      3.51      -56.62    -0.02     -0.02     5.38      44.17     
12  F8              EEG         μV      142.67    0.05      2.9       -50.63    0.02      0.02      3.97      92.03     
13  T3              EEG         μV      67.98     0.09      4.51      -28.14    0.02      0.02      7.47      39.84     
14  T4              EEG         μV      60.24     0.02      3.93      -29.16    -0.02     -0.02     6.36      31.08     
15  T5              EEG         μV      71.5      0.09      5.12      -29.82    0.02      0.02      8.51      41.69     
16  T6              EEG         μV      65.31     0.07      4.69      -28.07    0.03      0.03      7.73      37.25     
17  A1              REF         μV      111.04    -0.01     6.74      -61.24    -0.05     -0.05     11.0      49.79     
18  A2              REF         μV      89.31     -0.01     6.44      -52.32    0.08      0.08      10.36     36.99     
19  Fz              EEG         μV      34.46     -0.0      1.65      -23.98    -0.01     -0.01     2.67      10.48     
20  Cz              EEG         μV      60.21     0.12      2.95      -30.13    0.06      0.06      4.82      30.09     
21  Pz              EEG         μV      72.0      0.08      4.51      -34.64    0.02      0.02      7.48      37.36     
22  EOG1            EOG         μV      196.47    -0.03     7.48      -93.38    -0.05     -0.05     11.38     103.09    
23  EOG2            EOG         μV      120.71    -0.02     5.38      -64.11    -0.07     -0.07     8.51      56.6      
24  ECG             ECG         mV      1173.84   -0.06     86.37     -615.01   -6.18     -6.18     50.63     558.83    

Basic NEURO object properties

Sampling rate:

sr(eeg)
256

Size of the eeg.data array (channels, samples, epochs):

size(eeg)
(24, 256001, 1)

Number of channels:

nchannels(eeg)
24

Number of epochs:

nepochs(eeg)
1

Signal length in samples:

signal_len(eeg)
256001

Epoch length in samples:

epoch_len(eeg)
256001

Channel labels:

l = labels(eeg)
first(l, 5)
5-element Vector{String}:
 "Fp1"
 "Fp2"
 "F3"
 "F4"
 "C3"

Object type:

datatype(eeg)
"eeg"

Converting data to a DataFrame:

df = to_df(eeg)
# show first 5 time points
first(df, 5)
5×25 DataFrame
Row time Fp1 Fp2 F3 F4 C3 C4 P3 P4 O1 O2 F7 F8 T3 T4 T5 T6 A1 A2 Fz Cz Pz EOG1 EOG2 ECG
Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
1 0.0 -3.61876 0.451472 -4.1843 3.4805 1.29964 3.79688 -0.161454 8.19806 0.75293 5.0857 -5.62906 3.60649 -2.52252 5.05018 -2.08951 6.29989 -17.5273 -6.10144 -1.02441 4.27073 3.32821 -6.74063 -0.963465 -5.43696
2 0.0039 -2.62108 -0.614711 -1.80555 2.54468 4.66955 4.77973 2.88255 7.17105 3.51212 8.42386 -3.88443 3.44589 0.997312 5.38267 2.13859 6.55183 -10.4832 -0.887447 -0.871635 4.09755 5.51992 -4.54914 -2.07689 -8.15171
3 0.0078 -0.935175 -3.5474 0.853763 0.369701 5.54463 3.4151 5.49478 8.89833 7.43718 10.4673 -0.3261 2.15743 4.76706 4.92332 5.87302 7.32285 -3.34778 1.38792 -0.461632 4.09585 7.44717 -1.63285 -1.86917 -0.795649
4 0.0117 -3.67928 -1.21269 -5.3538 1.62046 -2.76407 1.25433 -3.43964 5.69924 -1.98902 3.70845 -6.4243 3.0027 -3.31217 2.61098 -3.35343 2.86376 -13.1599 -4.03449 -0.873815 -0.640716 0.35095 -2.73419 3.86397 -10.4405
5 0.0156 -2.24259 0.535407 -2.63971 1.72694 -2.19496 0.146516 -4.57769 1.1243 -3.62526 2.80111 -2.96658 0.375008 -4.23205 0.52774 -4.10575 0.936797 -5.97518 -1.0515 -0.895591 -2.582 -1.36012 -6.01542 3.53709 -4.47885

or

df = info(eeg, df = true)

Channel operations

Showing channel labels:

labels(eeg)
24-element Vector{String}:
 "Fp1"
 "Fp2"
 "F3"
 "F4"
 "C3"
 "C4"
 "P3"
 "P4"
 "O1"
 "O2"
 "F7"
 "F8"
 "T3"
 "T4"
 "T5"
 "T6"
 "A1"
 "A2"
 "Fz"
 "Cz"
 "Pz"
 "EOG1"
 "EOG2"
 "ECG"

Getting channel by its label:

get_channel(eeg, ch = "Fp1")
1-element Vector{Int64}:
 1

Renaming channel label:

rename_channel(eeg,
               ch = "Cz",
               name = "CZ")

Deleting channels (epochs and channels may be specified using number, range or vector):

delete_channel(eeg, ch = "Cz")

Deleting a range of channels:

chs = labels(obj)[10:18]
delete_channel(eeg, ch = chs)

Keeping channel(s) - will delete all other channels:

keep_channel(eeg,
             ch = get_channel(eeg, type = "eeg")[1:4])

Replacing channel 1 data with channel 18 data:

ch1 = 1
ch2 = 18
ch_data = extract_channel(eeg,
                          ch = get_channel(eeg, type = "all")[ch2])
replace_channel(eeg,
                ch = get_channel(eeg, type = "all")[1],
                s = ch_data)

Epoch operations

Epoching is a procedure in which specific time-windows are extracted from the continuous EEG signal; these time windows are called epochs. Epochs usually are time-locked with respect an event e.g. a visual stimulus. Recorded data is stored as matrix channel × time (where time is the complete continuous the signal). After the epoching procedure the matrix is transformed into an array: channel × time × epochs, where time is the time length of each epoch, and epochs is the number of segments you extracted from continuous signal.

Imagine we have a signal with length of 60 s and our sampling frequency is 1 Hz. The matrix representation of your EEG signal would be 1×60 array or matrix, so if you divide your main signal to some 2 s signals, you would have 30 epoch (each 2 s of your main signal would be an epoch). This could be done by a simple for loop resulting in a new matrix which size is 30×1×2.

If you want to extract epochs from your signal, you should know what are the segments of interest to be analyzed, for instance, a specific stimulus.

Tip: Many processing operations (such as filtering or ICA decomposition) should be performed on non-epoched (continuous) signal (e.g. due to the edge artifacts that may occur in case of filtering or the minimum required signal length for ICA decomposition).

Epoching EEG into 10-second epochs:

e10 = epoch(eeg, ep_len = 10)
header(e10)
              Data type: EEG
            File format: EDF
            Source file: eeg.hdf
         File size [MB]: 52044.49
       Memory size [MB]: 48.87
                Subject:  528004  SIT 52, 20220831-122227-{d589f756-53fc-4f1b-915d-6e3b8c1560ad}
              Recording: EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
        Recording notes: 
         Recording date: 31.08.22
         Recording time: 12:32:53
     Sampling rate (Hz): 256
Signal length [samples]: 256000
Signal length [seconds]: 1000.0
     Number of channels: 24
              Epochs ID: length_10s
       Number of epochs: 100
 Epoch length [samples]: 2560
 Epoch length [seconds]: 10.0
         Reference type: physical
         Line frequency: 50 Hz
                Markers: no
      Channel locations: yes
 Number of EEG channels: 19

Getting data of the 1st epoch:

e10e1 = extract_epoch(e10, ep = 1)
header(e10e1)
              Data type: EEG
            File format: EDF
            Source file: eeg.hdf
         File size [MB]: 52044.49
       Memory size [MB]: 0.51
                Subject:  528004  SIT 52, 20220831-122227-{d589f756-53fc-4f1b-915d-6e3b8c1560ad}
              Recording: EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
        Recording notes: 
         Recording date: 31.08.22
         Recording time: 12:32:53
     Sampling rate (Hz): 256
Signal length [samples]: 2560
Signal length [seconds]: 10.0
     Number of channels: 24
              Epochs ID: length_10s
       Number of epochs: 1
 Epoch length [samples]: 2560
 Epoch length [seconds]: 10.0
         Reference type: physical
         Line frequency: 50 Hz
                Markers: no
      Channel locations: yes
 Number of EEG channels: 19

Deleting epochs:

delete_epoch(e10, ep = 1)
delete_epoch(e10, ep = 8:10)
delete_epoch(e10, ep = [1:5; 9; 10])

Tip: Note the use of ; if a noncontinuous range is specified.

Keeping epochs (deleting all other epochs):

keep_epoch(e10,
           ep = [1, 3, 5, 9])

Split into 5-second epochs and then average into one epoch:

e5 = epoch(eeg, ep_len = 5)
e5avg = average_epochs(e5)
header(e5avg)
              Data type: ERP
            File format: EDF
            Source file: eeg.hdf
         File size [MB]: 52044.49
       Memory size [MB]: 39.29
                Subject:  528004  SIT 52, 20220831-122227-{d589f756-53fc-4f1b-915d-6e3b8c1560ad}
              Recording: EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
        Recording notes: 
         Recording date: 31.08.22
         Recording time: 12:32:53
     Sampling rate (Hz): 256
Signal length [samples]: 257280
Signal length [seconds]: 1005.0
     Number of channels: 19
              Epochs ID: length_5s
       Number of epochs: 201
 Epoch length [samples]: 1280
 Epoch length [seconds]: 5.0
                Markers: no
      Channel locations: yes
 Number of EEG channels: 19

Tip: average_epochs() averages EEG/MEG epochs. Non-EEG/MEG channels are removed. OBJ.header.recording[:data_type] becomes erp (for EEG) or erf for MEG. First epoch is the ERP/ERF.

Epoching at the event marker (each epoch is 1500 ms long and starts 200 ms before the event marker):

erp = epoch(eeg,
            marker = "Eyes Open",
            offset = 0.2,
            ep_len = 1.5)

Creating sub-epochs (of reduced time range, starting at 0.1 sec and ending at 1.1 sec):

subepoch(erp,
         ep_start = 0.1,
         ep_end = 1.1)