Signal processing#
These functions work on plain numpy arrays and do not keep any
state. They are in the submodule pp.signal (e.g.,
pp.signal.smooth_window). The methods of the data classes call them with the right arguments,
so you usually do not need them directly, but they are useful for your
own processing steps or for data that are not in a data object.
Filtering and baseline#
Get lowpass-filter coefficients for Butterworth-filter. |
|
Lowpass-filter signal using a Butterworth-filter. |
|
Lowpass filter that handles NaN values via iterative interpolation. |
|
Smooth the data using a window with requested size. |
|
Simple downsampling scheme using mean within the downsampling window. |
|
Z-transform an array, ignoring NaNs. |
|
Re-implementation from https://mc-stan.org/users/documentation/case-studies/splines_in_stan.html. |
|
Extract baseline based on the lower envelope of the (filtered) signal. |
|
Extract baseline based on (re-)estimating the lower envelope using B-splines. |
|
Extract baseline based on filtering after removing stim-locked activity. |
Blinks#
Compute velocity (first derivative) using Savitzky-Golay filter. |
|
Blinks in the pupil signal sy: runs of missing samples (NaN) whose flanks look like a blink (for dips without missing samples, see |
|
Partial blinks in the pupil signal sy: a fast fall followed by a fast rise without missing samples between them (the lid covers part of the pupil, but the tracker does not lose it). |
|
Transients in the pupil signal sy: fast changes that are artifacts. |
|
The flanks of dropouts that change faster than the pupil can manage, tested over many scales (see |
|
The flank of a dropout as a change faster than the pupil can manage, tested over many scales. |
|
Islands: short stretches of usable data between unusable ones. |
|
Comb artifacts: short drops of the signal that come back up within a few samples (the teeth of a comb). |
|
The local level of a signal: a robust, multi-scale moving median. |
|
The run of fast change that touches a gap: a flank of a blink (the closing before the gap, the reopening after it) or of another transient. |
|
Method for finding the on- and offset for each blink (including the transient). |
|
Interpolate blinks with the method by Mahot (2013). |
|
Interpolate blinks with a Gauss-Markov model (Kalman smoother). |
|
The stretches of the signal that are replaced for the blinks: the core of each blink (from its first to its last missing sample, as in |
Transplantation of blinks#
Real blinks are cut out and added to clean stretches of a signal, where the signal without the blink is known, e.g. to evaluate or tune the interpolation of blinks or in simulations.
Transplant the blinks of a signal into its clean stretches. |
|
Error of a reconstruction of transplanted blinks. |
|
Cores of the blinks: the runs of missing samples. |
|
Select the blinks that can be transplanted. |
|
Cut the artifacts of blinks out of a signal. |
|
The typical artifact of the blinks and how reliable the single ones are. |
|
Remove the fluctuations of the signal from the artifacts of blinks. |
|
Stretches of clean signal: no missing samples and far from any. |
|
Choose random, non-overlapping places for artifacts in clean stretches. |
|
Put artifacts of blinks into a signal. |
A signal with transplanted blinks (see |
The parameters of the interpolation of blinks can be tuned on
transplanted blinks (see
d.pupil.blinks_optimize_parameters()).
Tune the parameters of the Mahot interpolation on transplanted blinks. |
|
Error of the Mahot interpolation of transplanted blinks. |
|
Tune the margins of the Kalman interpolation on transplanted blinks. |
|
Error of the Kalman interpolation of transplanted blinks. |
|
Tune the margin after each blink (e.g., against slow openings of the lid) on transplanted blinks. |
Result of tuning the parameters of the interpolation of blinks. |
|
Margins after the blinks, tuned on transplanted blinks (see |
Pupil response#
According to Hoeks and Levelt (1993, https://link.springer.com/content/pdf/10.3758%2FBF03204445.pdf), the PRF can be described by the so-called Erlang gamma function $$h_{HL}(t) = t^n e^{-nt/t_{max}}$$ which we normalize to $$h(t)=frac{1}{h_{max}} h_{HL}(t)$$ where $$h_{max} = max_t{left(h_{HL}(t)right)} = e^{-n}t_{max}^{n}$$ which yields a maximum value of 1 for this function. |
|
According to Hoeks and Levelt (1993, https://link.springer.com/content/pdf/10.3758%2FBF03204445.pdf), the PRF can be described by the so-called Erlang gamma function $$h_{HL}(t) = t^n e^{-nt/t_{max}}$$ which we normalize to $$h(t)=frac{1}{h_{max}} h_{HL}(t)$$ where $$h_{max} = max_t{left(h_{HL}(t)right)} = e^{-n}t_{max}^{n}$$ which yields a maximum value of 1 for this function. |
|
Get the time when the PRF with parameters $n$ and $t_{max}$ is decayed to thr. |
|
Plot profile of the pupil-response function (PRF) with parameters npar and tmax. |
|
Construct design matrix (nevents x n). |
|
Estimate pupil-response based on event-onsets. |
|
Share of each event's response that falls on valid samples. |
|
Estimate single-event pupil responses based on canonical PRF (pupil_kernel()) using non-negative least-squares (NNLS). |
|
Compute local signal quality metric for pupil signal. |
|
Compute a slowly-varying offset between left and right pupil signals. |