ERP is created from epoched NeuroAnalyzer.NEURO
object
via erp()
command. ERP object has
OBJ.header.recording[:data_type]
set to “erp”. First epoch
of the OBJ is ERP, other epochs are the original data.
= import_recording("NEURO-testing-data/Brainvision/s1_faces.vhdr") eeg
Output:
[ Info: Imported: < EEG, 34 × 424488 × 1 (829.078125 s) >
Pre-process:
load_locs!(eeg, file_name="locs/standard-10-20-cap81.locs")
NeuroAnalyzer.filter!(eeg, fprototype=:butterworth, ftype=:hp, cutoff=1, order=8)
NeuroAnalyzer.filter!(eeg, fprototype=:iirnotch, cutoff=50, bw=2)
reference_avg!(eeg)
view_marker(eeg)
Output:
n ID start [s] length [s] description channel
1 'New Segment' 0.0 0.0 'marker' 0
2 'Marker' 0.0 0.0 'Impedance' 0
3 'Stimulus' 20.562 0.0 's111' 0
4 'Stimulus' 20.98 0.0 's130' 0
5 'Stimulus' 21.826 0.0 's71' 0
...
400 'Stimulus' 799.207 0.0 's130' 0
401 'Stimulus' 799.986 0.0 's71' 0
402 'Stimulus' 803.119 0.0 's130' 0
403 'Stimulus' 803.65 0.0 's71' 0
404 'Stimulus' 806.529 0.0 's121' 0
405 'Stimulus' 806.574 0.0 's122' 0
406 'Stimulus' 806.619 0.0 's102' 0
Epoch by marker “s71”:
eeg_epoched = epoch(eeg, marker="s71", offset=0.5, ep_len=2.5)
p = plot(eeg_epoched)
Create ERP, set baseline from -500 to 0 msec:
erp_s71 = erp(eeg_epoched, bl=(-0.5, 0))
p = plot_erp(erp_s71, ch=10)
plot_save(p, file_name="images/erp1.png")
(!) Baseline segment time points must be given in seconds.
By default, baseline is subtracted after averaging, to subtract baseline prior to averaging:
= average_epochs(eeg_epoched, bl=(-0.5, 0), blfirst=true) erp_s71
Output:
[ Info: Positive peak time: 143.0 ms
[ Info: Positive peak amplitude: 5.15 μV
[ Info: Negative peak time: 234.0 ms
[ Info: Negative peak amplitude: -8.82 μV
(!) To reverse the Y axis (so that negative values are at the top),
use the yrev=true
option:
= plot_erp(erp_s71, ch=10, yrev=true)
p plot_save(p, file_name="images/erp_rev.png")
To add the response time line to the plot:
= plot_erp(erp_s71, rt=0.18)
p plot_save(p, file_name="images/erp_rt.png")
Detect peaks:
erp_peaks(erp_s71)
(!) The output matrix contains the position (in samples) of the positive (first column) and negative (second column) peaks.
Butterfly plot over channels:
= plot_erp(erp_s71, ch=1:4, type=:butterfly, avg=true)
p plot_save(p, file_name="images/erp2.png")
Butterfly plot over epochs:
= plot_erp(erp_s71, ch=1, type=:butterfly, avg=true)
p plot_save(p, file_name="images/erp3.png")
Mean plot over channels:
= plot_erp(erp_s71, ch=1:30, type=:mean, peaks=false)
p plot_save(p, file_name="images/erp4.png")
Mean plot over epochs:
= plot_erp(erp_s71, ch=1, type=:mean, peaks=false)
p plot_save(p, file_name="images/erp5.png")
Topographical plot of ERPs:
= plot_erp(erp_s71, ch=1:30, type=:topo)
p plot_save(p, file_name="images/erp6.png")
Positive peak is at 143 ms, negative peak at 234 ms (see
plot_erp()
output). Draw markers and topoplots at these
time points:
= plot_erp(erp_s71, ch=signal_channels(erp_s71), type=:butterfly, labels=false, tm=[143, 234], title="", top_margin=10Plots.px, channel_labels=false)
p1 = plot_topo(erp_s71, ch=signal_channels(erp_s71), seg=(0.143, 0.144), cb=false, title="")
p2 = plot_topo(erp_s71, ch=signal_channels(erp_s71), seg=(0.234, 0.235), cb=false, title="")
p3 = resize_canvas(plot2canvas(p2), r=0.2)
c1 = resize_canvas(plot2canvas(p3), r=0.2)
c2 = add_topmargin_canvas(plot2canvas(p1), c1)
c = add_to_canvas(c, c1, x=230, y=0, title="143 ms", view=false)
c = add_to_canvas(c, c2, x=395, y=0, title="234 ms", view=false)
c iview_plot(c)
Plot stacked channels:
= plot_erp(erp_s71, ch=signal_channels(erp_s71), type=:stack)
p plot_save(p, file_name=file_name="images/erp8.png")
Plot stacked epochs:
= plot_erp(erp_s71, ch=10, type=:stack, tm=[143, 234])
p plot_save(p, file_name=file_name="images/erp9.png")
To plot stacked epochs and ERP:
= plot_erp(erp_s71, ch=1, type=:stack, cb=false, title="", xlabel="", xticks=false)
p1 = plot_erp(erp_s71, ch=1, title="")
p2 = Plots.plot(p1, p2, layout=@layout [a{0.8h}; b{0.2h}])
p plot_save(p, file_name=file_name="images/erp_stack.png")
To plot smoothed stacked epochs and ERP:
= plot_erp(erp_s71, ch=1, type=:stack, smooth=true, n=5)
p plot_save(p, file_name=file_name="images/erp_smooth.png")
To plot the response time line over the ERP stack plot:
= plot_erp(erp_s71, ch=1, type=:stack, rt=rt)
p plot_save(p, file_name=file_name="images/erp_rt1.png")
To plot the response time line over the ERP stack plot and sort epochs by RT values:
= plot_erp(erp_s71, ch=1, type=:stack, rt=rt, sort_epochs=true)
p plot_save(p, file_name=file_name="images/erp_rt2.png")
Calculate amplitude at given time point:
amp_at(erp_s71, t=0.250)
Calculate average, minimum and maximum amplitude over a time segment:
avgamp_at(erp_s71, t=(0.150, 0.250))
minamp_at(erp_s71, t=(0.150, 0.250))
maxamp_at(erp_s71, t=(0.150, 0.250))
Calculate non-phase-locked signal (signal - ERP):
= npl(erp_s71) erp_s71_npl
Calculate EROs (Event-Related Oscillations) spectrogram:
= eros(erp_s71, ch=10)
s, f, t = plot_eros(s, f, t, tm=[143, 234], frq_lim=(0, 40))
p plot_save(p, file_name=file_name="images/eros.png")
Calculate EROp (Event-Related Oscillations) power-spectrum:
= erop(erp_s71, ch=10)
p, f = plot_erop(p, f, frq_lim=(0, 40))
p plot_save(p, file_name=file_name="images/erop.png")