R/estimate_sample_rate.R

Defines functions .estimate_sample_rate

# This is a utility function for estimating the sample_rate in Hz based off the timestamps given.


.estimate_sample_rate <- function(data) {

  # estimate sample rate

    trial <- split(data, data$trial)
    sample_rates <- sapply(trial, function(data) {

      # estimate sample rate (ms) from difference between timestamps
      time <- data$time - data$time[1] # start trial timestamps at 0
      sample_rate <- mean(diff(time)) #difference between timestamps, expressing ms per sample
      sample_rate

    })
    #average sample rate across all trials
    sample_rate <- 1000/mean(sample_rates)
    sample_rate
  }

Try the eyetools package in your browser

Any scripts or data that you put into this service are public.

eyetools documentation built on June 18, 2025, 5:08 p.m.