sensor_resample: Resample a sensor data stream

View source: R/read_gt3x_Interpolate2.R

interpolate_CR Documentation

Resample a sensor data stream

Description

This function was originally developed to correct sensor packets when sampled more or fewer times than expected over the time interval. However, this function may have more far-reaching applications.

Usage

interpolate_C(original_samples, target_frequency)

interpolate_IMU(original_samples, target_frequency)

sensor_resample(
  original_samples,
  target_frequency,
  method = c("linear_C", "linear_R", "IMU")
)

interpolate_R(original_samples, target_frequency)

Arguments

original_samples

numeric. the original data stream

target_frequency

numeric. the target sampling frequency

method

character. Resampling method to apply. Currently accepts only interpolate.

Details

Currently, resampling is supported via linear interpolation and a distance-based approach. Two linear methods are supported, i.e., an R based version (method="interpolate_R") and a C++ based version (method="interpolate_C"). The latter is used by default. The distance-based approach is used for resampling/interpolating SENSOR_DATA packets (i.e., IMU data).

Value

An appropriately up/down-sampled data stream (numeric vector)

Examples

set.seed(14)
target_frequency <- 100

## Downsample linear
   original_samples <- sample(
     seq(1.3,2.4,0.12), 101, replace = TRUE
   )
   down_linear <- sensor_resample(
     original_samples, target_frequency
   )
   head(down_linear)

## Upsample linear
   original_samples <- original_samples[1:99]
   up_linear <- sensor_resample(
     original_samples, target_frequency
   )
   head(up_linear)

## Upsample IMU
   up_IMU <- sensor_resample(
     original_samples, target_frequency, "IMU"
   )
   head(up_IMU)

AGread documentation built on Sept. 13, 2022, 5:06 p.m.