Motor Evoked Potentials

Initialize NeuroAnalyzer
using NeuroAnalyzer
import CairoMakie
# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of
# NeuroAnalyzer figures: remove it
delete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)
using DataFrames

Motor evoked potentials (MEPs) are the electrical responses of a muscle, recorded with surface EMG electrodes, to stimulation of the motor cortex. In transcranial magnetic stimulation (TMS), a magnetic coil placed over the motor cortex delivers a brief magnetic pulse, which induces an electric current in the cortex; it activates the corticospinal neurons and produces a measurable MEP in the target muscle (e.g. the first dorsal interosseous or the abductor pollicis brevis for the hand area).

Measures:

  • latency: the time from the stimulus to the onset of the MEP (about 20–25 ms for hand muscles); prolonged in demyelination of the corticospinal tract
  • amplitude: the peak-to-peak amplitude, reflecting the excitability of the corticospinal pathway; it varies considerably from pulse to pulse, so several MEPs are averaged
  • motor threshold: the lowest stimulation intensity that evokes MEPs of ≥ 50 μV in at least half of the trials (resting motor threshold); used to set the intensity of TMS protocols

Applications:

  • Diagnostics: assessment of the integrity of the corticospinal tract, e.g. in multiple sclerosis, stroke, amyotrophic lateral sclerosis and spinal cord injury; intraoperative monitoring.
  • Research: motor physiology, cortical excitability and plasticity (e.g. paired-pulse protocols, effects of rTMS, drugs).

Importing MEPs

MEPs exported from the DuoMAG stimulator as MATLAB (.m) or ASCII (.ascii) files are imported using import_duomag(). Each MEP is stored as a separate channel of the NEURO object; the signals are baseline-corrected, the stimulation artifact is suppressed, and the amplitudes are scaled to μV:

mep = import_duomag("files/mep/mep-duomag.ascii")

or

mep = import_duomag("files/mep/mep-duomag.m")
info(mep)
              Data type: MEP
            File format: DuoMAG
            Source file: files/mep/mep-duomag.ascii
         File size [MB]: 0.93
       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.6503
     Number of channels: 19

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   

The time axis starts before the stimulus; the stimulus is at 0 s.

Visualization

A single MEP; by default its peaks are detected automatically (peaks = :detect):

plot_mep(mep; ch = "MEP1")

Files exported from DuoMAG contain peaks detected by the stimulator; to show them, use peaks = :embed (peaks = :off hides the peaks):

plot_mep(mep;
         ch = "MEP1",
         peaks = :embed)

All MEPs (butterfly plot) with their average; leg = false hides the list of channels:

plot_mep(mep;
         ch = "all",
         leg = false)

Mean and 95% confidence interval:

plot_mep(mep;
         ch = "all",
         avg = false,
         ci95 = true,
         peaks = :off)

All MEPs stacked (each row is one MEP, the amplitude is coded by color):

plot_mep(mep;
         ch = "all",
         type = :stack)

The amplitude varies considerably between pulses: MEP3 and MEP8 are the largest, while several MEPs (e.g. MEP13 and MEP14) are hardly visible.

Latency and Amplitude

mep_peaks() detects the positive and negative peaks of each MEP (searching from 20 samples after the stimulus); it returns their positions in samples (channels × 2: positive peak, negative peak). The latencies are obtained from the time axis:

p = mep_peaks(mep)
lat = mep.epoch_time[p] .* 1000
first(DataFrame(mep = labels(mep),
                positive_ms = lat[:, 1],
                negative_ms = lat[:, 2]), 5)
5×3 DataFrame
Row mep positive_ms negative_ms
String Float64 Float64
1 MEP1 28.32 25.6
2 MEP2 29.76 26.4
3 MEP3 31.44 25.68
4 MEP4 32.96 25.28
5 MEP5 33.12 25.36

Tip: the peaks are searched over the whole signal after the stimulus; for MEPs that are absent or very small, the maximum may be a late fluctuation rather than a response, so the detected peaks should be checked visually (or the amplitude measured within a time window, see below).

The amplitude of each MEP at a time point (in seconds):

amp_at(mep; t = 0.025)

The mean, minimum and maximum amplitude within a time window:

avgamp_at(mep; t = (0.015, 0.05))
minamp_at(mep; t = (0.015, 0.05))
maxamp_at(mep; t = (0.015, 0.05))

The peak-to-peak amplitude within the response window (15–50 ms) is the difference between the maximum and the minimum; MEPs ≥ 50 μV are counted as responses (e.g. when determining the motor threshold):

w = (0.015, 0.05)
pp = vec(maxamp_at(mep; t = w) .- minamp_at(mep; t = w))
println("Peak-to-peak amplitude [μV]: ", round.(Int, pp))
println("MEPs ≥ 50 μV: ", count(>=(50), pp), " of ", length(pp))
println("Mean amplitude: ", round(sum(pp) / length(pp); digits = 1), " μV")
Peak-to-peak amplitude [μV]: [165, 257, 841, 175, 128, 274, 26, 821, 100, 190, 99, 408, 9, 9, 28, 24, 19, 113, 14]
MEPs ≥ 50 μV: 12 of 19
Mean amplitude: 194.7 μV