【问题标题】:Using R and Sensor Accelerometer Data to Detect a Jump使用 R 和传感器加速度计数据检测跳跃
【发布时间】:2015-07-03 05:04:35
【问题描述】:

我对传感器数据很着迷。我使用我的 iPhone 和一个名为 SensorLog 的应用程序来捕获 当我站立并推动我的腿跳跃时的加速度计数据。

我的目标是使用 R 创建一个模型,该模型可以识别跳跃以及我在空中停留的时间。 我不确定如何应对这样的挑战。我有一个带有加速度计数据的时间序列。

https://drive.google.com/file/d/0ByWxsCBUWbqRcGlLVTVnTnZIVVk/view?usp=sharing

一些问题:

  • 如何检测时间序列数据中的跳跃?
  • 如何识别播出时间部分?
  • 如何训练这样的模型?

下面是用来创建上图的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)

【问题讨论】:

标签: r machine-learning time-series accelerometer iot


【解决方案1】:

这可能不是完美的解决方案,但它可能足以让您开始。第一部分依赖于对 gazetools 包中的 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
}

为了让 find_maxima 和 find_minima 函数为我们提供我们正在寻找的东西,我们需要进一步平滑 total_gravity 数据:

spline <- smooth.spline(sample$loggingSample, y = sample$total_gravity, df = 30)

注意:我将总重力“归零” (sample$total_gravity &lt;- sample$total_gravity - 1)

接下来,拉出平滑后的 x 和 y 值:

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

您可以降低阈值以获取更多数据点(加速度变化)。

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    我会考虑一些事情:

    1. 通过每 100 毫秒收集一次中值来平滑数据 - iPhone 上的加速度计数据并不完全准确,因此这种方法会有所帮助。
    2. 按照@scribbles 的建议识别turningpoints

    在我的 github 存储库中有可用的代码,可以对其进行修改以帮助解决这两个问题。带有一些解释的 PDF 在这里:https://github.com/MonteShaffer/mPowerEI/blob/master/mPowerEI/example/challenge-1a.pdf

    具体看一下:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 2015-06-02
      • 1970-01-01
      相关资源
      最近更新 更多