Using R accelerometer and sensor data to detect jump

I am fascinated by the sensor data. I used my iPhone and an app called SensorLog to capture accelerometer data as I stand and push my legs to jump.

My goal is to use R to create a model that can identify jumps and how long I will be in the air. I am not sure how to act in such a difficult situation. I have a timer with accelerometer data.

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

Some questions:

  • How can a jump in time data be detected?
  • How to determine part of the airtime?
  • How to prepare such a model?

enter image description here

Below is the R code used to create the graphs above, which I stood and took a simple jump.

Thanks!

# 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) 
+6
source share
2 answers

This is probably less than an ideal solution, but it may be enough to get you started. The first part is based on a small modification of the find_peaks function from the gazetools package.

 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 } 

To find the find_maxima and find_minima functions, to give us what we are looking for, we will need to further smooth the total_gravity data:

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

Note: "Zero" full gravity ( sample$total_gravity <- sample$total_gravity - 1 )

Then pull out the smoothed x and y values:

 out <- as.data.frame(cbind(spline$x,spline$y)) 

Then we find local maxima and minima

 max <- find_maxima(out$y, threshold = 0.4) min <- find_minima(out$y, threshold = -0.4) 

And then build the data to make sure everything looks legal:

 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') 

I want to be like Mike

And finally, we can see how long you have been on earth.

 print(hangtime <- min[1] - max[1]) [1] 20 

You can reduce your thresholds to get additional data (changes in acceleration).

Hope this helps!

+1
source

I would consider a few things:

  • Smooth the data by collecting median values ​​every 100 ms - the accelerometer data on the iPhone is not entirely accurate, so this approach will help.
  • Define turningpoints as @scribbles suggests.

There is code in my github repository that can be modified to help deal with both of these issues. PDF with some explanation here: https://github.com/MonteShaffer/mPowerEI/blob/master/mPowerEI/example/challenge-1a.pdf

In particular, see:

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

All Articles