Is there a function in java to get moving average

后端 未结 7 1812
囚心锁ツ
囚心锁ツ 2020-12-14 16:14

I have a situation where I need to process 5000 samples from a device in every 0.5 sec.

Lets say the window size is 100, then there would be 50 points resulting fro

7条回答
  •  北海茫月
    2020-12-14 16:59

    static int[] myIntArray = new int[16];
    public static double maf(double number)
    {
        double avgnumber=0;
        for(int i=0; i<15; i++)
        {
            myIntArray[i] = myIntArray[i+1];
        }
        myIntArray[15]= (int) number;
        /* Doing Average */
        for(int  i=0; i<16; i++)
        {
            avgnumber=avgnumber+ myIntArray[i];
        }
        return avgnumber/16;
    
    }
    

    this algorithm can also be called as Moving Average Filter which is working well for me ... i implemented this algo in my graph project!

提交回复
热议问题