【问题标题】:Smoothing algorithm that doesn't miss the bell curve不会错过钟形曲线的平滑算法
【发布时间】:2014-01-11 21:29:55
【问题描述】:

我正在编写一个 android 应用程序来测量位置变化时的高度。

我想查看用户是上山还是下山(乘坐电梯或骑山地自行车)。下坡时自然会有小幅度的上升,而上坡时可以稍微下坡。

我有一个平滑算法,它取前十个高度读数的平均值和接下来十个的平均值,然后比较两者的增加或减少。

这大致具有我正在寻找的效果,除了它错过了钟形曲线之外,还有一些我不想看到的普遍上升的下降区域。

统计数据不是我的强项,但有没有更好的方法来平滑这些数据?

这是我的代码

qu="SELECT ID,SPEED,ALTITUDE,ISCLIMB from trip_data where tripid="+Tripid+" order by gmttimestamp;";
    c= db.rawQuery(qu, null);
    if(c!=null && c.moveToFirst())
    {
        int av=10;
        for(int i=av;i<c.getCount()-av;i++)
        {

            double prevAlt=0;
            double nxtAlt=0;
            for(int b=0;b<av;b++)
            {
                c.moveToPosition(i-b);
                prevAlt+=c.getDouble(2);
            }
            prevAlt/=av;
            lastAlt=curAlt;
            c.moveToPosition(i);
            int id=c.getInt(0);
            curSpeed=c.getDouble(1);
            curAlt=c.getDouble(2);
            for(int b=1;b<av+1;b++)
            {
                c.moveToPosition(i+b);
                nxtAlt+=c.getDouble(2);
            }
            nxtAlt/=av;
            int isC=0;
            Log.i("corrections", "preivous ="+prevAlt+" and the next is "+nxtAlt);
            db.execSQL("UPDATE TRIP_DATA set PREVALT ="+prevAlt+", NEXTALT="+nxtAlt+", DALT="+(curAlt-lastAlt)+" where id="+id+"");
            if(nxtAlt>prevAlt)
            {
                isC=1;
            }else
            {
                isC=0;
            }

            String ins="UPDATE trip_data set ISCLIMB="+isC+" where ID="+id+";";
            db.execSQL(ins);
            Log.i("corrections", ins);
        }

【问题讨论】:

    标签: android algorithm


    【解决方案1】:

    看看Savitsky-Golay 过滤器。他们给每个点一个权重。

    您甚至可以使用它们直接计算平滑的一阶导数。

    例如,使用 5 点二次滤波器(数组中的所有点)从点 i 获取导数:

    // coefficients for 5 point 1ste derative
    // -2, -1, 0, 1, 2
    // factor = 10
    double derative = (point[x - 2] * -2 + point[x - 1] * -1 + point[x] * 0 + point[x + 1] * 1 + point[x + 2] * 2) / 10;
    

    【讨论】:

    • 我做最后十个 ALT (n-1 *10)+(n-2 *9)/10 有什么好处! (其中!表示阶乘而不是非运算符)给出加权平均值?如果这不是你在说的,请告诉我