Tuesday, March 26, 2013

Using Accelerometer : Ups and Downs

Accelerometer is a popular sensor for detecting motion and closer analysis reveals type of motion as well. In simple terms, this sensor gives you the acceleration along each axis. Researchers and app developer have used it extensively for detecting walking, running, postures etc. A generic accelerometer can be 3 axis and even 6 axis.  For this project, I want to use the accelerometer sensor that comes embedded in an Android device for detection opening and closing of doors, windows. Comparatively these types of motion are not as complex as change of postures, walking vs running and others.

Again there are few unanticipated challenges I faced while trying to detect this predictable variation in acceleration. As you may know, accelerometer readings have lots of noise in them. Suppose the device is lying on your table. If you see the consequent readings, it keeps changing every reading for even x and z axis. The y axis will be showing errors due to the gravity factor. Now this noisy reading becomes a challenge because unlike for walking/running, the change of acceleration for opening a door is not going to be that high to observe a distinct difference unless you open/close the door very fast. Moreover opening and closing of doors will be happening in matter of few seconds ( at max may be 2 seconds). Detection needs to be fast. So you will also not have the option for sampling for larger intervals. And also false positives and false negatives should be ideally zero. I can think of 3 ways to approach this problem for time being - 1. Do quick sampling ( 200 - 400 ms) and look for distinct change in acceleration or maintain a threshold; 2. Use gyroscope readings as well to look for variation in angle and also to filter out noise; 3. Have better classification algorithm to categorize changes.

I have been trying to do a variation of the first way, since it is simple and fast. So I have been experimenting with different threshold values. And also instead of depending on a single instance of change, if there has been a continuous increase or decrease in acceleration over few intervals then I classify the door to be in motion. For the particular case of opening and closing of door, I consider acceleration along x and z axes for obvious reasons to cut down on the noise even more.

I will add snapshots of graphs showing the different cases later today.
In the graph below, the green dots are the points when our algorithm detects door to be in motion. If you study the graph, the algo fails when the door is opened very slowly. For this reason we will add a second layer to this detection  which is based on sound level/amplitude (later)



No comments:

Post a Comment