edan

some projects

Shell Script for Zooming In to the EEG Data

leave a comment »

To make things a bit easier, I wrote the following shell script.

Copy and paste it to a plain text file, save that as plot-zoom.sh.

Put it in the folder that has your LOGGERnn.CSV files.

Now open up a command line prompt (Terminal, on a Mac), use cd to navigate to the directory that has the LOGGERnn.CSV files and plot-zoom.sh, and run the script with:

./plot-zoom.sh LOGGER00.CSV

(if you want to use e.g LOGGER01.CSV, then replace the file name with that.)

Here’s the script:
(if you want to see it with pretty formatting, check out the copy on Pastebin.


#! /bin/sh
echo "\n************ \n"
echo "Plots EEG data for a zoomed-in file region\n"
echo "This script expects to be run from within a folder\n containing the LOGGERNN.CSV file from the Arduino."
echo "It expects the pathname of the LOGGERNN.CSV\n file as a command line argument, e.g:"
echo "\t plot.sh LOGGER09.CSV \n"
echo "************ \n"

START_MINUTES=00
START_MSEC=00
LENGTH_MINUTES=00
LENGTH_MSEC=00

FILE=$1
echo "Using data from" $FILE


# ask for the offset
echo "\n"
head -n 2 "$FILE"
read -p "What's the offset? (millis value above) " OFFSET
# for testing:
#OFFSET=222
echo "\n"



read -p "How many minutes into the file does the selection start? (msec comes next) " START_MINUTES

read -p "How many milliseconds on top of that? " START_MSEC

read -p "How many minutes does the selection last? " LENGTH_MINUTES

read -p "How many milliseconds on top of that? " LENGTH_MSEC



# calculate starting offset

# for testing
 # START_MINUTES=33;START_MSEC=44;OFFSET=55;LENGTH_MINUTES=66;LENGTH_MSEC=77;

START_OFFSET=$(( ($START_MINUTES * 60 * 1000) + $START_MSEC + $OFFSET))

echo "Using start offset" $START_OFFSET "msec"

# calculate ending offset
END_OFFSET=$(( ($LENGTH_MINUTES  * 60 * 1000) + $LENGTH_MSEC + $START_OFFSET))

echo "Using end offset" $END_OFFSET "msec"

XSIZE=15
YSIZE=4

# testing

OUTFILE="$FILE-${START_MINUTES}m${START_MSEC}msec_for_${LENGTH_MINUTES}m${LENGTH_MSEC}msec.pdf"

echo "Writing output to" $OUTFILE

gnuplot -e "file=file='$FILE'; set datafile separator \",\"; set key autotitle columnhead; set yrange [0:1000000]; set y2range [0:100]; set parametric; set label 1 \"File $FILE starting at $START_MINUTES min $START_MSEC msec for duration $LENGTH_MINUTES min $LENGTH_MSEC msec\" at graph 0.5,1.02 center;set xrange [$START_OFFSET:$END_OFFSET]; set terminal pdfcairo color size $XSIZE,$YSIZE; set output '$OUTFILE'; plot for [i=6:13] file using 1:i with lines smooth bezier, file using 1:3 with lines axis x1y2 smooth csplines"
Advertisements

Written by 333dan

June 9, 2012 at 9:53 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: