R/RcppExports.R

Defines functions downsample_digital_timeseries

Documented in downsample_digital_timeseries

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' This function downsamples a vector of integers by keeping the mode within each resampled chunk.
#'
#' @description When downsampling integers, it is difficult to decide on what value should be retained
#' since simpler subsampling approaches may retain a digital value that is not representative of the local
#' neighborhood of the vector. This is less of a problem for downsampling of analog channels where we assume
#' relative continuity across values.
#'
#' Here, we have adopted the approach of downsampling integers by retaining the most common intger value within
#' each subset of the vector. For example, if the vector is of length 100 and we are downsampling 10x, then
#' the function will look within each set of 10 integers and retain the most common value in each.
#'
#' @name downsample_digital_timeseries
#' @param x A vector of integer values to be downsampled by retaining the mode in each chunk
#' @param downsamp The factor by which data are downsampled (e.g., 3 will reduce the resulting vector 3x)
#' @param demote_zeros Logical indicating whether to prefer non-zero modes, even if they are no more likely in a chunk
#' @return A vector of length \code{ceiling(length(x)/downsamp)} with downsampled integers
#'
#' @details Note that this function does not allow for multiple modes. If there are multiple modes, it  always
#'   retains the mode with the lowest integer value in each chunk. The exception is if \code{demote_zeros} is \code{TRUE}.
#'   In this case, even if there is one non-zero value in a chunk, it will trump any number of zeros. This is helpful for
#'   TTL codes where a code may be on for part of the higher-frequency time series and we don't want it to become zero
#'   in the downsampled data.
#' @author Michael Hallquist
#' @export
NULL

downsample_digital_timeseries <- function(x, downsamp, demote_zeros = TRUE) {
    .Call(`_experiment_pipeline_downsample_digital_timeseries`, x, downsamp, demote_zeros)
}
PennStateDEPENdLab/experiment_pipeline documentation built on Nov. 27, 2024, 4:56 a.m.