Kalman Filter for Noise Reducer on Sensor Readings

a,d Department of Electrical Engineering, Universitas Ahmad Dahlan, Yogyakarta, Indonesia b Department of Electrical Engineering, Universitas Muhammadiyah Yogyakarta, Yogyakarta, Indonesia c Department of Information Technology and Electrical Engineering, Universitas Gadjah Mada, Yogyakarta, Indonesia 1 alfianmaarif@ee.uad.ac.id*; 2iswanto_te@umy.ac.id; 3 anindityanuryono@gmail.com; 4 rio1600022036@webmail.uad.ac.id


Introduction
High-sensitivity sensors are very vulnerable to noise when reading data from environment [1]. Vibration, wind pressure, are some examples of external disturbances which cause noise on datareading. Meanwhile, most systems nowadays require high-sensitivity sensors to increase its system performances [2] [3]. In example, high-sensitivity accelerometer and gyro are needed in robot systems [4] [5] [6], quad-rotors [7] and maglev systems [8]. These sensors are commonly being uncovered from external disturbances such as wind pressure and vibration of rotors. This can result noise on datareadings. For example, Fig. 1 shows the unfiltered result of ADC readings of an accelerometer of an unmoving balancing wheel. Based on Fig. 1, it can be known that sensor readings are affected by noise or disturbances since the result are varying for an unmoving robot.
Noise on data-readings can be fatal since the real measured-data are used as an input to a controller. High-sensitivity sensors contribute to the sensitivity of a controller. If noise is calculated as the measurement data, the control system cannot achieve its best performances or even fail to control the system. As for previous case of a varying data result taken from an accelerometer of unmoving balancing robot, the noise could affect the controller's performance as the controller will respond to the 'error', which causes by the difference of the result from sensor's readings with the referenced Most systems nowadays require high-sensitivity sensors to increase its system performances. However, high-sensitivity sensors, i.e. accelerometer and gyro, are very vulnerable to noise when reading data from environment. Noise on data-readings can be fatal since the real measured-data contribute to the performance of a controller, or the augmented system in general. The paper will discuss about designing the required equation and the parameter of modified Standard Kalman Filter for filtering or reducing the noise, disturbance and extremely varying of sensor data. The Kalman Filter equation will be theoretically analyzed and designed based on its component of equation. Also, some values of measurement and variance constants will be simulated in MATLAB and then the filtered result will be analyzed to obtain the best suitable parameter value. Then, the design will be implemented in real-time on Arduino to reduce the noise of IMU (Inertial Measurements Unit) sensor reading. Based on the simulation and real-time implementation result, the proposed Kalman filter equation is able to filter signal with noises especially if there is any extreme variation of data without any information available of noise frequency that may happen to sensorreading. The recommended ratio of constants in Kalman Filter is 100 with measurement constant should be greater than process variance constant.
acceleration. The controller may become too aggressive while controlling the robot's movement. Furthermore, this will result to bad system's performances i.e. uneven trajectory of the robot's movement.

Unfiltered accelerometer result of unmoving robot
Ideally, all of the noise from the readings should be cancelled for high-sensitivity sensors. However, it is practically impossible to cancel all the noise since it happens due to external environment natures. Other options available are to reduce the noise or to separate the noise from the real measurement data.
Most common filters, such as Low Pass Filter (LPF), High Pass Filter (HPF) and Band Pass Filter (BPF) are using frequency to differentiate the noise and the real-measurement data. This is the simplest method but has some disadvantages. First, we need to know the frequency of the noise. This is applicable when the noise has distinctive frequency with the real-measurement data. However, this is not applicable when the noise happens in all range of frequencies.
Kalman filter is popular for having easy computation, memory requirements and good capability on overcoming noises. It is state technique estimation that can extract information from noisy data [21]. Hence, Kalman Filter is best to use for general noise reducer on sensor-reading, especially when the information of noise's frequency that may happen to the sensor-reading is unavailable.
Despite the advantages, it is challenging to design the required equation of Kalman Filter's design for noise reducer. Moreover, it is also important to be careful while determining some parameters such as measurement constant and process variance constant because it affects the filter result much. The paper will discuss on how to specifically design the Kalman Filter equation and parameters for noise reducer on sensor readings. The Kalman Filter equation will be theoretically analyzed and designed based on its component of equation. Also, some values of measurement and variance constant will be simulated and then the filtered result will be analyzed to obtain best suitable values of the parameters. The paper will be arranged into four sections as follows. The first section will be an introduction. The second part will discuss the Kalman Filter and the design process on purpose to reduce signal's noise. The third section is result and discussion about Matlab and Arduino testing. Then last section will provide the conclusions.

Kalman Filter
Kalman filter is an algorithm which is used to predict (or to estimate) the next result based on the previous data. It is not categorized as common filters such as LPF, HPF, and BPF. It is basically an estimator to predict any state or part in the signal which contains signal. The result of the estimation process is similar with eliminating noise from the signal, which is why it is called as Kalman Filter.
Systems in Kalman Filter are assumed as linear systems. Kalman Filter minimalizes the average estimation error square for stochastic linear systems using linear noises sensor. It also minimalizes estimation error square function for linear dynamic systems by white measurement and noise disturbance. It functions as to estimate states on dynamic systems and also to analyze system's performance [10].
There are various types of Kalman Filter, such as standard Kalman Filter [4], Extended Kalman Filter [22], Unscented Kalman Filter [23] and Ensemble Kalman Filter [24]. Standard Kalman Filter is the simplest while the other types are modified for more complicated tasks. The paper will use standard Kalman filter since it contains enough part of equation for noise reducing.
Kalman Filter has two parts, the predict part and the update part. The standard Kalman Filter equation is shown in (1) -(5).

Predict:
Update: where is estimated state, is state transition matrix, is control variables, is control matrix, is state variance matrix, is process variance matrix, is measurement variables, is measurement matrix, is Kalman gain, is measurement matrix, | is current time period, − 1| − 1 is previous time period, and | − 1 is intermediate steps.
Equations (1) to (5) can be called as Kalman Filter system model and its purpose is not defined yet. Therefore, they can be modified based on the designed purpose and how complex the system will be. To implement Kalman Filter algorithm, so that it can be used to reduce noise of sensor-readings, some adjustments for the conditions are needed. Those adjustments are as follows.

Predicting the state
On this stage, adjustments are done in (1) by giving the score ! = 1 because there is no state transition. Thus, reducing the system's input component ! because the used system does not have any input ! . The adjusted equation is shown in (6).

Updating the state value
From (3), ! = 1 since the sensor data that will be filtered is only consisted of one sensor reading. Hence, the equation can be written as (8).

Kalman Filter for Noise Reducer
After the adjustments are done, Kalman Filter equation for reducing noise of sensor-reading can be rewritten as (11) -(15).

Algorithm
The algorithm of Kalman filter, which is based on (11) - (15), is illustrated as flowchart as in Fig.  2. It can be implemented through Matlab, Arduino or another programming sources. After the program starts, some initialization must be made for some variables and constants. In this step, the process variance constant and the measurement constant must be chosen properly. Initially, the values of the estimated state variable ! can be set to zero and the state variance variable ! can be set to one. The next step is to make the sensor data as the input of the Kalman filter as unprocessed signal. The third step is to calculate the predict part which consists of the prediction estimated state variable _ and the prediction state variance variable _ .
The fourth step is to calculate the update part, which actually consists of the Kalman gain ! the updated estimated state variable ! , and the updated state variance variable ! . In the update part, the filtered data is the updated estimate state variable ! and will be shown as the output of the algorithm. Some other values such as the last estimated state and the last state variance is also saved as previous data for next iteration as the looping process is doing lifetime until the system is terminated. The sample source is available in the appendix.

Matlab Implementation
The research is done by doing simulation in Matlab. The research scenario is by making a signal with noise then it will be filtered by using Kalman Filter. Both data, before and after it gets filtered, are compared to find out the Kalman Filter performances. Hence, some parameters in Kalman Filter, which are R and Q matrices, is changed by some values and then is analyzed to seek which ones are the optimal ones to get the best result of the filter.
The test results are shown in Fig. 3, Fig. 4 until Fig. 8. The X-axis shows time and Y-axis shows the data. Green-colored signal is input signal which has original data, some noises, disturbance and extreme variation value. The red-colored signal is the input signal result after getting filtered by Kalman Filter. In testing, it is assumed that the data from random signal is the values of sensor reading with big noise and disturbance.

Kalman Filter Flow Chart
The first examination is in Fig. 4 where using the measurement constant, = 1 and the variance constant, = 1. Based on Fig. 4 the input signal only gets filtered a bit when it is compared to the input signal. Moreover, the values are varying drastically. This may result as very aggressive system response.
The second examination is shown in the Fig. 5 where the measurement constant = 1 and the variance constant = 0.1. Based on Fig. 5, the input signal starts to get filtered better than before. However, the values are still varying drastically although not as big as previous test filtered result. This may still result in a very aggressive system response. Parameter values from both of this and previous examination are not suitable to be implemented into real systems. The third and fourth examination respectively are shown in the Fig. 6 using = 1 and = 0.01 and Fig. 7 using = 10 and = 0.1). The both examination is the best two of filter results because the noise is able to be reduced yet the original data characteristics are still preserved. Similar results are shown by those figures, most possibly because of the same ratio difference of R and Q values. Based on the examination, both of the parameter values are suitable to be implemented into the real system.
The fifth examination is shown in Fig. 8 using = 100 and = 0.1. Based on Fig. 8, the input signal loses its original data so that it can be said that the ratio difference of R and Q should not be greater than 1000 or it will give overly-filtered result. Thus, the parameter is not suitable to be implemented into real system because of the loss of original data characteristics.  Based on the examination from Fig. 3 until Fig. 7, those constants highly affect the noise reducer. The bigger the ratio between R and Q, the bigger the noise damping effect. To investigate the damping effect, the filter result is then compared to the real values. The difference then can be seen as an error equation which can be written as follows The equation ̅ is known as mean error where is the data values and is filter results. The calculations from the equation are shown as in Table 1 on mean error column. Based on Table 1, it can be seen that the bigger difference between and make bigger mean error values. Besides, the same and difference values result in similar value of mean error, whatever the values of and . By comparing Table 1 with previous analysis from the figures, best parameters which provide result with its original data characteristics have mean error values range from 40 to 55.

Arduino Implementation
After simulation using Matlab, the next step is to implement Kalman Filter in Arduino to reduce the noise of IMU (Inertial Measurements Unit) sensor. The IMU sensor consists of Accelerometer Sensor and Gyro Sensor. The results of accelerometer sensor noise reducer are shown by Fig. 9 and Fig. 10. The X-axis on those figures is the n-th data and Y-axis is the 10-bit-ADC sensor data. Greencolored line represents the sensor data and red-colored line represents the result of Kalman filter. Parameters values of Fig. 9 are R=10 and Q=0.1. Meanwhile, R=10 and Q=0.01 are used on Fig. 10. Fig. 9 and Fig. 10 shows that the noise is able to be reduced by using Kalman Filter. The ratio of R and Q on Fig. 9 is 100 and 1000 on Fig. 10. The result from Fig. 9 provides better performance in preserving the original data characteristics than the result from Fig 10. The bigger the ratio of R and Q make smoother filter result. However, if the ratio difference is too wide, the original data loss may