Smoothing Accelerometer Data

Each time the accelerometer sends an update, the center of the view changes to reflect the orientation of the device. However, because the accelerometer’s updateInterval is constant and the device’s movement is variable, the center of the view jumps around instead of moving in calm, peaceful, smooth manner. To get smooth movement, you need smoothed data. To smooth accelerometer data, you apply a low-pass filter.

In HypnosisViewController.m, add the following lines of code to filter the accelerometer data:

-​ ​(​v​o​i​d​)​a​c​c​e​l​e​r​o​m​e​t​e​r​:​(​U​I​A​c​c​e​l​e​r​o​m​e​t​e​r​ ​*​)​m​e​t​e​r​ ​ ​ ​ ​ ​ ​ ​ ​d​i​d​A​c​c​e​l​e​r​a​t​e​:​(​U​I​A​c​c​e​l​e​r​a​t​i​o​n​ ​*​)​a​c​c​e​l​ {​ ​ ​ ​ ​H​y​p​n​o​s​i​s​V​i​e​w​ ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.