Signal Processing Functions#
This section documents the signal processing functions for spectral analysis, resampling, and baseline removal.
Spectral Analysis#
- eegprep.eeg_autocorr(EEG, pct_data=None)
Compute autocorrelation of ICA components.
Parameters#
- EEGdict
EEG data structure with icaact
- pct_datafloat, optional
Percentage of data to use (default 100)
Returns#
- acndarray
Autocorrelation array
- eegprep.eeg_autocorr_welch(EEG, pct_data=100)
Compute autocorrelation of EEG ICA components using Welch method.
Parameters#
- EEGdict
EEG data structure with ‘icaweights’, ‘icaact’, ‘pnts’, ‘srate’ fields.
- pct_datafloat, optional
Percentage of data to use. Default 100.
Returns#
- ndarray
Autocorrelation array.
- eegprep.eeg_rpsd(EEG, nfreqs=None, pct_data=100)
Compute relative power spectral density for ICA components.
Parameters#
- EEGdict
EEG data structure with ICA activations.
- nfreqsint, optional
Number of frequency bins. Default is Nyquist frequency.
- pct_datafloat, optional
Percentage of data to use. Default is 100.
Returns#
- ndarray
Power spectral density in dB for each component.
Time-Frequency And Statistics#
- eegprep.newtimef(data, frames, tlimits, srate, cycles=0, *, winsize=None, freqs=None, freqrange=None, nfreqs=None, freqscale=None, timesout=None, padratio=None, overlap=None, baseline=0, scale='log', basenorm='off', trialbase='off', powbase=None, alpha=None, pboot=None, rboot=None, erspboot=None, itcboot=None, naccu=200, boottype='shuffle', baseboot=1, mcorrect='none', itctype='phasecoher', type=None, subitc='off', plottype='image', plot='on', plotersp='on', plotitc='on', plotphase='off', title='Time-frequency', rng=None, detrend='off', causal='off', wletmethod='dftfilt3', timewarp=None, timewarpms=None, timewarpidx=None, vert=None, verbose='off')
Compute an EEGLAB-like ERSP/ITC time-frequency decomposition.
- Parameters:
data (Any)
frames (int)
tlimits (Any)
srate (float)
cycles (Any)
winsize (Any)
freqs (Any)
freqrange (Any)
nfreqs (Any)
freqscale (Any)
timesout (Any)
padratio (Any)
overlap (Any)
baseline (Any)
scale (str)
basenorm (str)
trialbase (str)
powbase (Any)
alpha (Any)
pboot (Any)
rboot (Any)
erspboot (Any)
itcboot (Any)
naccu (int)
boottype (str)
baseboot (Any)
mcorrect (str)
itctype (str)
type (str | None)
subitc (str)
plottype (str)
plot (Any)
plotersp (Any)
plotitc (Any)
plotphase (Any)
title (str)
rng (Any)
detrend (str)
causal (str)
wletmethod (str)
timewarp (Any)
timewarpms (Any)
timewarpidx (Any)
vert (Any)
verbose (str)
- Return type:
TimeFrequencyResult
- eegprep.newcrossf(x, y, frames, tlimits, srate, cycles=0, **kwargs)
Compute an EEGLAB-like event-related coherence decomposition.
- eegprep.timefreq(data, srate, *, frames=None, cycles=0, wavelet=0, winsize=None, tlimits=None, detrend='off', causal='off', freqs=None, nfreqs=None, freqscale='linear', ffttaper='hanning', padratio=2, itctype='phasecoher', subitc='off', timesout=None, ntimesout=None, timestretch=None, wletmethod='dftfilt3', verbose='off')
Return EEGLAB-like spectral estimates for each trial.
Args mirror EEGLAB’s
timefreqwhere practical. The optionalframeskeyword is an EEGPrep convenience for reshaping flat trial-concatenated input before applying the EEGLAB algorithm.- Parameters:
data (Any)
srate (float)
frames (int | None)
cycles (Any)
wavelet (Any)
winsize (int | None)
tlimits (Any)
detrend (str)
causal (str)
freqs (Any)
nfreqs (Any)
freqscale (str)
ffttaper (str)
padratio (int)
itctype (str)
subitc (str)
timesout (Any)
ntimesout (Any)
timestretch (Any)
wletmethod (str)
verbose (str)
- Return type:
TimeFrequencyDecomposition
- eegprep.timef(data, frames, tlimits, srate, cycles=0, **kwargs)
Compute legacy
timefoutputs using EEGPrep’snewtimefcore.
- eegprep.crossf(x, y, frames, tlimits, srate, cycles=0, **kwargs)
Compute legacy
crossfoutputs using EEGPrep’snewcrossfcore.
- eegprep.pac(X, Y, srate, **kwargs)
Compute phase-amplitude coupling from epoched signals.
The output mirrors EEGLAB’s compute-only helper with named fields for the PAC matrix, output times, amplitude frequencies, phase frequencies, and single-trial spectral decompositions.
- eegprep.pac_cont(X, Y, srate, **kwargs)
Compute sliding-window phase-amplitude coupling from continuous data.
- eegprep.dftfilt(length, maxfreq, cycle, oversmp, wavfact)
Return legacy discrete Fourier filters.
- eegprep.dftfilt2(freqs, cycles, srate, cycleinc='linear', kind='morlet')
Return EEGLAB
dftfilt2wavelet filters.
- eegprep.dftfilt3(freqs, cycles, srate, *, cycleinc='linear', winsize=None, timesupport=7.0)
Return EEGLAB
dftfilt3-style complex wavelet filters.- Parameters:
freqs (Any) – Frequencies of interest in Hz.
cycles (Any) – Scalar, two-value, or per-frequency cycle specification.
srate (float) – Sampling rate in Hz.
cycleinc (str) –
"linear"or"log"interpolation for two cycle values.winsize (int | None) – Optional fixed filter length. When omitted, Morlet filters use EEGLAB’s seven-standard-deviation support and variable lengths.
timesupport (float) – Number of temporal standard deviations included.
- Returns:
(wavelets, cycles, freqresol, timeresol).- Return type:
- eegprep.timewarp(ev_latency, new_latency)
Return the linear interpolation matrix that warps event latencies.
ev_latencyandnew_latencyuse EEGLAB’s 1-based frame indexing. Multiplying the returned matrix by a column time series maps samples so the original event frames align with the requested event frames.
- eegprep.angtimewarp(ev_latency, new_latency, angdata)
Warp an angular time series and wrap results to
(-pi, pi].
- eegprep.tf_cycle_calc(freqs=None, width=None, width_unit=None, *, log_spaced=False, plot=False, data=None, fs=None, norm=False)
Calculate Morlet wavelet cycles from temporal or spectral width.
- eegprep.newtimefbaseln(power, timesout, *, baseline=0, powbase=None, basenorm='off', commonbase='off', singletrials='on', trialbase='off')
Apply EEGLAB average baseline correction to absolute power.
- Parameters:
power (Any) – Power array, usually
freqs x times x trials.timesout (Any) – Time values in milliseconds.
baseline (Any) – Scalar threshold,
[min, max]interval, or NaN to disable.powbase (Any) – Optional externally supplied baseline spectrum.
basenorm (str) –
"on"for z-like baseline normalization.commonbase (str) – Average baseline spectra across a list of power arrays.
singletrials (str) – Whether trials remain present on the last axis.
trialbase (str) – Trial baseline mode from
newtimef.
- Returns:
(corrected_power, baseline_indices, baseline_values).- Return type:
- eegprep.newtimeftrialbaseln(power, timesout, *, baseline=0, basenorm='off', trialbase='off')
Apply trial-level divisive or standardized baseline correction.
- eegprep.newtimefitc(tfdecomp, itctype='phasecoher')
Compute EEGLAB-style inter-trial coherence.
- eegprep.newtimefpowerunit(params=None)
Return the display unit implied by
newtimefbaseline settings.
- eegprep.bootstat(args, statistic, *, alpha=0.05, naccu=200, bootside='both', boottype='shuffle', basevect=None, shuffledim=None, rng=None)
Accumulate surrogate statistics and return EEGLAB-style thresholds.
This Python helper intentionally accepts a callable statistic instead of MATLAB expression strings. It covers the time-frequency bootstrap paths used by EEGPrep while avoiding runtime string evaluation.
- eegprep.correct_mc(EEG, cycles=(3, 0.5), freqrange=(2, 50), timesout=(5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40))
Estimate an EEGLAB-style multiple-comparison correction count.
EEGLAB fits a Ramberg-Schmeiser distribution to neighboring-bin correlations. EEGPrep uses the same standalone fitted p-value path without depending on the vendored EEGLAB checkout at runtime.
- eegprep.correctfit(pvalue, *, allpval=None, gamparams=None, zeromode='on')
Return a gamma-fit corrected p-value and fitted parameters.
- eegprep.rsadjust(lambda3, lambda4, mean, variance, skewness)
Return
lambda1throughlambda4adjusted to mean and variance.
- eegprep.rsfit(x, value, plot=0, *, return_details=False)
Return a Ramberg-Schmeiser fitted p-value for
valuewithinx.
- eegprep.rsget(lambdas, value)
Return the fitted Ramberg-Schmeiser cumulative probability at
value.
- eegprep.rspdfsolv(lambdas, skewness, kurtosis)
Return the Ramberg-Schmeiser moment residual for
lambda3/lambda4.
- eegprep.rspfunc(pvalue, lambdas, value)
Return the absolute quantile residual for one probability value.
- eegprep.signalstat(data, plotlab=1, dlabel=None, percent=5, dlabel2='', map=None, chan_locs=None)
Compute EEGLAB-style summary statistics for a real-valued signal.
- eegprep.pop_newtimef(EEG=None, typeproc=1, num=None, tlimits=None, cycles=None, *args, gui=None, renderer=None, return_com=False, **kwargs)
Plot a channel or component ERSP/ITC decomposition.
- eegprep.pop_newcrossf(EEG=None, typeproc=1, num1=None, num2=None, tlimits=None, cycles=None, *args, gui=None, renderer=None, return_com=False, **kwargs)
Plot event-related channel/component cross-coherence.
- eegprep.pop_timef(EEG=None, typeproc=1, num=None, tlimits=None, cycles=None, *args, gui=None, renderer=None, return_com=False, **kwargs)
Run legacy
pop_timefthrough EEGPrep’spop_newtimefimplementation.
- eegprep.pop_crossf(EEG=None, typeproc=1, num1=None, num2=None, tlimits=None, cycles=None, *args, gui=None, renderer=None, return_com=False, **kwargs)
Run legacy
pop_crossfthrough EEGPrep’spop_newcrossfimplementation.
- eegprep.pop_signalstat(EEG=None, typeproc=1, cnum=None, percent=5, *, gui=None, renderer=None, return_com=False)
Compute and plot statistics for one channel or component.
- eegprep.pop_eventstat(EEG=None, eventfield=None, type=None, latrange=None, percent=5, *, gui=None, renderer=None, return_com=False)
Compute and plot statistics for numeric EEG event fields.
Browser#
- eegprep.eegplot(data, *args, **kwargs)
Open an EEGLAB-style scrolling browser for channel-major EEG data.
Parameters use EEGLAB names where practical.
datamay be a NumPy-like array shapedchannels x samplesorchannels x samples x trials, or an EEG dictionary containingdata,srate,chanlocs, andeventfields. Spectral inputs usefreqswithfreqlimits; in that modewinlengthis interpreted as a frequency span in Hz. The input is copied into the browser model and is not mutated by the viewer.
- eegprep.eeg_multieegplot(data, rej=None, rejE=None, oldrej=None, oldrejE=None, *args, oldcolor=(0.8, 1.0, 0.8), newcolor=(0.8, 0.8, 1.0), show=True, **kwargs)
Open
eegplotwith current and previous rejection marks.rej/rejEandoldrej/oldrejEfollow EEGLAB’s convention: trial vectors are sweeps-length arrays of 0/1 marks and electrode marks arechannels x sweepsboolean arrays. For continuous data, rejection rows may be[start end]or EEGLAB event-like rows whose start/end are in columns 3 and 4.
Resampling#
- eegprep.pop_resample(EEG, freq=None, engine=None, *, gui=None, renderer=None, return_com=False, fc=None, df=None)
Resample EEG data to a new sampling rate.
Parameters#
- EEGdict
EEGLAB EEG structure.
- freqfloat
New sampling rate in Hz.
- enginestr or None
Engine to use for implementation. Options are: - None: Use the default Python implementation - ‘poly’: Use scipy’s resample_poly function - ‘matlab’: Use MATLAB engine - ‘octave’: Use Octave engine
Returns#
- EEGdict
EEGLAB EEG structure with resampled data.
Baseline Removal#
- eegprep.rmbase(data, frames=0, basevector=0, *, return_mean=False)
Subtract per-channel baseline means from continuous or epoched data.
- Parameters:
data (Any) – Data array shaped
(channels, frames * epochs)or(channels, frames, epochs).frames (int | None) – Samples per epoch.
0orNoneuses the full second dimension, matching EEGLAB’s default.basevector (Any) – EEGLAB-style 1-based baseline frame indices, or
0/ empty for the whole epoch.return_mean (bool) – When true, return
(dataout, datamean).
- Returns:
Baseline-corrected data, and optionally the channel-by-epoch means.
- eegprep.pop_rmbase(EEG=<object object>, timerange=None, pointrange=None, chanlist=None, *, gui=None, renderer=None, return_com=False)
Remove baseline means from an epoched or continuous EEG dataset.
timerangeuses the units stored inEEG["times"].pointrangeand numericchanlistvalues use EEGLAB-facing 1-based indices. Callingpop_rmbase(EEG)opens the GUI; pass explicit ranges orgui=Falsefor direct command-line use.
Topography#
- eegprep.cart2topo(x, *args)
Convert XYZ Cartesian coordinates to polar
topoplotcoordinates.This follows current EEGLAB
cart2topo.mbehavior: Cartesian coordinates are converted to MATLAB-style spherical coordinates, then totopoplotthetaandradiusviasph2topomethod 2.- Parameters:
- Returns:
(theta, radius, x, y, z)arrays.- Return type:
- eegprep.pop_topoplot(EEG=None, typeplot=1, items=None, topotitle=None, rowcols=None, plotdip=0, *args, gui=None, renderer=None, return_com=False, **kwargs)
Plot EEGLAB-style 2-D scalp maps for ERP latencies or ICA components.
- Parameters:
typeplot (int) –
1for channel ERP latency maps,0for component maps.items (Any) – Latencies in ms when
typeplot=1or 1-based component indices whentypeplot=0. Negative component indices invert map polarity andNaNleaves a blank subplot.topotitle (str | None) – Figure title.
rowcols (Any) – Optional
[rows, columns]layout. Empty uses EEGLAB’s near-square page geometry.plotdip (Any) – Accepted for EEGLAB signature compatibility; DIPFIT overlays are deferred to the Phase 4 headplot/DIPFIT integration.
gui (bool | None) – Force or suppress the EEGLAB-like input dialog.
renderer (Any | None) – Optional dialog renderer for tests.
return_com (bool) – Return
(figures, command)when true.**kwargs (Any) – Additional
topoplotoptions such aselectrodes,colorbarandmaplimits.args (Any)
- eegprep.topoplot(datavector, chan_locs, **kwargs)
Plot a 2D topographic map of EEG data.
Parameters#
- datavectorarray-like
Values to plot at each channel location.
- chan_locslist of dict
Channel location structures with ‘labels’, ‘theta’, and ‘radius’ fields.
- kwargsdict
Additional keyword arguments for customization:
noplot : str or tuple, default ‘off’
plotgrid : str, default ‘off’
plotchans : list, default []
ELECTRODES : str, default ‘on’
intrad : float, default nan
plotrad : float, default nan
headrad : float, default 0.5
method : str, default ‘rbf’
Returns#
- handlematplotlib.figure.Figure or None
Figure handle if plotted, None otherwise.