Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement a Highpass filter for the IPhone accelerometer?

Tags:

iphone

I remember seeing the code for a Highpass filter a few days back somewhere in the samples, however I can't find it anywhere now! Could someone remember me where the Highpass filter implementation code was?

Or better yet post the algorithm?

Thanks!

like image 898
Robert Gould Avatar asked Sep 27 '08 03:09

Robert Gould


People also ask

Why low-pass filter is used in accelerometer?

The total noise power at the output of a system directly depends on the system bandwidth. That's why we need a low-pass filter to limit the bandwidth to the maximum frequency needed by the application. This maximizes the resolution and dynamic range of the accelerometer.

How do you use a high pass filter?

High pass filters are most commonly used to remove low-frequency content that is not within an instrument's frequency range. As a general starting point, you should place a high pass filter on each channel and adjust it according to the lowest frequency the sound source can produce.

What is the difference between a low-pass and a high pass filter & How does it work?

A high-pass filter (HPF) attenuates content below a cutoff frequency, allowing higher frequencies to pass through the filter. A low-pass filter (LPF) attenuates content above a cutoff frequency, allowing lower frequencies to pass through the filter.

What is a high pass filter and what does it do?

A high pass filter is a simple, effective type of EQ curve, one that scoops out unwanted low frequencies from any audio source. They are fantastic when used correctly to clean up woofy signals and tighten up arrangements. When used incorrectly, they can cause more problems than they solve.


2 Answers

From the idevkit.com forums:

#define kFilteringFactor 0.1
static UIAccelerationValue rollingX=0, rollingY=0, rollingZ=0;


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

    // Calculate low pass values

    rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
    rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
    rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

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

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

    // Use the acceleration data.

}
like image 177
Adam Davis Avatar answered Oct 27 '22 16:10

Adam Davis


Just in case someone wants to know, the highpass filter can be found in the Accelerometer Graph sample.

like image 26
Mike Akers Avatar answered Oct 27 '22 16:10

Mike Akers