# iOS – High pass filter equation for accelerometer

Could someone explain how one arrives at the equation below for high pass filtering of the accelerometer values? I don’t need mathematical derivation, just an intuitive interpretation of it is enough.

```    #define kFilteringFactor 0.1
UIAccelerationValue rollingX, rollingY, rollingZ;

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

// Subtract the low-pass value from the current value to get a simplified high-pass filter

rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));

rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));

rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

float accelX = acceleration.x - rollingX;
float accelY = acceleration.y - rollingY;
float accelZ = acceleration.z - rollingZ;

// Use the acceleration data.

}
```

• Watching variables in Xcode
• Scale UIView and all its children
• How do I make my app work with the media control buttons on lock screen?
• filterContentForSearchText and shouldReloadTableForSearchString not called (UITableView & UISearchBar)
• Enabling done button after inserting one char in a textfield: textFieldDidEndEditing: or textFieldShouldBeginEditing: or?
• Decode images in background thread?
• ### 3 Solutions Collect From Internet About “iOS – High pass filter equation for accelerometer”

The rollingX, rollingY, rollingZ values are persistent across calls to the function. They should be initialised at some point prior to use. These “rolling” values are just low pass filtered versions of the input values (aka “moving averages”) which are subtracted from the instantaneous values to give you a high pass filtered output, i.e. you are getting the current deviation from the moving average.

A moving average is just a crude low pass filter. In this case it’s what is known as ARMA (auto-regressive moving average) rather than just a simple MA (moving average). In DSP terms this is a recursive (IIR) filter rather than a non-recursive (FIR) filter. Regardless of all the terminology though, yes, you can think of it as a smoothing function” – it’s “smoothing out” all the high frequency energy and leaving you with a slowly varying estimate of the mean value of the signal. If you then subtract this smoothed signal from the instantaneous signal then the difference will be the content that you have filtered out, i.e. the high frequency stuff, hence you get a high pass filter. In other words: `high_pass_filtered_signal = signal - smoothed_signal`.