# Verifying the result from lowpass filter

I have a event record from acceleration censer.

I'm trying to remove gravity from the event record by low/high pass filter as following site shows.

https://developer.android.com/reference/android/hardware/SensorEvent#values

As the first step I tried to extract Gravity by using following formula as a low pass filter.

G[t] = 0.1*G[t-1]+(1-0.1)*a[t]

G[t] is extracted gravity as the result.
G[t-1] is previous result .
a[t] is censer value in current row of event record.


I calculated it on Excel sheet for each X,Y,Z axis. And I'd like to know how to verify the result.

I thought I can verify by summarizing G value for X,Y,Z from low pass filter will be 1023 based on following picture.

Green is X

Blue is Y

Red is Gravity

G only weighs on Y at the first.

After rotate X-Y,G will weigh on both X and Y.

There will be G on X and G on Y

However, Gx+Gy+Gz is not 1023 during censing so far.

Here is top 8 line of the data.

time-x  x   time y  y   time-z  z   time-zz zz
0   904 0   -20 0   504 0   -320
0.006   892 0.004   -16 0.006   504
0.008   888 0.015   -4  0.015   488
0.02    888 0.018   8   0.02    492
0.022   892 0.022   16  0.022   492
0.031   876 0.029   20  0.032   500
0.034   876 0.034   4   0.038   496
0.049   884 0.051   4   0.056   488


To eliminate gravity you need a high pass filter. From your source

This can be achieved by applying a high-pass filter. Conversely, a low-pass filter can be used to isolate the force of gravity.

You implemented a low pass filter. Instead try

$$G[n] = p \cdot G[n-1] + 0.5 \cdot (1-p) \cdot (a[n]-a[n-1])$$

where p is the location of your pole. I would start with $$p = 0.9$$

And I'd like to know how to verify the result.

Same you should do with any algorithm

1. Write down the math of the algorithm
2. Select some suitable test signals where you can pre-calculated the result
3. Run the test signals through your implementation and check whether the results match.
4. Verify all other quantitative requirements

So in your case, you should run a constant signal through and check whether the output is zero and you should run a sine wave at different frequencies to it and verify that the output is indeed a sine wave at the same frequency and that the gain at the corner frequency is $$\sqrt{1/2}$$