Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Correct way of calculating the roll of an animal using 3d acceleration?

$
0
0

I placed an accelerometer to several fishes in a field experiment to understand some of their behaviours. What I got was values of raw acceleration (X, Y, Z) of the fishes. This raw acceleration is decomposed into a part that is static (due to the gravity. I call it rmX, rmY and rmZ) and a dynamic part (due to the movement of the fish. I call it diX,diY and diZ). What I would like is to calculate the roll of my fishes in different circumstances (while swimming, resting, etc) since this information could be relevant from an ecological point of view.

The most complicated aspect in my case is that the accelerometers do not stay perfectly aligned with all the gravity acceleration on the Y-axis and being X and Z = 0. I always placed the accelerometer with the same orientation but static acceleration differs among fishes due to the impossibility of placing the accelerometer exactly in the same way in all fishes. For all individuals, in their natural position (belly down and dorsal fin up), the gravity acceleration is on all 3 axes. enter image description here

What I had done to calculate the roll was this:

FR <- 12.0 # Recording frequency. 12 Hz in my case.
RM <- 2 * FR # Running mean (to calculate static and dynamic acceleration)

Individual1$rmX <-runmean(Individual1$X,RM) # To calculate static acceleration
Individual1$rmY <-runmean(Individual1$Y,RM)
Individual1$rmZ <-runmean(Individual1$Z,RM)

Individual1$disurge <- abs(Individual1$X-Individual1$rmX) # To calculate dinamic acceleration
Individual1$diheave <- abs(Individual1$Y-Individual1$rmY)
Individual1$disway <- abs(Individual1$Z-Individual1$rmZ)

Individual1$roll <- (asin(Individual1$rmZ))*180/pi # To calculate Roll!!

summary(Individual1$roll)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
-90.000 -53.953 -42.423 -26.456  -9.004  66.924    2186 

However, I get NAs for the variable roll. I think it is due to the formula I am using. If I use the formula that appears in this post in StackOverflow I get the following:

foo$roll<- atan2(foo$rmY, foo$rmZ) * 180/pi

summary(foo$roll)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-179.97  100.45  113.13   96.76  143.81  179.97 

As you can see, the result differs substantially between I used to do and what I have seen that is being used for other colleagues. I think it makes more sense what I saw in the post (foo$roll<- atan2(foo$rmY, foo$rmZ) * 180/pi) since the range of values for the roll is -180/ +180. I have seen that the formula I used to use only take into account the Z-axis, but the formula mentioned in the post uses also the value of the Y-axis to calculate the roll.

Does anyone know how to proceed in my particular case? Which formula takes more sente?


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>