Example

This example demonstrates basic processing of an EEG measurement with Neuroimaging.jl`. An example file is imported, and the basic properties of the data structure are reported including sampling rate and channel information. Simple preprocessing, such as referencing and channel manipulation is demonstrated. And the data of a single channel and multiple channels is visualised.

Import EEG measurement in to Neuroimaging.jl for analysis

The first step in this example is to import the required packages. In addition to importing the Neuroimaging.jl package, the DataDeps package is imported to facilitate access to the example dataset ExampleSSR which contains an example EEG measurement in the Biosemi data format.

To read the data the function read_EEG is used. This returns the data as a GeneralEEG type which stores EEG measurements that are not associated with any particular experimental paradigm.

using Neuroimaging, DataDeps

data_path = joinpath(
    datadep"ExampleSSR",
    "Neuroimaging.jl-example-data-master",
    "neuroimaingSSR.bdf",
)

s = read_EEG(data_path)
EEG measurement of 5.0 mins with 7 channels sampled at 8192.0 Hz

To view a summary of the returned data simply call the returned variable.

s
EEG measurement of 5.0 mins with 7 channels sampled at 8192.0 Hz

Probe information about the EEG measurement

The summary output of the imported data only includes basic information. Several functions are provided to access more detailed aspects of the recording. To list the names of the channels in this measurement call:

channelnames(s)
7-element Vector{String}:
 "F5"
 "TP7"
 "O1"
 "F6"
 "Cz"
 "TP8"
 "O2"

Similarly to query the sample rate of the measurement. Internally Neuroimaging.jl makes extensive use of the Uniful package and stores many values with their associated units. To obtain the sampling rate in Hz as a floating point number call:

samplingrate(s)
8192.0 Hz
Accessing data structure fields

Note that we call the function channelnames, and do not access properties of the type itself. This allows the use of the same functions across multiple datatypes due to the excellent dispatch system in the Julia language. Accessing the fields of data types directly is not supported in Neuroimaging.jl and may break at any time. If you wish to access an internal type field and a function is not provided then raise a GitHub issue.

Basic signal processing for EEG data

Once data is imported then standard preprocessing procedures can be applied. For example to rereference the data to the Cz channel call:

s = rereference(s, "Cz")
EEG measurement of 5.0 mins with 7 channels sampled at 8192.0 Hz

After which the Cz channel will not contain meaningful information any longer. So you may wish to remove it from further analysis. You can remove multiple channels by providing an array of channel names by calling:

remove_channel!(s, ["Cz", "TP7"])
s
EEG measurement of 5.0 mins with 5 channels sampled at 8192.0 Hz

And the resulting data structure will now have less channels as the output describes.

Visualise continuous EEG data

It is also useful to visualise the EEG data. You can view a single channel or subset of channels by passing the string or strings you wish to plot.

plot(s, "F6")

Or you can plot all channels by calling plot with no arguments.

plot(s)

Extract underlying data for custom analysis

You may wish to run your own analysis on the underlying raw data array. To access the raw data call:

data(s)
2621440×5 Matrix{Float32}:
 -3824.5   27151.1  13743.7  7320.19  22253.4
 -3823.03  27151.9  13746.7  7321.66  22252.7
 -3822.38  27152.1  13746.8  7323.28  22252.1
 -3822.81  27149.8  13747.8  7322.72  22252.9
 -3824.28  27148.5  13748.9  7321.91  22253.5
 -3820.72  27150.3  13751.6  7324.84  22252.3
 -3821.72  27149.8  13750.7  7323.5   22251.9
 -3823.56  27146.8  13747.9  7321.81  22246.8
 -3822.59  27149.8  13748.3  7321.22  22246.1
 -3823.28  27153.8  13749.4  7320.59  22251.1
     ⋮                                
 -3585.47  27258.9  14071.9  7578.09  22299.2
 -3586.56  27256.2  14071.5  7577.59  22296.1
 -3587.38  27253.7  14072.5  7576.59  22295.0
 -3584.69  27254.4  14072.6  7578.0   22298.4
 -3584.0   27253.3  14069.1  7577.53  22296.9
 -3583.09  27254.5  14069.6  7577.88  22298.5
 -3580.88  27255.1  14071.2  7578.34  22296.7
 -3581.56  27252.0  14070.8  7576.03  22295.5
 -3581.0   27251.0  14073.4  7576.72  22298.9

Or to access a subset of channels call:

data(s, ["F6", "F5"])
2621440×2 Matrix{Float32}:
 13743.7  -3824.5
 13746.7  -3823.03
 13746.8  -3822.38
 13747.8  -3822.81
 13748.9  -3824.28
 13751.6  -3820.72
 13750.7  -3821.72
 13747.9  -3823.56
 13748.3  -3822.59
 13749.4  -3823.28
     ⋮    
 14071.9  -3585.47
 14071.5  -3586.56
 14072.5  -3587.38
 14072.6  -3584.69
 14069.1  -3584.0
 14069.6  -3583.09
 14071.2  -3580.88
 14070.8  -3581.56
 14073.4  -3581.0

Conclusion

A demonstration of how to read in EEG data was provided. A brief explanation of how to query the returned data type was discussed. Basic signal processing and plotting was demonstrated.