日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁(yè) > 物聯(lián)網(wǎng)與傳感器 > 設(shè)計(jì)應(yīng)用 > 傳感器算法處理:加權(quán)平滑\\簡(jiǎn)單移動(dòng)平均線\\抽取突變

          傳感器算法處理:加權(quán)平滑\\簡(jiǎn)單移動(dòng)平均線\\抽取突變

          作者: 時(shí)間:2017-10-14 來(lái)源:網(wǎng)絡(luò) 收藏

            通過(guò)利用先進(jìn)的庫(kù),智能手機(jī)和平板OEM廠商就能讓開(kāi)發(fā)者能夠追蹤智能手機(jī)和用戶的移動(dòng)軌跡。通過(guò)觀察移動(dòng)軌跡,應(yīng)用程序就能讓用戶與設(shè)備以創(chuàng)新、方便的手勢(shì)進(jìn)行交互。例如,當(dāng)用戶把手機(jī)放在耳朵旁邊的時(shí)候,程序就能自動(dòng)接收音頻指令。

          本文引用地址:http://yuyingmama.com.cn/article/201710/366215.htm

            然而,最流行的移動(dòng)應(yīng)用程序卻不常用到。應(yīng)用程序開(kāi)發(fā)者說(shuō)用很難,沒(méi)錯(cuò),這是因?yàn)閭鞲衅魇怯脕?lái)度量物理環(huán)境的,但沒(méi)有好的想法或用法,這些測(cè)量經(jīng)常沒(méi)有意義。

            現(xiàn)在,傳感器廠商意識(shí)到了和軟件才是產(chǎn)品最基本的要素。獨(dú)立的固件開(kāi)發(fā)者開(kāi)發(fā)了傳感器庫(kù),不但能保持傳感器處在校準(zhǔn)狀態(tài)從而提供準(zhǔn)確的導(dǎo)航,還能減輕外界電磁干擾造成的影響。

            一、在傳感器使用中,我們常常需要對(duì)傳感器數(shù)據(jù)進(jìn)行各種整理,讓?xiě)?yīng)用獲得更好的效果,以下介紹幾種常用的簡(jiǎn)單處理方法:

            1.加權(quán)平滑:平滑和均衡傳感器數(shù)據(jù),減小偶然數(shù)據(jù)突變的影響;

            2.抽取突變:去除靜態(tài)和緩慢變化的數(shù)據(jù)背景,強(qiáng)調(diào)瞬間變化;

            3.簡(jiǎn)單移動(dòng)平均線:保留數(shù)據(jù)流最近的K個(gè)數(shù)據(jù),取平均值;

            二、加權(quán)平滑

            使用如下:

           ?。ㄐ轮担?= (舊值)*(1 - a) + X * a其中a為設(shè)置的權(quán)值,X為最新數(shù)據(jù),程序?qū)崿F(xiàn)如下:

            float ALPHA = 0.1f;

            public void onSensorChanged(SensorEvent event){

            x = event.values[0];

            y = event.values[1];

            z = event.values[2];

            mLowPassX = lowPass(x,mLowPassX);

            mLowPassY = lowPass(x,mLowPassY);

            mLowPassZ = lowPass(x,mLowPassZ);

            }

            private float lowPass(float current,float last){

            return last * (1.0f - ALPHA) + current * ALPHA;

            }

            三、抽取突變

            采用上面加權(quán)平滑的逆。實(shí)現(xiàn)代碼如下:

            public void onSensorChanged(SensorEvent event){

            final float ALPHA = 0.8;gravity[0] = ALPHA * gravity[0] + (1-ALPHA) * event.values[0];

            gravity[1] = ALPHA * gravity[1] + (1-ALPHA) * event.values[1];

            gravity[2] = ALPHA * gravity[2] + (1-ALPHA) * event.values[2];filteredValues[0] = event.values[0] - gravity[0];

            filteredValues[1] = event.values[1] - gravity[1];

            filteredValues[2] = event.values[2] - gravity[2];

            }

            四、簡(jiǎn)單移動(dòng)平均線

            保留傳感器數(shù)據(jù)流中最近的K個(gè)數(shù)據(jù),返回它們的平均值。k表示平均“窗口”的大?。?/p>

            實(shí)現(xiàn)代碼如下:

            public class MovingAverage{

            private float circularBuffer[]; //保存?zhèn)鞲衅髯罱腒個(gè)數(shù)據(jù)

            private float avg; //返回到傳感器平均值

            private float sum; //數(shù)值中傳感器數(shù)據(jù)的和

            private float circularIndex; //傳感器數(shù)據(jù)數(shù)組節(jié)點(diǎn)位置

            private int count;public MovingAverage(int k){

            circularBuffer = new float[k];

            count= 0;

            circularIndex = 0;

            avg = 0;

            sum = 0;

            }

            public float getValue(){

            return arg;

            }

            public long getCount(){

            return count;

            }

            private void primeBuffer(float val){

            for(int i=0;i《circularbuffer.length;++i){

            circularBuffer[i] = val;

            sum += val;

            }

            }

            private int nexTIndex(int curIndex){

            if(curIndex + 1 》= circularBuffer.length){

            return 0;

            }

            return curIndex + 1;

            }

            public void pushValue(float x){

            if(0 == count++){

            primeBuffer(x);

            }

            float lastValue = circularBuffer[circularIndex];

            circularBuffer[circularIndex] = x; //更新窗口中傳感器數(shù)據(jù)

            sum -= lastValue; //更新窗口中傳感器數(shù)據(jù)和

            sum += x;

            avg = sum / circularBuffer.length; //計(jì)算得傳感器平均值

            circularIndex = nexTIndex(circularIndex);

            }

            }



          關(guān)鍵詞: 算法 傳感器

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉