[chronojump] Improved test: smooth-by-speed-changes



commit 4e8053c56143ddbcff5b71ee50f8ec5cf8974ec4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Mar 11 18:42:09 2016 +0100

    Improved test: smooth-by-speed-changes

 encoder/tests/smooth-by-change-pos/result.png      |  Bin 1127225 -> 92490 bytes
 .../smooth-by-change-pos/smooth-by-change-pos.R    |   47 --------------------
 .../smooth-by-change-pos/smooth-by-speed-changes.R |   45 +++++++++++++++----
 3 files changed, 36 insertions(+), 56 deletions(-)
---
diff --git a/encoder/tests/smooth-by-change-pos/result.png b/encoder/tests/smooth-by-change-pos/result.png
index b1d0b69..adcd8fc 100644
Binary files a/encoder/tests/smooth-by-change-pos/result.png and 
b/encoder/tests/smooth-by-change-pos/result.png differ
diff --git a/encoder/tests/smooth-by-change-pos/smooth-by-speed-changes.R 
b/encoder/tests/smooth-by-change-pos/smooth-by-speed-changes.R
index ac6d902..eb50490 100644
--- a/encoder/tests/smooth-by-change-pos/smooth-by-speed-changes.R
+++ b/encoder/tests/smooth-by-change-pos/smooth-by-speed-changes.R
@@ -45,28 +45,55 @@ speedToSpeedChanges <- function(displ)
 
 displ.raw <- scan("oscillating-signal.txt",sep=",")
 
+#-------- new method ------
+
 displ.changes <- speedToSpeedChanges(displ.raw)
 pos.raw <- cumsum(displ.raw)
 pos.diffspeed <- pos.raw[displ.changes[,1]]
-#pos.diffspeed.smooth <- smooth.spline(displ.changes[,1], pos.diffspeed, spar=.7)
-pos.diffspeed.smooth <- smooth.spline(displ.changes[,1], pos.diffspeed, spar=.1)
+pos.diffspeed.smooth <- smooth.spline(displ.changes[,1], pos.diffspeed, spar=.7)
+#pos.diffspeed.smooth <- smooth.spline(displ.changes[,1], pos.diffspeed, spar=.1)
 
 #plot
-plot(pos.raw, type="b", col="red")
-points(displ.changes[,1], pos.diffspeed, col="green", cex=2)
+#plot(pos.raw, type="b", col="red")
+#points(displ.changes[,1], pos.diffspeed, col="green", cex=2)
 #points(pos.diffspeed.smooth, col="blue", cex=1)
-lines(pos.diffspeed.smooth, col="blue")
+#lines(pos.diffspeed.smooth, col="blue")
+
+speed = predict( pos.diffspeed.smooth, deriv=1 )
+accel = predict( pos.diffspeed.smooth, deriv=2 )
+
+#-------- old method ------
+
+speedOld = getSpeed(displ.raw, 0.7)
+accelOld = getAcceleration(speedOld)
 
-speed <- getSpeed (pos.diffspeed.smooth$y, 0.7)
+
+#-------- graph all --------
+# left side
+par(mfrow=c(1,2))
+plot(pos.raw, type="l", col="black", axes=F, xlab="old method", ylab="")
+abline(v=2500)
 par(new=T)
-plot(speed, col="yellow", type="l", lwd=2)
-accel <- getAcceleration(pos.diffspeed.smooth)
+plot(speedOld, col="green", type="l", lwd=2, xlab="")
 par(new=T)
-plot(accel, col="magenta", type="l", lwd=4, axes=F)
+plot(accelOld, col="magenta", type="l", lwd=2, axes=F, xlab="", ylab="")
 axis(4)
 
+# right side
+plot(pos.raw, type="l", col="black", axes=F, xlab="new method", ylab="")
+abline(v=2500)
+par(new=T)
+plot(speed, col="green", type="l", lwd=2, xlab="")
+par(new=T)
+plot(accel, col="magenta", type="l", lwd=2, axes=F, xlab="", ylab="")
+axis(4)
+par(mfrow=c(1,1))
 
 
+#displ.raw[2480:2530]
+ [1]  0 -1  0  0 -1  0  0  0 -1  0  0 -1  0  0  0 -1  0  0  0  0 -1  0  0  0  0
+[26] -1  0  0 -1  0  0 -1  0  0 -1  0  0 -1  0  0 -1  0  0  0 -1  0  0 -1  0  0
 
+#note the: 0  0  0  0 -1  0  0  0  0
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]