使用R和传感器加速计数据检测跳跃

使用R和传感器加速计数据检测跳跃,r,machine-learning,time-series,accelerometer,iot,R,Machine Learning,Time Series,Accelerometer,Iot,我被传感器数据迷住了。我用我的iPhone和一个叫做SensorLog的应用程序来捕捉 当我站着并推动腿跳跃时,加速度计数据 我的目标是使用R创建一个模型,可以识别跳跃和我在空中的时间。 我不知道如何在这样的挑战中前进。我有一个带有加速计数据的时间序列 一些问题: 如何在timeseries数据中检测到跳转 如何识别广播时间部分 如何培养这样一个榜样 下面是用来创建上面图表的R代码,这是我站着做一个简单的跳跃 谢谢 # Training set sample <- read.csv

我被传感器数据迷住了。我用我的iPhone和一个叫做SensorLog的应用程序来捕捉 当我站着并推动腿跳跃时,加速度计数据

我的目标是使用R创建一个模型,可以识别跳跃和我在空中的时间。 我不知道如何在这样的挑战中前进。我有一个带有加速计数据的时间序列

一些问题:

  • 如何在timeseries数据中检测到跳转
  • 如何识别广播时间部分
  • 如何培养这样一个榜样

下面是用来创建上面图表的R代码,这是我站着做一个简单的跳跃

谢谢

# Training set
sample <- read.csv("sample-data.csv")

# Sum gravity
sample$total_gravity <- sqrt(sample$accelerometerAccelerationX^2+sample$accelerometerAccelerationY^2+sample$accelerometerAccelerationZ^2)

# Smooth our total gravity to remove noise
f <- rep(1/4,4)
sample$total_gravity_smooth <- filter(sample$total_gravity, f, sides=2)

# Removes rows with NA from smoothing
sample<-sample[!is.na(sample$total_gravity_smooth),]

#sample$test<-rollmaxr(sample$total_gravity_smooth, 10, fill = NA, align = "right")

# Plot gravity
plot(sample$total_gravity, type="l", col=grey(.2), xlab="Series", ylab="Gravity", main="Accelerometer Gravitational Force")
lines(sample$total_gravity_smooth, col="red")
stdevs <- mean(sample$total_gravity_smooth)+c(-2,-1,+1,+2)*sd(sample$total_gravity_smooth)
abline(h=stdevs)
#训练集

示例这可能不是完美的解决方案,但它可能足以让您开始。第一部分依赖于包中find_peaks函数的一个小修改

find_maxima <- function(x, threshold)
{
  ranges <- find_peak_ranges(x, threshold)
  peaks <- NULL
  if (!is.null(ranges)) {
    for (i in 1:nrow(ranges)) {
      rnge <- ranges[i, 1]:ranges[i, 2]
      r <- x[rnge]
      peaks <- c(peaks, rnge[which(r == max(r))])
    }
  }
  peaks
}


find_minima <- function(x, threshold)
{
  ranges <- find_peak_ranges(x, threshold)
  peaks <- NULL
  if (!is.null(ranges)) {
    for (i in 1:nrow(ranges)) {
      rnge <- ranges[i, 1]:ranges[i, 2]
      r <- x[rnge]
      peaks <- c(peaks, rnge[which(r == min(r))])
    }
  }
  peaks
}

<代码> FiffyMax(P>)我会考虑一些事情:

  • 通过每100ms收集一次中值来平滑数据——iPhone上的加速计数据并不完全准确,因此这种方法会有所帮助
  • 按照@scribbles的建议识别
    转折点
  • 我的github存储库中有一些代码可以修改,以帮助解决这两个问题。以下是一份PDF格式的说明:

    具体来看:

    library(devtools);  
    install_github("MonteShaffer/mPowerEI", subdir="mPowerEI");
    library(mPowerEI);
    
    # data smoothing
    ?scaleToTimeIncrement
    
    # turning points
    ?pastecs::turnpoints
    

    请参考这里的答案。也许会有帮助!
    out <- as.data.frame(cbind(spline$x,spline$y))
    
    max <- find_maxima(out$y, threshold = 0.4)
    min <- find_minima(out$y, threshold = -0.4)
    
    plot(out$y, type="l", col=grey(.2), xlab="Series", ylab="Gravity", main="Accelerometer Gravitational Force")
    lines(out$y, col="red")
    stdevs <- mean(out$y)+c(-2,-1,+1,+2)*sd(out$y)
    abline(h=stdevs)
    abline(v=max[1], col = 'green')
    abline(v=max[2], col = 'green')
    abline(v=min[1], col = 'blue')
    
    print(hangtime <- min[1] - max[1])
    [1] 20
    
    library(devtools);  
    install_github("MonteShaffer/mPowerEI", subdir="mPowerEI");
    library(mPowerEI);
    
    # data smoothing
    ?scaleToTimeIncrement
    
    # turning points
    ?pastecs::turnpoints