R/import_data.R
import_activpal3_csv.Rdimport_activpal3_csv imports the raw multi-channel accelerometer data
stored in ActivPal3 csv format by converting the accelerometer values (in
digital voltage values) to \(g\) unit.
import_activpal3_csv(filepath, header = FALSE)dataframe. The imported multi-channel accelerometer signal, with the first column being the timestamps in POSXlct format, and the rest columns being accelerometer values in \(g\) unit.
ActivPal 3 sensors have known dynamic range to be \((-2g, +2g)\). And the sensor stores values using 8-bit memory storage. So, the digital voltage values may be converted to \(g\) unit using following equation.
$$x_g = \frac{x_{voltage} - 127}{2^8} * 4$$
This function is a File IO function that is used to import data from ActivPal3 devices during algorithm validation.
default_ops = options()
options(digits.secs=3)
# Use the sample activpal3 csv file provided by the package
filepath = system.file('extdata', 'activpal3.csv', package='MIMSunit')
# Check the csv format
readLines(filepath)[1:5]
#> [1] "43265.5705908565,112,140,58" "43265.5705914352,124,132,59"
#> [3] "43265.5705920139,116,126,61" "43265.5705925926,116,121,64"
#> [5] "43265.5705931713,102,113,68"
# Load the file, in our case without header
df = import_activpal3_csv(filepath, header=FALSE)
# Check loaded file
head(df)
#> HEADER_TIME_STAMP X Y Z
#> 1 2018-06-14 13:41:39 -0.234375 0.203125 -1.078125
#> 2 2018-06-14 13:41:39 -0.046875 0.078125 -1.062500
#> 3 2018-06-14 13:41:39 -0.171875 -0.015625 -1.031250
#> 4 2018-06-14 13:41:39 -0.171875 -0.093750 -0.984375
#> 5 2018-06-14 13:41:39 -0.390625 -0.218750 -0.921875
#> 6 2018-06-14 13:41:39 -0.421875 -0.546875 -0.843750
# Check more
summary(df)
#> HEADER_TIME_STAMP X Y
#> Min. :2018-06-14 13:41:39 Min. :-1.56250 Min. :-1.953125
#> 1st Qu.:2018-06-14 13:42:41 1st Qu.: 0.04688 1st Qu.: 0.046875
#> Median :2018-06-14 13:43:44 Median : 0.06250 Median : 0.046875
#> Mean :2018-06-14 13:43:44 Mean : 0.02084 Mean :-0.006097
#> 3rd Qu.:2018-06-14 13:44:46 3rd Qu.: 0.06250 3rd Qu.: 0.046875
#> Max. :2018-06-14 13:45:49 Max. : 0.90625 Max. : 1.218750
#> Z
#> Min. :-1.9688
#> 1st Qu.:-1.0156
#> Median : 1.1250
#> Mean : 0.3263
#> 3rd Qu.: 1.1250
#> Max. : 1.9688
# Restore default options
options(default_ops)