diff --git a/NAMESPACE b/NAMESPACE index d32934d..401cd37 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,7 +21,6 @@ import(foreach) import(ggplot2) import(ggpubr) importFrom(GENEAread,read.bin) -importFrom(GGIR,g.downsample) importFrom(GGIRread,readAxivity) importFrom(GGIRread,resample) importFrom(data.table,fread) diff --git a/R/autocalibration.R b/R/autocalibration.R index 702b115..b5c729a 100644 --- a/R/autocalibration.R +++ b/R/autocalibration.R @@ -8,12 +8,12 @@ #' @param brand Character of sensor brand: "ActiGraph", "activPAL", "Acttrust", "Axivity", "GENEActiv", or "MOX". #' @return List of objects identical to g.calibrate function R package GGIR #' @importFrom stats sd lm.wfit -#' @importFrom GGIR g.downsample #' @export autocalibration = function(data, sr, printsummary= TRUE, brand) { # simplified version of auto-calibration from R package GGIR # without temperature and without loading the data in blocks + # now includes old g.downsampling function removed from GGIR... spherecrit=0.3 minloadcrit=72 @@ -73,13 +73,29 @@ autocalibration = function(data, sr, printsummary= TRUE, brand) { #============================================= # non-integer sampling rate is a pain for deriving epoch based sd # however, with an epoch of 10 seconds it is an integer number of samples per epoch + g.downsample = function(sig,fs,ws3,ws2) { + #averaging per second => var1 + sig2 =cumsum(c(0,sig)) + select = seq(1,length(sig2),by=fs) + var1 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))]))) + #averaging per ws3 => var2 (e.g. 5 seconds) + select = seq(1,length(sig2),by=fs*ws3) + var2 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))]))) + #averaging per ws2 => var3 (e.g. 15 minutes) + select = seq(1,length(sig2),by=fs*ws2) + var3 = diff(sig2[round(select)]) / abs(diff(round(select[1:(length(select))]))) + invisible(list(var1=var1,var2=var2,var3=var3)) + } + EN = sqrt(Gx^2 + Gy^2 + Gz^2) - D1 = GGIR::g.downsample(EN,sr,ws4,ws2) + D1 = g.downsample(EN,sr,ws4,ws2) EN2 = D1$var2 #mean acceleration - D1 = GGIR::g.downsample(Gx,sr,ws4,ws2); GxM2 = D1$var2 - D1 = GGIR::g.downsample(Gy,sr,ws4,ws2); GyM2 = D1$var2 - D1 = GGIR::g.downsample(Gz,sr,ws4,ws2); GzM2 = D1$var2 + + D1 = g.downsample(Gx,sr,ws4,ws2); GxM2 = D1$var2 + D1 = g.downsample(Gy,sr,ws4,ws2); GyM2 = D1$var2 + D1 = g.downsample(Gz,sr,ws4,ws2); GzM2 = D1$var2 + #sd acceleration dim(Gx) = c(sr*ws4,ceiling(length(Gx)/(sr*ws4))); GxSD2 = apply(Gx,2,sd) dim(Gy) = c(sr*ws4,ceiling(length(Gy)/(sr*ws4))); GySD2 = apply(Gy,2,sd) diff --git a/README.md b/README.md index 7151f85..0151e87 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![codecov](https://codecov.io/gh/wadpac/mechanicalshakerexperiments/branch/main/graph/badge.svg?token=C2X6Z6AJLL)](https://codecov.io/gh/wadpac/mechanicalshakerexperiments) -The code in this repository corresponds to our research project to facilitate processing and analyzing data from a large pool of acceleration sensors that were attached to a mechanical shaker machine. The data itself is publicly available [here] ([https://pages.github.com/](https://zenodo.org/records/8160791)). +The code in this repository corresponds to our research project to facilitate processing and analyzing data from a large pool of acceleration sensors that were attached to a mechanical shaker machine. The data itself is publicly available [here](https://zenodo.org/records/8160791). ### File reading