1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Javaによるカルマンフィルターの実装方法

Last updated at Posted at 2017-12-02

なんでもフィルタリングできて手軽に実装できるカルマンフィルター!
Javaでの実装例がなかったのでメモとして書いておきます。

    public static void main(String[] args){
        ArrayList<Double> result = new ArrayList<Double>();
        double now = 0;
        double xPre = 0;
        double pPre = 0;
        double  sigmaW = 0;
        double sigmaV = 0;
        //引数指定 1 sigmaW , 2 sigmaV
        sigmaW = Integer.parseInt("5");
        sigmaV = Integer.parseInt("50");
        Scanner sc  = new Scanner(System.in);
        while(true){

            now = sc.nextDouble();
            if(now == -1){
                break;
            }
            double xForecast = xPre;
            double pForecast = pPre + sigmaW;
            double KGain = pForecast/(pForecast + sigmaV);
            double  xFiltered = (xForecast + KGain*(now - xForecast));
            double pFiletered = (1-KGain) * pForecast;
            result.add(xFiltered);
            System.out.println(xFiltered);
            xPre = xFiltered;
            pPre = pFiletered;
        }
        System.out.println("-------------------------------");
        for(Double out : result){
            System.out.println(out);

        }

    }

sigmaWとsigmaVの組み合わせによってフィルタリングの度合いが変わってきます。

これを利用してAPI化することによって様々な数値をフィルタリングさせることができます。

ここではリストとして出力しているがリアルタイムで値を出力させることもできます。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?