Context Logger for iPhone OS
Aus Embedded Systems
Inhaltsverzeichnis |
So what is it all about?
Basically the whole purpose of 'Context Logger' is to record context information (as the name clearly suggests) ... now the interesting part here is the word Context. Anind K. Dey from the Georgia Institute of Technology defines context as "[...] any information that can be used to characterize the situation of an entity. An entity is a person, place or object that is considered relevant to the interaction between a user and an application, including the user and application themselves". In other words context is the relevant information about a certain state of an object or person and its surrounding environment.
The iPhone can provide exactly that sort of information with its build-in accelerometer. When the user is holding the device and performs a certain gesture - for example "drawing" a big circle in the air - the accelerometer records the acceleration data (which is basically a numerical value for each of the three axes in space per time unit). As this data is more or less unique for different gestures it allows us to recognize a gesture and react to it accordingly.
In it's first version 'Context Logger' focuses on just recording the gestures, labeling them and providing an easy-to-use way to upload the recorded files to a computer where they can be processed with tools such as MatLab. In the future we might add support for other sensors such as the microphone and maybe even provide on-device gesture recognition.
Getting started
Installing the Program
Most likely you already have the program on your iPhone at this point ... but in case you don't here's the iTunes-Link that'll get you right to the app.
The Live View
The first thing you'll see after starting the program is the so called Live View. You can see three graphs which represent the acceleration values of each axis in space in the course of time. When you're holding your device upwards you will notice that the value on the y-axis has a constant acceleration of -1G. As you may have guessed the reason for that is gravity. If you would like the application to ignore gravity and other low frequency signals, you can switch on the high pass filter. You'll find the appropriate switch in the Settings - menu.
Setting up Labels
After the first start of the program you probably want to set up the gesture-labels first. You can do that by going into the Settings-menu where you have to tap on Configure Labels. You may delete the Default Gesture by either swiping across it and tapping the delete-button that appears after the swipe or by tapping the Edit - button in the top right corner.
If you want to add a Label simply tap the Add Label - button and enter the name of the gesture in the appearing pop-up window.
Please note that you can only enter six labels since the limited screen size makes it impossible to display more label-buttons on the recording-screen (at least in a way that still allows for an easy label-selection during the process of recording a gesture).
Recording a Gesture
The layout of the recording view is quite simple for the reason of clarity - after all you don't want to have to concentrate on the screen while recording a gesture. Therefore the Start/Stop Recording - button takes quite a big amount of the available screen real estate. That way it's very easy for the user to tap it with the thumb or whichever finger is closest to it during the recording process. Above the Recording - button you can see the label buttons. The one with the currently active gesture label is highlighted.
When recording a gesture or a series of gestures select the initial label and tap the Start Recording - button. When you reached a point in your gesture where you need to change the label, just select the new label and finish the gesture. Most of the times you'll probably need only one label for each recording, though.
After you're done the record gets moved to the archive automatically. In the archive view you can see the date and time of each record as well as a list with all the labels that were used during the recording.
Uploading the Records
Now the real beauty of 'Context Logger' lies within it's convenient upload function. Basically what it does is launch a webserver on the iPhone. All you have to do as a user is navigate your web browser to the URL that's being displayed on the screen and you can start downloading the files from a web interface.
In order to do that you need to switch to the upload view. Once you're there simply tap the Start Server - button and wait a few seconds until the next screen appears which tells you about the address you have to enter into your web browser.
The important part ist that the computer you're using to access the files must be on the same network as the iPhone that you're trying to connect to (as the web server only publishes on the local network). Also it might be that "non-Apple" devices cannot access the "local"-address since it requires a fully set up zeroconf system (aka "Bonjour" on the Mac). In that case simply use the IP-address which is working on all machines (basically the local address is nothing but syntactic sugar).
After you navigated to the correct address you'll see the web interface of Context Logger. To download a file simply right-click on it and choose save target as ....
Example: How to display the Records with MatLab
Now that you've downloaded your files you obviously want to see them on a screen. I'll demonstrate on a short example how one would do that in the simplest possible way using MatLab.
First you'll need to open your record with a text editor. For MatLab to read the file successfully you need to delete the comments at the beginning of the file (they are there to tell you about the meaning of the labels) or simply change the comment-symbol from '#' to '%' (we chose to use '#' instead of '%' as our internal toolbox uses these symbols for comments as well and so does SciPy).
Now is probably a good time to have a closer look at the content of a log file. As I already mentioned the comments are there to put the labels that were used during the recording in relation to their numerical values. Below the comments you find the actual data - it's arranged in six columns. The last column contains the information about the used label in the current sample. The first two columns provide some sort of time stamp for each sample of the recording. The number in the first column equals the number of seconds since the 1st of January in 1970. The second column shows the millisecond fraction of the current second. With this information you can control the frequency of the accelerometer - it should be somewhere around 40 Hz - and you learn more about the timing of each part of the signal. Columns number three, four and five simply contain the acceleration data for the x-, y- and z-axis.
After you've cleaned the file you can start MatLab. Once MatLab has loaded you need to change your 'current directory' to the path where you saved your file (you do that in the upper window on the right hand side). After you've done that you can plot the graph by typing the following code in the editor on the left hand side:
data=load('2008-12-15 12-34-59 +0100.txt'); plot( data(:,3:5) )
The interesting part of the code is "data(:,3:5)". The first colon means that you want to plot all samples of the data (as in "all rows" of the file). The second argument means that you want the plot to contain only columns three to five. The rule of thumb here is that a colon means "everything" - ranges are noted as "lowerBound:upperBound" and a discrete selection of rows or columns would be noted in a vector like "[1, 3, 5]". If you want to plot everything (even though plotting a timestamp doesn't really make any sense) you could just use "plot(data)".
When you include the labels in the plot you will notice that they are represented by a "stair-like" graph. When the line is at level 0 it means that the label corresponding to 0 is active, the same goes for 1, 2, 3, and so on. You can get the meaning of the level-values from the aforementioned file-comments.
Obviously there are ways to get more sophisticated plots from MatLab (e.g. with actual labels on the plots). If you'd like to learn more please refer to the documents mentioned in the next section or the built-in MatLab help function.
The next steps
OK, so now you know your way around the basic stuff. If you want to learn more about signal analysis (e.g. feature selection, feature extraction and most importantly classification) you should read the tutorials, Kai provided for our students. They handle all the basic MatLab stuff - and in case you don't have access to MatLab the latest version of the tutorial also covers the free SciPy solution.
Stay up to date and have your say
If you would like to get the latest news about the Context Logger application you should have a look at the official blog, which can be found here. Of course you're also more than welcome to leave a comment.
