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. |
|
Detect blinks as everything between a fast downward and a fast upward-trending PD-changes. |
|
Detect blinks as consecutive sequence of blink_val (e.g., 0 or NaN) of at least min_duration successive values in the signal sy. |
|
Method for finding the on- and offset for each blink (excluding transient). |
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. |
Simulated data#
Generate smooth baseline pupil size via filtered noise. |
|
Generate step-function gaze positions (fixations with random locations and durations). |
|
Add Gaussian measurement noise to a signal. |
|
Generate complete synthetic dataset for testing foreshortening correction algorithm. |