sensor_resample: Resample a sensor data stream

Description Usage Arguments Details Value Examples

View source: R/read_gt3x_Interpolate2.R

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

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)

Example output

package 'AGread' was built under R version 3.5.0
[1] 2.26 2.26 1.66 1.66 2.38 1.30
[1] 2.2600 2.2600 1.6840 1.6600 2.3224 1.4080
[1] 2.2600 2.2600 1.6720 1.6600 2.3512 1.3540

AGread documentation built on Feb. 26, 2020, 5:12 p.m.