downsample: Downsample pupil time series with anti-aliasing filtering

View source: R/pipeline-downsample.R

downsampleR Documentation

Downsample pupil time series with anti-aliasing filtering

Description

This function downsamples pupillometry data by applying an anti-aliasing filter before decimation. Unlike binning, downsampling preserves the original temporal dynamics without averaging within bins.

Usage

downsample(
  eyeris,
  target_fs,
  plot_freqz = FALSE,
  rp = 1,
  rs = 35,
  call_info = NULL
)

Arguments

eyeris

An object of class eyeris derived from load_asc().

target_fs

The target sampling frequency in Hz after downsampling.

plot_freqz

Boolean flag for displaying filter frequency response (default FALSE).

rp

Passband ripple in dB (default 1).

rs

Stopband attenuation in dB (default 35).

call_info

A list of call information and parameters. If not provided, it will be generated from the function call.

Details

Downsampling reduces the sampling frequency by decimating data points. The function automatically designs an anti-aliasing filter using the lpfilt() function with carefully chosen parameters:

  • ws (stopband frequency) = Fs_new / 2 (Nyquist freq of new sampling rate)

  • wp (passband frequency) = ws - max(5, Fs_nq * 0.2)

  • An error is raised if wp < 4 to prevent loss of pupillary responses

The resulting time points will be: 0, 1/X, 2/X, 3/X, ..., etc. where X is the new sampling frequency.

Value

An eyeris object with downsampled data and updated sampling rate.

Note

This function is part of the glassbox() preprocessing pipeline and is not intended for direct use in most cases. Provide parameters via downsample = list(...).

Advanced users may call it directly if needed.

See Also

glassbox() for the recommended way to run this step as part of the full eyeris glassbox preprocessing pipeline. bin() for binning functionality.

Examples

demo_data <- eyelink_asc_demo_dataset()

# downsample pupil data recorded at 1000 Hz to 100 Hz with the default params
demo_data |>
  eyeris::glassbox(downsample = list(target_fs = 100)) |>
  plot(seed = 0)


eyeris documentation built on July 3, 2025, 9:08 a.m.