Dear folks,
How to adjust the below functions using the Kalman filter library.
SimpleKalmanFilter pressureKalmanFilter(1, 1, 0.01);
// read a reference value from A0 and map it from 0 to 100
float real_value = analogRead(A0)/1024.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);
Please refer the link: SimpleKalmanFilter/BasicKalmanFilterExample.ino at master · denyssene/SimpleKalmanFilter · GitHub
In my case sensor gives with noise value so real_value and measured_value are the same.
Thank you in advance.
J-M-L
June 8, 2022, 9:19am
2
The lines
// add a noise to the reference value and use as the measured value
float measured_value = real_value + random(-100,100)/100.0;
are in the demo code to generate additional noise. You don't want/need that in your code.
what's your exact question?
Dear J-M-L,
Thank you for your response.
How to tune this values in "SimpleKalmanFilter pressureKalmanFilter(1, 1, 0.01)"?
Could you please explain these below three terms with an example?
SimpleKalmanFilter(e_mea, e_est, q);
e_mea: Measurement Uncertainty
e_est: Estimation Uncertainty
q: Process Noise
Assume my sensor's output is a mixing of noise and Fluctuating between 1.1 to 1.7 values.
Thank you in advance
Dear J-M-L,
Thank you for your quick response,
My value fluctuates between 1.2 to 1.7, So It means
e_mea= 0.5
e_est= 0.5
q= 0.01
Please revert if I'm wrong.
Thank you in advance.
For best operations use the setProcessNoise() property to update the reading times.
void fReadBattery( void * parameter )
{
const float r1 = 50500.0f; // R1 in ohm, 50K
const float r2 = 10000.0f; // R2 in ohm, 10k potentiometer
const TickType_t xFrequency = 1000; //delay for mS
float adcValue = 0.0f;
float Vbatt = 0.0f;
int printCount = 0;
float vRefScale = (3.3f / 4096.0f) * ((r1 + r2) / r2);
uint64_t TimePastKalman = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
TickType_t xLastWakeTime = xTaskGetTickCount();
for (;;)
{
adc1_get_raw(ADC1_CHANNEL_0); //read and discard
adcValue = float( adc1_get_raw(ADC1_CHANNEL_0) ); //take a raw ADC reading
KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
adcValue = KF_ADC_b.updateEstimate( adcValue ); // apply simple Kalman filter
Vbatt = adcValue * vRefScale;
xSemaphoreTake( sema_CalculatedVoltage, portMAX_DELAY );
CalculatedVoltage = Vbatt;
xSemaphoreGive( sema_CalculatedVoltage );
printCount++;
if ( printCount == 3 )
{
//log_i( "Vbatt %f", Vbatt );
printCount = 0;
}
TimePastKalman = esp_timer_get_time(); // time of update complete
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil( &xLastWakeTime, xFrequency );
//log_i( "fReadBattery %d", uxTaskGetStackHighWaterMark( NULL ) );
}
vTaskDelete( NULL );
}
J-M-L
June 8, 2022, 12:15pm
7
That's the range of your data, it's not the Measurement Uncertainty . (or did you mean you get a varying value of 1.2 to 1.7 by measuring a known, unchanging reference??)
In Kalman's world, the measurement uncertainty is the variance of the measurement errors. this is often provided by the sensor's vendor or can be derived by a calibration procedure (you know the true value, you make say 100 measures and calculate the variance of the error between the measurement and true value)
Dear J-M-L,
I'm sensing an RH value with my Arduino setup is flutes between 1.2 to 1.7 every ten seconds once a 2.2 value shows.
I have an RH Master meter it is showing a constant value of 1.55.
Could you please give me some guidance on how to approach the Kalman?
Thank you in advance.
Dear Idahowalker,
Thank you for your response,
I'm not able to understand the logic of the code, My request could you please make a code for sensing the sensor voltage (0V to 1V/1000mV). The sensor gives noise value including actual value.
Thank you in advance.
J-M-L
June 9, 2022, 9:23am
10
so you are saying the true value si 1.55 and the Arduino sees between 1.20 and 1.70
run 100 measurements and calculate the variance of the measurement errors.
Dear J-M-L,
Thank you for your quick response.
Okay I got the variance of the measurement error.
May I know the Next step please?
Thank you in advance.
J-M-L
June 10, 2022, 6:36am
12
You use that for the first two parameters and something small for the last one
system
Closed
December 7, 2022, 6:36am
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.