Call Encore now on +44 (0) 1273 722 544 or contact us
Monday 6th, February 2012

Nodding and shaking the iPhone

Posted by Neil Mather on June 30, 2009

The accelerometer in the iPhone allows for lots of interesting new methods of user interaction (here’s a good list of examples.)

We’ve recently been making an iPhone app which required a tilting back and forth mechanism — essentially the ability to ‘nod’ and ‘shake’ the iPhone. A tilt back and forth on the x-axis being a nod, and on the y-axis a shake (the app runs in landscape orientation.)

To watch for a nod or a shake, you can’t simply observe the present accelerometer values — you need to watch a range of them over time. Once you’ve got a set of data over time, you can do a bit of analysis on a particular window and see if it matches the gesture you’re after.

The free Context Logger app is very useful to watch the incoming data from the accelerometer and see what the data looks like for the gesture you’re after. For our gesture, a nod or shake, you get some kind of oscillating waveform. In an ideal world with ideal user interaction you’d get a nice
smooth sine wave with a fixed amplitude and frequency every time — not likely though in real life! You’re more likely to get some kind of triangle or saw wave with all kinds of bits of noise.

If you could really force the user to do one kind of nice wave for you, you could probably do a fourier transform to look at the incoming data and check for a spike at a certain frequency (e.g. suggestions here.) I do think there’s something to be said for forcing the user to conform to an expected input gesture — you can’t possibly capture every user’s interpretation of what a nod or a shake is — but at the same time you have to give a bit of leeway.

So in our case we tried to be more general. We simply watch for oscillations (ensuring the peaks are over a certain amplitude to ignore the low-level noise you always get) and if we get enough in our window on one axis we take it to be a nod or shake. We take an oscillation to be a change from a negative deviation from the mean of the values in our window, to a positive deviation from the mean, or vice versa.

2 Comments »

  1. Craguss

    October 31, 2009 // 1:16 pm

    Wow, you really have done your homework with this, I appreciate your efforts in providing this information. Very scientific!

  2. craig

    October 31, 2009 // 1:18 pm

    Way to go! That’s all I do with my Iphone, nod and shake it about! It’s great!

Leave a Comment

Like what you see? Then get in touch;
t. +44 (0) 1273 722 544   e. contact us