如何在android中使用加速度计计算准确的步数? [英] how to calculate exact foot step count using accelerometer in android?

查看:28
本文介绍了如何在android中使用加速度计计算准确的步数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 算法 开发一些应用程序,如 Runtastic Pedometer,但我没有得到任何结果之间的相似性.

I am developing some application like Runtastic Pedometer using the algorithm but I am not getting any similarity between the results.

我的代码如下:

public void onSensorChanged(SensorEvent event) 
{
        Sensor sensor = event.sensor; 
        synchronized (this)
 {
            if (sensor.getType() == Sensor.TYPE_ORIENTATION) {}
            else {
            int j = (sensor.getType() == Sensor.TYPE_ACCELEROMETER) ? 1 : 0;
                if (j == 1) {
                    float vSum = 0;
                    for (int i=0 ; i<3 ; i++) {
                        final float v = mYOffset + event.values[i] * mScale[j];
                        vSum += v;

                    }
                    int k = 0;
                    float v = vSum / 3;
                    //Log.e("data", "data"+v);

                    float direction = (v > mLastValues[k] ? 1 : (v < mLastValues[k] ? -1 : 0));
                    if (direction == - mLastDirections[k]) {
                        // Direction changed
                        int extType = (direction > 0 ? 0 : 1); // minumum or maximum?
                        mLastExtremes[extType][k] = mLastValues[k];
                        float diff = Math.abs(mLastExtremes[extType][k] - mLastExtremes[1 - extType][k]);

                        if (diff > mLimit) {

                            boolean isAlmostAsLargeAsPrevious = diff > (mLastDiff[k]*2/3);
                            boolean isPreviousLargeEnough = mLastDiff[k] > (diff/3);
                            boolean isNotContra = (mLastMatch != 1 - extType);

                            if (isAlmostAsLargeAsPrevious && isPreviousLargeEnough && isNotContra) {

                                for (StepListener stepListener : mStepListeners) {
                                    stepListener.onStep();
                                }
                                mLastMatch = extType;
                            }
                            else {
                                Log.i(TAG, "no step");
                                mLastMatch = -1;
                            }
                        }
                        mLastDiff[k] = diff;
                    }
                    mLastDirections[k] = direction;
                    mLastValues[k] = v;
                }
            }
        }
    }

用于注册传感器:

mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        mSensor = mSensorManager.getDefaultSensor(
                Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(mStepDetector,mSensor,SensorManager.SENSOR_DELAY_NORMAL);

在算法中我有不同的敏感度作为公共无效

in the algorithm i have different levels for sensitivity as public void

setSensitivity(float sensitivity) {
        mLimit = sensitivity; // 1.97  2.96  4.44  6.66  10.00  15.00  22.50  33.75  50.62
    }

在各种敏感度水平上,我的结果是:

on various sensitivity level my result is:

sensitivity   rantastic pedometer  my app
10.00           3870                 5500
11.00           3000                 4000
11.15           3765                 4576
13.00           2000                 890
11.30           754                  986

我没有得到任何符合要求的正确模式.根据我的分析,此应用程序使用 Sensor.TYPE_MAGNETIC_FIELD 进行步数计算,请告诉我一些算法,以便我满足要求.

I am not getting any proper pattern to match with the requirement. As per my analysis this application is using Sensor.TYPE_MAGNETIC_FIELD for steps calculation please let me know some algorithm so that I can meet with the requirement.

推荐答案

您需要做的第一件事是确定算法.据我所知,文献中描述的使用加速度计检测步数的方法大致分为三种:

The first thing you need to do is decide on an algorithm. As far as I know there are roughly speaking three ways to detect steps using accelerometers that are described in the literature:

  1. 使用勾股定理计算来自加速度计的每个样本的加速度矢量的大小.对幅度信号进行低通滤波以去除高频噪声,然后在滤波后的信号中寻找波峰和波谷.您可能需要添加其他要求以消除误报.这是迄今为止最简单的步数检测方法,也是您可以从体育用品商店购买的大多数普通计步器的工作方式.

  1. Use the Pythagorean theorem to calculate the magnitude of the acceleration vector of each sample from the accelerometer. Low-pass filter the magnitude signal to remove high frequency noise and then look for peaks and valleys in the filtered signal. You may need to add additional requirements to remove false positives. This is by far the simplest way to detect steps, it is also the way that most if not all ordinary pedometers of the sort that you can buy from a sports store work.

像 (1) 中那样使用毕达哥拉斯,然后通过 FFT 运行信号并将 FFT 的输出与已知的步行输出进行比较.这要求您能够访问相当大量的训练数据.

Use Pythagoras' like in (1), then run the signal through an FFT and compare the output from the FFT to known outputs of walking. This requires you to have access to a fairly large amount of training data.

将加速度计数据输入到使用一些合适的机器学习技术的算法中,例如神经网络或数字小波变换.您当然可以在这种方法中包含其他传感器.这还要求您能够访问相当大量的训练数据.

Feed the accelerometer data into an algorithm that uses some suitable machine learning technique, for example a neural network or a digital wavelet transform. You can of course include other sensors in this approach. This also requires you to have access to a fairly large amount of training data.

确定算法后,您可能希望使用 Matlab 或 SciPy 之类的工具,使用在 Android 手机上录制的录音在计算机上测试您的算法.将加速度计数据转储到手机上的 cvs 文件中,记录该文件代表的步数,将文件复制到您的计算机并在数据上运行算法以查看步数是否正确.这样你就可以检测算法的问题并纠正它们.

Once you have decided on an algorithm you will probably want to use something like Matlab or SciPy to test your algorithm on your computer using recordings that you have made on Android phones. Dump accelerometer data to a cvs file on your phone, make a record of how many steps the file represents, copy the file to your computer and run your algorithm on the data to see if it gets the step count right. That way you can detect problems with the algorithm and correct them.

如果这听起来很困难,那么获得良好步数检测的最佳方法可能是等到更多手机配备 KitKat 启用的内置步数计数器.

If this sounds difficult, then the best way to get access to good step detection is probably to wait until more phones come with the built-in step counter that KitKat enables.

这篇关于如何在android中使用加速度计计算准确的步数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆