How to implement Kalman filter in Java

Kalman filter that can filter anything and can be easily implemented! Since there was no implementation example in Java, I will write it as a memo.

    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;
        //Argument specification 1 sigmaW, 2 sigmaV
        sigmaW = Integer.parseInt("5");
        sigmaV = Integer.parseInt("50");
        Scanner sc  = new Scanner(;

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



The degree of filtering depends on the combination of sigmaW and sigmaV.

By using this and making it into an API, you can filter various numerical values.

Although it is output as a list here, it is also possible to output the value in real time.

Recommended Posts

How to implement Kalman filter in Java
How to implement date calculation in Java
How to implement coding conventions in Java
[Java] How to implement multithreading
Summary of how to implement default arguments in Java
How to learn JAVA in 7 days
How to use classes in Java?
How to name variables in Java
Try to implement Yubaba in Java
How to concatenate strings in java
How to implement search functionality in Rails
Multilingual Locale in Java How to use Locale
Try to implement n-ary addition in Java
How to filter JUnit Test in Gradle
How to do base conversion in Java
How to embed Janus Graph in Java
How to get the date in java
How to implement ranking functionality in Rails
How to implement asynchronous processing in Outsystems
How to implement a job that uses Java API in JobScheduler
How to display a web page in Java
I tried to implement deep learning in Java
How to get Class from Element in Java
How to hide null fields in response in Java
How to implement a like feature in Rails
How to implement optimistic locking in REST API
[Java] How to substitute Model Mapper in Jackson
How to solve an Expression Problem in Java
How to write Java String # getBytes in Kotlin?
How to implement Pagination in GraphQL (for ruby)
How to implement UICollectionView in Swift with code only
[Java] How to use Map
How to call functions in bulk with Java reflection
How to create a Java environment in just 3 seconds
[Java] How to omit the private constructor in Lombok
How to implement guest login in 5 minutes in rails portfolio
How to lower java version
[Java] How to use Map
How to implement a like feature in Ajax in Rails
How to uninstall Java 8 (Mac)
I tried to implement Firebase push notification in Java
Java --How to make JTable
How to input / output IBM mainframe files in Java?
How to use java Optional
How to minimize Java images
How to write java comments
Implement two-step verification in Java
How to use java class
[Java] How to use Optional ②
How to create a data URI (base64) in Java
[Java] How to use removeAll ()
[Java] How to display Wingdings
Implement Basic authentication in Java
[Java] How to use string.format
How to use Java Map
Implement math combinations in Java
How to set Java constants
2 Implement simple parsing in Java
How to generate / verify ID token in Java Memo
Implement Email Sending in Java
How to convert A to a and a to A using AND and OR in Java