usingNeuroAnalyzerusingStatisticsNeuroAnalyzer.progress_bar =falseeeg =import_edf("files/eeg/eeg.edf")# filtered 0.5-35 Hz (removes the DC offsets and the line noise of the raw# recording)NeuroAnalyzer.filter!(eeg; ch ="all", fprototype =:butterworth, ftype =:hp, cutoff =0.5, order =4)NeuroAnalyzer.filter!(eeg; ch ="all", fprototype =:fir, ftype =:lp, cutoff =35, bw =10)# 10-second epochse10 =epoch(eeg; ep_len =10)
apply() evaluates a Julia expression for each selected channel and each epoch. It is a quick way to compute per-channel, per-epoch measures (statistics, amplitudes, custom features) or to transform the signals with any Julia function, without writing loops.
How apply() Works
The formula is a string in which obj stands for the signal of one channel in one epoch (a vector of samples):
r =apply(e10; ch = ["Fp1", "Fp2", "O1"], f ="std(obj)")println("size: ", size(r))
size: (3, 1, 120)
The formula is compiled once and evaluated for every channel and epoch (in parallel); the result is an array of size channels × (length of the result) × epochs:
a single number per channel and epoch (e.g. mean(obj), std(obj)) gives channels × 1 × epochs,
a vector (e.g. obj .^ 2) gives channels × (vector length) × epochs; its length must be the same for all channels and epochs.
The result must be real; complex results (e.g. fft(obj)) must be converted, e.g. with abs.(). Any function available in Julia and in the packages used by NeuroAnalyzer (e.g. Statistics, FFTW) can be used.
The peak-to-peak amplitude of each channel and epoch, and the epochs in which it exceeds 150 μV in any channel (e.g. because of eye blinks or movements):
A transformed signal of the same length can be written back into a copy of the object (or added as a new channel with add_channel!()):
e10_z =deepcopy(e10)eeg_ch =get_channel(e10_z; ch ="eeg")e10_z.data[eeg_ch, :, :] = z
Tip: NeuroAnalyzer has dedicated functions for many of these operations (e.g. normalize(), remove_dc(), amp(), rms(), psd()), which are faster and record the operation in the processing history; apply() is meant for measures and transformations not available otherwise.