Question

There are a number of posts about Android sensor data being very noise, and suggestions on implementing a smoothing algorithm such as low-pass filter. I am reading low-pass filter and I found that I have to calculate the smoothing parameter ALPHA. Everyone comes with different ALPHA. However, I am so confused because there is not consistent between wiki and Android developer website.

Two formulas will produce two different ALPHA. This make me so confused. Which formula is correct? Everyone could give me the explanation?

Thank in advance.

Was it helpful?

Solution 2

A lowpass filter is supposed to let in low frequencies and elimiate high frequencies. So the wikipedia version looks right to me- for a low frequency, dT should be big, for a high frequency it should be small.

However, I'd really suggest either hiring someone who knows DSP or doing some more research before blindly implementing a filter. These things are quite complex and a simple filter will often have negative side effects. You spend a year or so studying these if you become an electrical engineer. Odds of getting it right the first time on your own are fairly low, unless you use a library. And then the risk changes to using the wrong type of filter or configuring the constants wrong.

The filters shown by Wikipedia are about the simplest possible and have the most side effects, FYI.

OTHER TIPS

Let's compare the two versions!

Here I use a time constant 'tau'

Alpha_A = dt / (dt + tau)
Alpha_B = tau / (tau + dt)

Let's put some values into it. Let's try:

dt = 0.5, tau = 1;
Alpha_A = 0.5 / (0.5 + 1.0) = 1/3
Alpha_B = 1.0 / (1.0 + 0.5) = 2/3

So therefore:

Alpha_A = 1 - Alpha_B

It comes down to how you defined the low-pass filter. Is it:

New_Filtered = New_Raw * Alpha + Prev_Filtered * (1-Alpha)

or

New_Filtered = New_Raw * (1-Alpha) + Prev_Filtered * Alpha

IE does Alpha work on the raw data directly, or the previous filtered data?

Effectively they do the same thing!

The one posted on the Wikipedia site is correct, providing that end user wants alpha (the smoothing constant) to be equal to 1 when no filtering is desired. That is from the classic definition for alpha, such that the output from an iterative filter remains unfiltered when alpha = 1.

if ( first_pass ) {
    Vn-1 = 0;
    first_pass = false;
} else {
    Vn+1 = Vn-1 + alpha * (Vn - Vn-1);
    Vn-1 = Vn+1;
    Vn = Vn+1;
}

Note that in the above iterative algorithm, Vn+1 remains always equal to Vn when alpha = 1.

I would suspect that the alpha used on the Android developer site was designed to go to zero when the time constant equals zero. That could be by design if the Android developer needed 0 for the smoothing constant when no filtering is desired.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top