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:
parent
ed7f3ad559
commit
3fcd6b3c59
|
|
@ -3,33 +3,26 @@ BEGIN { firstline = 1 }
|
||||||
|
|
||||||
# Calculates the first derivative of columns 2 and 3 wrt column 1
|
# Calculates the first derivative of columns 2 and 3 wrt column 1
|
||||||
$0 !~ /^#/ {
|
$0 !~ /^#/ {
|
||||||
t = $1
|
$1 /= 1000000.0
|
||||||
x = $2
|
|
||||||
y = $3
|
|
||||||
if (firstline == 1) {
|
if (firstline == 1) {
|
||||||
old_tx = old_ty = t
|
for ( i=1; i<=NF; i++) {
|
||||||
old_x = x
|
prev_t[i] = $1
|
||||||
old_y = y
|
prev_x[i] = $i
|
||||||
dy_dt = dx_dt = 0
|
deriv[i] = 0
|
||||||
|
}
|
||||||
firstline = 0
|
firstline = 0
|
||||||
} else {
|
} else {
|
||||||
dx = old_x - x
|
printf $1
|
||||||
dy = old_y - y
|
for ( i=2; i<=NF; i++) {
|
||||||
|
if ( $i != prev_x[i] ) {
|
||||||
if ( dx != 0) {
|
dx = $i - prev_x[i]
|
||||||
dt = old_tx - t
|
dt = $1 - prev_t[i]
|
||||||
dx_dt = dx/dt
|
deriv[i] = dx/dt
|
||||||
old_tx = t
|
prev_t[i] = $1
|
||||||
old_x = x
|
prev_x[i] = $i
|
||||||
}
|
}
|
||||||
if ( dy != 0) {
|
printf " %s %0f", $i, deriv[i]
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
print ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,14 @@ gnuplot --persist -e "
|
||||||
set y2label 'Velocity (mm/minute)'; set ytics nomirror ; set y2tics;
|
set y2label 'Velocity (mm/minute)'; set ytics nomirror ; set y2tics;
|
||||||
set samples 10000 ;
|
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\"
|
plot '${VELOC}' u (\$1):(60.0*\$3/$MM_PER_STEP) with lines t \"X-velocity\" axes x1y2
|
||||||
, '' u (\$1/1000000):(60000000.0*\$4/$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/1000000):(60000000.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\"
|
||||||
"
|
"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue