denyssene / simplekalmanfilter Goto Github PK
View Code? Open in Web Editor NEWA basic implementation of Kalman Filter for single variable models.
License: MIT License
A basic implementation of Kalman Filter for single variable models.
License: MIT License
Hello,
Good day.
Does this library support STM32 blue pill? As Bluepill is a 32-bit MCU.
Please let me know.
Please, if possible, add some example to use the lib for filter an RSSI signal (from BLE or Wifi).
In the altitude example or the basic example
this type of construct
if (millis() > refresh_time) {
...
refresh_time=millis()+SERIAL_REFRESH_TIME;
}
will lead to an incorrect behaviour
Not only refresh_time
as a signed long
so will become negative (so best would be to declare it as unsigned long
, which is millis() returned type) but in ~50 days refresh_time
will rollover to 0 whilst millis()
will stay at a huge value and thus you'll trigger the display right away.
the typical way to handle this is through subtraction, not addition. I suggest the following code
#include <SimpleKalmanFilter.h>
/*
This sample code demonstrates how to use the SimpleKalmanFilter object.
Use a potentiometer in Analog input A0 as a source for the reference real value.
Some random noise will be generated over this value and used as a measured value.
The estimated value obtained from SimpleKalmanFilter should match the real
reference value.
SimpleKalmanFilter(e_mea, e_est, q);
e_mea: Measurement Uncertainty
e_est: Estimation Uncertainty
q: Process Noise
*/
SimpleKalmanFilter simpleKalmanFilter(2, 2, 0.01);
// Serial output refresh time
const unsigned long SERIAL_REFRESH_TIME = 100;
unsigned long last_refresh_time = -SERIAL_REFRESH_TIME;
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect. Needed for native USB boards
}
void loop() {
// read a reference value from A0 and map it from 0 to 100
float real_value = analogRead(A0) / 1023.0 * 100.0;
// add a noise to the reference value and use as the measured value
float measured_value = real_value + random(-100, 100) / 100.0;
// calculate the estimated value with Kalman Filter
float estimated_value = simpleKalmanFilter.updateEstimate(measured_value);
// send to Serial output every SERIAL_REFRESH_TIME ms (here every 100ms)
// use the Serial Ploter for a good visualization
if (millis() - last_refresh_time >= SERIAL_REFRESH_TIME) {
Serial.print(real_value, 4);
Serial.write(',');
Serial.print(measured_value, 4);
Serial.write(',');
Serial.println(estimated_value, 4);
last_refresh_time += SERIAL_REFRESH_TIME; // or last_refresh_time = millis();
}
}
same approach would also work for the altitude example.
Hi! Compared to Professor Michel van Biezen lectures, in the following line:
where this additional formula + fabsf(_last_estimate-_current_estimate)*_q
not explained by the Pr comes from? I remember when I tried Pr formulas, my Kalman did not succeed to filter high fluctuations in the signal, with this extra code it works.
Thanks!
With the current behaviour the Filter starts at 0. This results in a high error estimate at the beginning.
What about setting the first value as the start value instead? the starting error estimate would have more impact then.
A possible implementation of this could be the following code. the Gain can never be 0 with a positive error in the measurement so this is only the case for the first value.
float SimpleKalmanFilter::updateEstimate(float mea)
{
if (_kalman_gain == 0.0) {
_last_estimate = mea;
}
[…]
}
Is this useful? Or do is miss something?
Per arduino/Arduino#10119 (comment) it looks like one should update the version in
SimpleKalmanFilter/library.properties
Line 2 in 1520d80
Also update the version in
SimpleKalmanFilter/library.json
Line 9 in 1520d80
Otherwise the code and documentation won't match the version installed by Arduino.
Hi,
I must say this was the best library I found in a while. Kalman filter is just what I was missing in my project. I have tried all sorts of averages moving averages IIR FIR but this filter is just superb at filtering noise while still having decent response time.
I am not really strong at this level of mathematics and I was wondering if you could explain fine tuning of this filter.
I just would like to know how the filter actually changes with change in those constants e_mea, q and if I understand correctly e_est don't have to worry about since the filter adjusts it anyway.
I can see that if I increase e_mea or decrease q the response is slower but I would love to be able to fine tune and understand how to fine tune the filter. Can you give me some sort of kalman filter for dummies info, please?
thank you
Josef
The repository has a code version of 0.1.1, but Arduino Library manager won't share it until you post a 0.1.1 release on https://github.com/denyssene/SimpleKalmanFilter/releases
See:
and
I would like to request a new feature.
It would be nice to have a version that accepts two values, the value to be filtered, and the values weight.
The weight is used as a means to tell the filter how much influence the current value should have on the next estimate.
Is this something we can implement?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.