From: Tomas Mudrunka Date: Thu, 2 Aug 2012 19:48:46 +0000 (+0200) Subject: Sleepmon gnuplot graphing X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=7cd5c7da35ac8f7e5596e4133c85e1f24e66f418;p=mirrors%2FPrograms.git Sleepmon gnuplot graphing --- diff --git a/c/goertzel/README.md b/c/goertzel/README.md index a21b5cc..d32a00b 100644 --- a/c/goertzel/README.md +++ b/c/goertzel/README.md @@ -18,6 +18,7 @@ Scriptable tone detection and audio analysis * **histogram.sh**: example using histogram.pl to draw realtime equalizer * **sleepmon.sh**: Generates frequency on soundcard output and detects it on input * Can be used to detect and log motion using soundcard and PIR sensor or NC switch + * **sleepplot.sh*: Generates gnuplot graph from sleeplog * TODO * Guitar tuner * Send me more... diff --git a/c/goertzel/sleepmon.sh b/c/goertzel/sleepmon.sh index 4896e87..87967dd 100755 --- a/c/goertzel/sleepmon.sh +++ b/c/goertzel/sleepmon.sh @@ -28,10 +28,10 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do level="$(echo "$line" | cut -f 2)" echo -ne "$time\t$date\t$(date '+%F%t%T')\t" test "$level" -gt "$tresh" && { - echo -n "Nothing detected..."; + echo -n "0 Nothing detected..."; $screen && xset dpms force off || true; } || { - echo -n "Motion detected!!!!"; + echo -n "1 Motion detected!!!!"; $screen && xset dpms force on; } test "$lastdate" != 0 && { @@ -39,6 +39,7 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do echo -ne "\t$level After $after secs"; } echo; + ./sleepplot.sh "$out" &>/dev/null; lastdate="$date"; done | tee "$out" kill $! diff --git a/c/goertzel/sleepplot.sh b/c/goertzel/sleepplot.sh new file mode 100755 index 0000000..09fd050 --- /dev/null +++ b/c/goertzel/sleepplot.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +test -z "$1" && { + echo "Usage: $0 sleeplog.txt" + exit 23 +} + +size="$(tail -n 1 "$1" | cut -d . -f 1)" +test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods +size="$(( 200 + ($size * 2) ))" + +gnuplot << EOF +set output "$1.png" +set terminal png size $size,200 + +set title "Sleep motions" +set xlabel "time" +set ylabel "motion" + +set yrange [-0.5:1.5] + +set xdata time +set timefmt "%s" +#set format x "%H:%M:%S" + +#set y2tics 300 +#set ytics 5 + +set grid + +#set pointsize 0.5 +plot "$1" using 2:5 with histeps; + +EOF + + + +