0
\$\begingroup\$

I' measuring linear acceleration (acceleration minus gravity) and gyroscope from Android smartphones on three axis (x,y,z). Becuase the distribution of the measurments is exponential, i.e. there are much more small values than large values, I would like to bin the sensor measurements using logarithmic binning into 96 bins. If I would use linear binning, I would have to clip the sensor measurements very heavy because otherwise most of the measurements will fall into the first few bins.

Right now I'm using the following bin edges (Python):

import numpy as np
bins = np.logspace(np.log10(0.001), np.log10(hi), num=96, base=10)

The problem here is that there are different types of logarithms (base e, 2, 10) and different starting points (here 0.001).

What is the best way to determine the best logarithmic binning?

Second, right now I'm clipping gyroscope values at 5 rad/s and linear acceleration values at 4*g. Is this reasonable or what are common values for clipping?

\$\endgroup\$
4
  • \$\begingroup\$ 1) Yes, I was drawing a histogram. What do you mean by using the histogram to have equal number of readings in each bin? 2) But with a different base I'm getting different bin edges 3) I'm taking the absolute values of the sensor measurements, so all values are positive. 4) I will use the binned data as input to a machine learning pipeline. So it it is just an encoding / simplification of the measurements into a 96 dimensional vector. \$\endgroup\$
    – machinery
    Commented May 31, 2021 at 13:45
  • \$\begingroup\$ @AJN Yes, roughly equal number of sample would make sense. How can I choose the logarithmic scale so that there are equal number of samples in each bin? \$\endgroup\$
    – machinery
    Commented May 31, 2021 at 14:00
  • \$\begingroup\$ Ignore my comment about equal spacing. i think that exponential random variable when binned in logarithmicaly spaced bins will automatically satisfy the equal number in each bin condition. I am not 100% sure about this. You can check it your self by varying the number of bins and seeing the result. \$\endgroup\$
    – AJN
    Commented May 31, 2021 at 14:03
  • 1
    \$\begingroup\$ You need to define "best". otherwise any input to logspace would be equally good ? \$\endgroup\$
    – AJN
    Commented May 31, 2021 at 14:04

1 Answer 1

1
\$\begingroup\$

The problem here is that there are different types of logarithms (base e, 2, 10) and different starting points (here 0.001).

I get the same bins for any base. see below. note the aproprate usage of log10, log and log2 functions which are consistent with the base= parameter.

>>> import numpy as np
>>> np.logspace(np.log10(0.1), np.log10(10), num=11, base=10)
array([ 0.1       ,  0.15848932,  0.25118864,  0.39810717,  0.63095734,
        1.        ,  1.58489319,  2.51188643,  3.98107171,  6.30957344,
       10.        ])

>>> np.logspace(np.log(0.1), np.log(10), num=11, base=2.718)
array([0.10002388, 0.15851959, 0.25122463, 0.39814519, 0.63098747,
       1.        , 1.58481752, 2.51164657, 3.98050148, 6.30836847,
       9.99761287])

>>> np.logspace(np.log2(0.1), np.log2(10), num=11, base=2)
array([ 0.1       ,  0.15848932,  0.25118864,  0.39810717,  0.63095734,
        1.        ,  1.58489319,  2.51188643,  3.98107171,  6.30957344,
       10.        ])

Second, right now I'm clipping gyroscope values at 5 rad/s and linear acceleration values at 4*g. Is this reasonable or what are common values for clipping?

That depends on your application.

5 rad/s is approximately 3/4 rotation per second. A highly agile quad copter would touch this limit. A model aircraft may not. A real aircraft shouldn't. A motor spinning at 100 RPM definitely would get clipped.

Similar for the 4g acceleration. A fighter aircraft may touch it during maneuvres; a civil aircraft (hopefully) won't. A quad copter might.

\$\endgroup\$
1
  • \$\begingroup\$ An android phone can definitely get clipped readings if it is dropped on a hard surface. The application and expected signals will be known only to you. \$\endgroup\$
    – AJN
    Commented May 31, 2021 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.