CMMotionManager - How to define steps ignoring small movements?

Getting data from is pretty straight forward, processing it is not much. CMMotionManager

Does anyone have any pointers to relatively accurately determine the step (and ignore small movements) or recommendations in the general direction of how to do this?

+3
source share
1 answer

What you basically need is a kind of low-pass filter that allows you to ignore small movements. Effectively, it “smoothes” data by taking out trembling data.

- (void)updateViewsWithFilteredAcceleration:(CMAcceleration)acceleration
{
    static CGFloat x0 = 0;
    static CGFloat y0 = 0;

    const NSTimeInterval dt = (1.0 / 20);
    const double RC = 0.3;
    const double alpha = dt / (RC + dt);

    CMAcceleration smoothed;
    smoothed.x = (alpha * acceleration.x) + (1.0 - alpha) * x0;
    smoothed.y = (alpha * acceleration.y) + (1.0 - alpha) * y0;

    [self updateViewsWithAcceleration:smoothed];

    x0 = smoothed.x;
    y0 = smoothed.y;
}

alpha , . dt - . RC . .

+3

All Articles