usingNeuroAnalyzerimportCairoMakie# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of# NeuroAnalyzer figures: remove itdelete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)usingDataFrames
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:
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:
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")