I'm doing some math on both gyroscope and accelerometer data combined and I'd like to low pass filter the resulting data. So could someone post some generic code for a Low Pass filter?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
If Apple's AccelerometerGraph example is too complex for you to understand, I created a simpler accelerometer example for my class which you can download here. This implements a simple low-pass and high-pass filter for raw accelerometer values, then logs the results to the screen.
As hotpaw2 and Goz describe, this uses a very simple weighted rolling average for the filter calculation:
A 1st order IIR low-pass filter can be of the form:
which is pretty much what's inside Apple's AccelerometerGraph example. You select the rate parameter depending on what frequency (very very roughly shakes per second) you want to roll-off or start to attenuate to get a smoother resulting output, and the sample rate of the input data.
A low pass filter is simply smoothing of the results to remove the high frequencies. The simplest low pass filter is a box filter which is done by averaging n samples together.
For averaging 2 samples together this is as simple as doing: