26

I am trying to figure out how knocktounlock.com is able to detect "knocks" on the iPhone. I am sure they use the accelerometer to achieve this, however all my tries come up with false flags (if user moves, jumps, etc it sometimes fires)

Basically, I want to be able to detect when a user knocks/taps/smacks their phone (and be able to distinguish that from things that may also give a rise to the accelerometer). So I am looking for sharp high peeks. The device will be in the pocket so the movement of the device will not be very much.

I have tried things like high/low pass (not sure if there would be a better option)

This is a duplicate of this: Detect hard taps anywhere on iPhone through accelerometer But it has not received any answers.

Any help/suggestions would be awesome! Thanks.

EDIT: Looking for more thoughts before I accept the answer below. I did hear back from Knocktounlock and they use the fourth derivative (jounce) to get better values to then analyse. Which is interesting.

Community
  • 1
  • 1
Jonovono
  • 3,437
  • 5
  • 42
  • 64
  • just a suggestion, but you may want to calculate the first or maybe second derivative... then you would just have a single thing to watch with no filtering needed – Grady Player Dec 22 '13 at 05:35
  • 1
    Part of the solution uses the accelerometer in the background. – Andrew Dec 22 '13 at 05:41
  • Knock’s detection isn’t as precise as you think. If my phone is on my desk, and I pick it up to knock it, my computer usually unlocks just from the motion of picking it up. But Knock doesn’t even *look* for knocks until your computer is already trying to unlock, so it doesn’t need to filter out all kinds of motions. Just knock-like motions you might make accidentally while also trying to unlock your computer. This lessens their need to filter out false positives. – Zev Eisenberg Oct 02 '14 at 06:13

5 Answers5

17

I would consider knock on the iPhone to be exactly same as bumping two phones with each other. Check out this Github Repo,

https://github.com/joejcon1/iOS-Accelerometer-visualiser

Build&Run the App on iPhone and check out the spikes on Green line. You can see the value of the spike clearly,

Knocking the iPhone:

enter image description here

As you can see the time of the actual spike is very short when you knock the phone. However the spike patterns are little different in Hard Knock and Soft knock but can be distinguished programmatically.

Now lets see the Accelerometer pattern when iPhone moves in space freely,

enter image description here

As you can see the Spikes are bell shaped that means the it takes a little time for spike value to return to 0.

By these pattern it will be easier to determine the knocking pattern. Good Luck.

Also, This will drain your battery out as the sensor will always be running and iPhone needs to persist connection with Mac via Bluetooth.

P.S.: Also check this answer, https://stackoverflow.com/a/7580185/753603

Community
  • 1
  • 1
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
  • I found it not too practical for knock. I can trigger that even using shake or carry phone while walking or running. – Ricky Jul 11 '14 at 09:16
13

I think the way to go here is using pattern recognition with accelerometer data. You could (write and) train a classifier (e.g. K-nearest neighbor) with data you gathered and that has been classified by hand. Neural networks are also an option. However, there will be many different ways to solve that problem. But there is probably no straightforward way for achieving this.

Some papers showing pattern recognition approaches to similar topics (activity, movement), like http://www.math.unipd.it/~cpalazzi/papers/Palazzi-Accelerometer.pdf (some more, but I am not allowed to post them with my reputation count. You can search for "pattern recognition accelerometer data")

There is also a master thesis about gesture recognition on the iPhone: http://klingmann.ch/msc_thesis_marco_klingmann_iphone_gestures.pdf

In general you won't achieve 100% correct classification. Depending on the time/knowledge one has got the result will vary between good-usable and we-could-use-random-classification-instead.

Daniel Witurna
  • 750
  • 6
  • 13
3

Just a though, but It could be useful to add to the mix the output of the microphone to listen to really short, loud noises at the same time that a possible "knock" movement has been detected.

asendra
  • 410
  • 1
  • 4
  • 14
2

I am surprised that 4th derivative is needed, intuitively feels to me 3rd ("jerk", the derivative of acceleration) should be enough. It is a big hint what to keep eye on, though.

It seems quite simple to me: collect accelerometer data at high rates, plot on chart, observe. Calculate from that first derivative, plot&observe. Then rinse&repeat, derivative of the last one. Draw conclusions. I highly doubt you will need to do pattern recognition per se, clustering/classifiers/what-have-you - i think you will see very distinct peak on one of your charts, may only need to tune collection rate and smoothing.

It is more interesting to me how come you don't have to be running the KnockToUnlock app for this to work? And if it was running in the background, who left it run there for unlimited time. I dont think accel. qualifies for unlimited background run. And after some pondering, i am guessing the reason is that the app uses Bluetooth to connect Mac as accessory - and as such gets a pass from iOS to run in the background (and suck your battery, shhht)

Nas Banov
  • 28,347
  • 6
  • 48
  • 67
0
  1. To solve this problem you need to select the frequency. Tap (knock) has a very high frequency, so you should chose the frequency of the accelerometer is not lower than 50 Hz (perhaps even 100 Hz) for quality tap detection in the case of noise from other movements.
  2. The use of classifiers is necessary, but in order to save battery consumption you should not call a classifier very often.It should write a simple algorithm that would find only taps and situation similar to knoks and report that you program need to call a classifier.
  3. Note the gyro signal, it also responds to knocks, besides the gyroscope signal not be need separated from the constant component and the gyroscope signal contains less noise.
  4. That is a good video about the basics of working with smartphones sensors: http://talkminer.com/viewtalk.jsp?videoid=C7JQ7Rpwn2k#.UaTTYUC-2Sp .