NeuroAnalyzer tutorials: MEPs

using NeuroAnalyzer

Motor evoked potentials (MEPs) are the electrical signals recorded from the descending motor pathways or from muscles following stimulation of motor pathways within the brain (source: Encyclopedia of the Neurological Sciences).

MEPs are used in Transcranial Magnetic Stimulation (TMS) for determining the intensity of stimulation.

NeuroAnalyzer allows analysis of MEP recordings. Usually recording contains more than one MEP. Each MEP is imported as individual channel of the NeuroAnalyzer.NEURO object.

Load MEP recording exported from DuoMAG stimulator:

mep = import_duomag("mep-duomag.m")

or

mep = import_duomag("files/mep-duomag.ascii")
m[ Info: Imported: MEP (19 × 8129 × 1; 0.51 s)
NeuroAnalyzer.NEURO(NeuroAnalyzer.HEADER(Dict{Symbol, Any}(:weight => -1, :id => "000011", :middle_name => "", :height => -1, :head_circumference => -1, :handedness => "", :last_name => "5-1", :first_name => ""), Dict{Symbol, Any}(:stimulation_sample => [1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754, 1754], :channel_type => ["mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep", "mep"], :label => ["MEP1", "MEP2", "MEP3", "MEP4", "MEP5", "MEP6", "MEP7", "MEP8", "MEP9", "MEP10", "MEP11", "MEP12", "MEP13", "MEP14", "MEP15", "MEP16", "MEP17", "MEP18", "MEP19"], :coil_type => ["----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----", "----"], :data_type => "mep", :recording_notes => "", :markers_pos => [2108, 2126, 2150, 2166, 2168, 2156, 0, 2151, 2094, 2150, 2113, 2158, 0, 0, 0, 0, 0, 2124, 0], :recording_date => "21.11.2019", :sampling_rate => 12500, :file_type => "DuoMAG"…), Dict(:name => "", :design => "", :notes => "")), [-0.1402, -0.1402, -0.1401, -0.14, -0.1399, -0.1398, -0.1398, -0.1397, -0.1396, -0.1395  …  0.5093, 0.5094, 0.5094, 0.5095, 0.5096, 0.5097, 0.5098, 0.5098, 0.5099, 0.51], [-0.1402, -0.1402, -0.1401, -0.14, -0.1399, -0.1398, -0.1398, -0.1397, -0.1396, -0.1395  …  0.5093, 0.5094, 0.5094, 0.5095, 0.5096, 0.5097, 0.5098, 0.5098, 0.5099, 0.51], [-1.3082855504587165 0.6917144495412835 … 2.6917144495412835 3.6917144495412835; -2.2894495412844016 -2.2894495412844016 … -0.2894495412844016 0.7105504587155984; … ; -0.8612672018348633 0.13873279816513673 … -6.861267201834863 -5.861267201834863; -2.539850917431192 0.46014908256880815 … 52.460149082568805 51.460149082568805;;;], Dict{Any, Any}(), 0×5 DataFrame
 Row │ id      start    length   value   channel 
     │ String  Float64  Float64  String  Int64   
─────┴───────────────────────────────────────────, 0×9 DataFrame
 Row │ label   loc_radius  loc_theta  loc_x    loc_y    loc_z    loc_radius_sp ⋯
     │ String  Float64     Float64    Float64  Float64  Float64  Float64       ⋯
─────┴──────────────────────────────────────────────────────────────────────────
                                                               3 columns omitted, String[])

Show recording details:

info(mep)
              Data type: MEP
            File format: DuoMAG
            Source file: files/mep-duomag.ascii
         File size [MB]: 0
       Memory size [MB]: 1.25
                Subject: 000011:  5-1
              Recording: 
        Recording notes: 
         Recording date: 21.11.2019
         Recording time: 14:28:51
     Sampling rate (Hz): 12500
Signal length [samples]: 8129
Signal length [seconds]: 0.65
     Number of channels: 19
             Components: no

Channels:
 ch     label           type        unit    bad     
 ------ --------------- ----------- ------- -------
 1      MEP1            MEP         μV      false   
 2      MEP2            MEP         μV      false   
 3      MEP3            MEP         μV      false   
 4      MEP4            MEP         μV      false   
 5      MEP5            MEP         μV      false   
 6      MEP6            MEP         μV      false   
 7      MEP7            MEP         μV      false   
 8      MEP8            MEP         μV      false   
 9      MEP9            MEP         μV      false   
 10     MEP10           MEP         μV      false   
 11     MEP11           MEP         μV      false   
 12     MEP12           MEP         μV      false   
 13     MEP13           MEP         μV      false   
 14     MEP14           MEP         μV      false   
 15     MEP15           MEP         μV      false   
 16     MEP16           MEP         μV      false   
 17     MEP17           MEP         μV      false   
 18     MEP18           MEP         μV      false   
 19     MEP19           MEP         μV      false   

Detect peaks:

mep_peaks(mep)
19×2 Matrix{Int64}:
 2110  2076
 2128  2086
 2149  2077
 2168  2072
 2170  2073
 2159  2082
 6562  2129
 2154  2073
 2096  2232
 2152  2090
 2115  2202
 2160  2087
 5658  2385
 2745  7601
 7548  2092
 2075  2112
 3099  2119
 2125  2094
 7699  2844

(!) The output matrix contains the position (in samples) of the positive (first column) and negative (second column) peaks.

Plot MEP, channel 1:

plot_mep(mep, ch="MEP1")
m[ Info: Positive peak time: 28.0 ms
[ Info: Positive peak amplitude: 65.69 μV
[ Info: Negative peak time: 26.0 ms
[ Info: Negative peak amplitude: -95.31 μV

(!) These peaks are auto-detected. Files exported from DuoMAG contain peaks detected by the stimulator. To use embedded peaks, use:

plot_mep(mep, ch="MEP1", peaks_detect=false)
[ Info: Positive peak time: 28.0 ms
[ Info: Positive peak amplitude: 65.69 μV
[ Info: Negative peak time: 26.0 ms
[ Info: Negative peak amplitude: -96.31 μV

Butterfly plot over MEPs:

plot_mep(mep, ch="all", type=:butterfly, avg=true)
m[ Info: Positive peak time: 32.0 ms
[ Info: Positive peak amplitude: 63.15 μV
[ Info: Negative peak time: 26.0 ms
[ Info: Negative peak amplitude: -96.06 μV