arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
KalmanFilter Class Reference

Simple 1D Kalman Filter for smoothing measurements. More...

#include <KalmanFilter.h>

Public Member Functions

 KalmanFilter (float process_noise=0.01f, float measurement_noise=1.0f)
 Construct a new Kalman Filter object.
 
void addMeasurement (float measurement)
 Updates the filter with a new measurement and returns the filtered value.
 
bool begin ()
 Reset the filter state to zero, keeping the current noise parameters.
 
bool begin (float process_noise, float measurement_noise)
 reset the filter with new parameters
 
float calculate ()
 Returns the current estimated value.
 
void end ()
 End or clear the filter (sets the estimate to zero).
 

Protected Attributes

float K
 Kalman gain (K)
 
float P
 Estimation error covariance (P)
 
float Q
 Process noise covariance (Q)
 
float R
 Measurement noise covariance (R)
 
float X
 Estimated state (X)
 

Detailed Description

Simple 1D Kalman Filter for smoothing measurements.

This class implements a basic one-dimensional Kalman filter for smoothing noisy measurements. It is useful for sensor data fusion and signal processing applications where noise reduction is required.

The Kalman filter uses two main parameters:

Lower values for Q make the filter trust the model more (less responsive to changes), while higher values for R make the filter trust the measurements less (more smoothing).

Note
Reasonable defaults for many sensor applications are Q = 0.01 and R = 1.0, but these should be tuned for your specific use case.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ KalmanFilter()

KalmanFilter ( float  process_noise = 0.01f,
float  measurement_noise = 1.0f 
)
inline

Construct a new Kalman Filter object.

Parameters
process_noiseThe process noise covariance (Q). Default is 0.01.
measurement_noiseThe measurement noise covariance (R). Default is 1.0.

Member Function Documentation

◆ addMeasurement()

void addMeasurement ( float  measurement)
inline

Updates the filter with a new measurement and returns the filtered value.

Parameters
measurementThe new measurement to be filtered
Returns
float The updated (filtered) estimate

◆ begin() [1/2]

bool begin ( )
inline

Reset the filter state to zero, keeping the current noise parameters.

Returns
true Always returns true.

◆ begin() [2/2]

bool begin ( float  process_noise,
float  measurement_noise 
)
inline

reset the filter with new parameters

Parameters
process_noiseThe process noise covariance (Q). Default is 0.01.
measurement_noiseThe measurement noise covariance (R). Default is 1.0.

Initialize or reset the filter with new parameters.

Parameters
process_noiseThe process noise covariance (Q). Default is 0.01.
measurement_noiseThe measurement noise covariance (R). Default is 1.0.
Returns
true Always returns true.

◆ calculate()

float calculate ( )
inline

Returns the current estimated value.

Returns
float The current estimate

The documentation for this class was generated from the following file: