deriv.awk: Calculate derivative of every column

Instead of just two columns (x and y) in the trace file, treat
every column as a function and calculate the first derivative
of it without regard for its supposed "meaning".  In addition
to getting more data from this, it also allows us to calculate
the 2nd derivative easily by running the script again on the
resulting data.

Also convert time in column 1 from microseconds to seconds.
This commit is contained in:
Phil Hord 2013-12-13 08:15:31 -05:00 committed by Markus Hitter
parent ed7f3ad559
commit 3fcd6b3c59
2 changed files with 27 additions and 27 deletions

View File

@ -3,33 +3,26 @@ BEGIN { firstline = 1 }
# Calculates the first derivative of columns 2 and 3 wrt column 1
$0 !~ /^#/ {
t = $1
x = $2
y = $3
$1 /= 1000000.0
if (firstline == 1) {
old_tx = old_ty = t
old_x = x
old_y = y
dy_dt = dx_dt = 0
for ( i=1; i<=NF; i++) {
prev_t[i] = $1
prev_x[i] = $i
deriv[i] = 0
}
firstline = 0
} else {
dx = old_x - x
dy = old_y - y
if ( dx != 0) {
dt = old_tx - t
dx_dt = dx/dt
old_tx = t
old_x = x
}
if ( dy != 0) {
dt = old_ty - t
dy_dt = dy/dt
old_ty = t
old_y = y
}
if ( dx != 0 || dy != 0 ) {
print t, " ", x, " ", y, " ", dx_dt, " ", dy_dt
printf $1
for ( i=2; i<=NF; i++) {
if ( $i != prev_x[i] ) {
dx = $i - prev_x[i]
dt = $1 - prev_t[i]
deriv[i] = dx/dt
prev_t[i] = $1
prev_x[i] = $i
}
printf " %s %0f", $i, deriv[i]
}
print ""
}
}

View File

@ -24,7 +24,14 @@ gnuplot --persist -e "
set y2label 'Velocity (mm/minute)'; set ytics nomirror ; set y2tics;
set samples 10000 ;
plot '${VELOC}' u (\$1/1000000):(\$2/$MM_PER_STEP) with lines t \"X-position\" , '' u (\$1/1000000):(\$3/$MM_PER_STEP) with lines t \"Y-position\"
, '' u (\$1/1000000):(60000000.0*\$4/$MM_PER_STEP) with lines t \"X-velocity\" axes x1y2
, '' u (\$1/1000000):(60000000.0*\$5/$MM_PER_STEP) with lines t \"Y-velocity\" axes x1y2
plot '${VELOC}' u (\$1):(60.0*\$3/$MM_PER_STEP) with lines t \"X-velocity\" axes x1y2
, '' u (\$1):(60.0*\$5/$MM_PER_STEP) with lines t \"Y-velocity\" axes x1y2
, '' u (\$1):(60.0*\$7/$MM_PER_STEP) with lines t \"Z-velocity\" axes x1y2
, '' u (\$1):(60.0*\$9/$MM_PER_STEP) with lines t \"E-velocity\" axes x1y2
, '' u (\$1):(\$2/$MM_PER_STEP) with lines t \"X-position\"
, '' u (\$1):(\$4/$MM_PER_STEP) with lines t \"Y-position\"
, '' u (\$1):(\$6/$MM_PER_STEP) with lines t \"Z-position\"
, '' u (\$1):(\$8/$MM_PER_STEP) with lines t \"E-position\"
, '' u (\$1):(\$10/$MM_PER_STEP) with steps t \"X-Step\"
, '' u (\$1):(\$10/$MM_PER_STEP) with steps t \"Y-Step\"
"