Noise Reduction in the Accelerometer and Gyroscope Sensor with the Kalman Filter Algorithm

Noise is unwanted signals in a communication or information system. Kalman filter has a good ability to handle noise. This study uses the Kalman filter algorithm that works to reduce noise at the accelerometer and gyroscope sensor output. Data were taken using the accelerometer sensor and the gyroscope sensor in a stationary condition. The device is Arduino Uno for processing the data and MPU6050 for accelerometer and gyroscope sensor. In the Kalman filter algorithm, there is process variance matrix and measurement variance matrix parameters that affect noise attenuation or reduction at the accelerometer and gyroscope output. If the difference between the two parameters is too large, then the attenuation becomes very large and eliminates the original value of the sensor output. Thus, the value cannot be chosen carelessly. The best value is the measurement variance matrix must bigger than the process variance matrix. Keywords—Noise Reducer, Noise Reduction, Kalman Filter, Accelerometer Sensor, Gyroscope Sensor


INTRODUCTION
The accelerometer is a device used to measure acceleration, detect and measure vibrations (vibrations), and measure the acceleration due to gravity [1] [2]. The accelerometer sensor can be used to measure the angle of a plane or space [3], and changes in angle based on the value of the acceleration due to gravity but is influenced by vibration and acceleration [4]. Gyroscope an angular speed sensor that is used to measure the rotational speed of an object, the output generated by the gyroscope in the form of angular velocity [5] [6]. One of the advantages of accelerometer and gyroscope sensors is that it can provide an accurate reading of the tilt angle of an object, but on the other hand, this sensor also has the disadvantage of being vulnerable to vibration or noise [7] [8] [9]. Applications of these sensors include attitude detection on flying vehicle models [10], the design and implementation of Real Segway on a one-wheel skateboard [11], humanoid robot [12], quadrotor [13], and implementation on balance control [14] [15].
According to the Indonesian Dictionary, Noise is unwanted signals in a communication or information system. These noise signals can disrupt the quality of signal reception and reproduction of the signal to be emitted. Noise can also limit the range of the system at a certain emission power, affect the sensitivity or sensitivity of the reception signal, and even lead to a reduction in bandwidth in a system.
Kalman filter is a series of mathematical equations that have the ability to estimate the state of a process recursively and efficiently by minimizing the average square error [16] [17]. Kalman filter has a good ability to handle noise [8] and has a lot of application [18] [19][20] [21][22] [23]. The use of filtering methods on data sensor output is quite important, because there is noise or interference that can be reduced the accuracy of the output value of the sensor [24]. In the research, the Kalman filter algorithm is used to reduce noise at the output of the accelerometer and gyroscope sensors so that more accurate data is obtained.

II. METHODS
In this study, the experimental method was used by using the values of variables process variance matrix (Q) and measurement variance matrix (R) as Q>R, Q=R, and Q<R. The designed Kalman filter algorithm is then implemented in the accelerometer and gyroscope sensor output data. Output data before being given the Kalman filter algorithm is compared with the output data that has been given the Kalman filter algorithm. The output analyzed is the estimated value of the state and speed to achieve stable conditions at each output. Data from each variable value is then compared to determine the value of the variable that produces the best Kalman filter algorithm output

A. System Design
The design of this system consists of several things, including system block diagrams, wiring diagrams. The system block diagram images can be seen in Figure 1, and the wiring diagram can be seen in Figure 2. In Figure 1, it is explained that the data entered through the MPU6050 sensor as input and then given an additional Kalman filter algorithm to reduce noise, then processed on Arduino Uno R3 [25], then the data is displayed on a laptop using the Arduino IDE software. Figure 2 shows the Arduino Uno R3 [26] cabling with the MPU6050 sensor [27]. Data communication is I2C, the pin connections between the Journal of Robotics and Control (JRC) ISSN: 2715-5072 181 Rio Ikhsan Alfian, Noise Reduction in the Accelerometer and Gyroscope Sensor with the Kalman Filter Algorithm MPU6050 sensor [28] with Arduino Uno R3 [29], among others, VCC with 5V, GND with GND, SCL with A5, and SDA with A4.

B. MPU6050 accelerometer and gyroscope sensors
In this study, data were taken using the accelerometer sensor and the MPU6050 gyroscope in a stationary condition. The sensor data is then read by the Arduino Uno microcontroller using I2C data communication. The sensor reading data is then sent to a computer using 9600 Bps serial communication. The data recorded is the accelerometer data and x-axis gyroscope, y-axis, and z-axis. The data is then logged at 0.1-second intervals. The accelerometer data is an integer number that has a lot of noise, so it needs to be filtered first. The accelerometer and gyroscope output data used are illustrated in Figure 3 and    Figure 4 show the MPU6050 sensor output, the x-axis accelerometer, and the x-axis gyroscope. It can be seen that the output is unstable and has a very rapid change in value even though the sensor when retrieval of data is at rest.

C. Kalman Filter
Kalman filter is a series of mathematical equations that have the ability to estimate the state of a process recursively and efficiently by minimizing the average square error. One of the advantages of the Kalman filter is that it is able to estimate a situation based on minimal data. The Kalman filter equation is divided into two groups [30]: the time update equation and the measurement update equation. Time update can also be called a predicted process, which uses a state estimate from a previous time to get a state estimate at this time. At the same time, the measurement update is also called the correct process, which is the measurement information currently used to improve predictions, with the hope that a more accurate state estimate will be obtained. The Kalman filter algorithm process is illustrated in Figure 5. The following are the predictions and correct equations in the Kalman filter: Predict: correct: Where ̂ is an estimated state, F is a state transition matrix, U is a control variable, B is a control matrix, H is a measurement matrix, y is a measurement variable., T is a process variance matrix, P is a state variance matrix, K is a Kalman filter gain, Q is the process variance matrix, and R is a measurement variance matrix.
Adjustments to some conditions are needed to be able to make the Kalman filter algorithm work on the output of the accelerometer and gyroscope sensors. Adjustments include:

Predict the State
To predict the state at the beginning of the process used Equation Equation (6) is then translated into a programming language becomes Xt_1 = Xt_1t_1;

Predict Error
In this process, the Equation is used in Equation (2). The value of F = 1 was previously determined. Thus the Equation used to predict errors is, Equation (7) is then translated to the programming language as: Pt_1 = Pt_1t_1 + Q;

Calculate Kalman Gain
Kalman Gain calculation can be done using Equation (4) for an adjustment given the value of H = 1. Thus the Equation used to calculate Kalman Gain is, Equation (8) is then translated into a programming language becomes, Kt = Pt_1 / (Pt_1 + R);

Update the State Value based on measurement results
State value update can be done by using Equation (3). The results of Equation (6), which is the initial state prediction and Equation (8) Where y is the accelerometer/gyroscope sensor output value, Equation (9) is then translated to the programming language as: Xt = Xt_1 + Kt * (accelerometer_x-Xt_1);

Update Error value
Update Error Value can be done using Equation (5). The results of Equation (7), which is the initial error prediction, and Equation (8), which is the Kalman Gain value is used to update the error value. Previously determined the value of H = 1. Thus the Equation used to update the error value is Equation (10) is then translated to the programming language as: To run the Kalman filter algorithm, initialization is needed which aims to determine the initial value of some variables because the actual value of the variable has not been obtained. Variables that have initialization values include Xt_1t_1 (prior state value), Pt_1t_1 (prior error value), Q (process error) and R (measurement error). These variables are randomly assigned values , and the results obtained are observed so that they get good filter results. In this study, the values of variables Q and R are divided into 3, namely Q> R, Q = R, and Q <R. To ensure the algorithm can run with repetitive and continuous processes, Equation (6) and Equation (7) are written down again under equation 10. Flowchart system design can be seen in Figure 10. MPU6050 sensor output data is sent to Arduino Uno using I2C communication, inside Arduino data is processed using the Kalman filter algorithm, then the results are displayed on Arduino ideas using a laptop.

A. Variables Process Variance Matrix (Q) > Measurement Variance Matrix (R)
Comparison of the values of Q> R is given 3 variations, Q = 10, with R = 0.1, Q = 10 with R = 0.01, and Q = 100 with R = 0.1. The results of the comparison of the accelerometer x output can be seen in Figure 7, Figure 8, and Figure 9. Gyroscope x output can be seen in Figure 10, Figure 11, and Figure 12. In the figure shows the comparison between the accelerometer sensor output data and the unfiltered gyroscope (blue) and filtered accelerometer and gyroscope sensor output data (red). Figure 7 shows that the Kalman filter has not worked well to reduce noise at the accelerometer x sensor output with variable values Q = 10 and R = 0.1. It can be seen in the picture, which shows the output of the accelerometer sensor before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, ISSN: 2715-5072 183 Rio Ikhsan Alfian, Noise Reduction in the Accelerometer and Gyroscope Sensor with the Kalman Filter Algorithm which means that it makes almost no difference before and after the Kalman filter algorithm is given.  Figure 8 shows that the Kalman filter has not worked well to reduce noise at the accelerometer x sensor output with a variable value Q = 10 and R = 0.01. It can be seen in the picture, which shows the output of the accelerometer sensor before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, which means that it makes almost no difference before and after the Kalman filter algorithm is given.  Figure 9 shows that the Kalman filter has not worked well to reduce noise at the accelerometer x sensor output with a variable value Q = 100 and R = 0.1. It can be seen in the picture, which shows the output of the accelerometer sensor before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, which means that it makes almost no difference before and after the Kalman filter algorithm is given.  Figure 10 shows that the Kalman filter has not worked well to reduce noise at the gyroscope x sensor output with a variable value Q = 10, and R = 0.1. It can be seen in the picture that shows the gyroscope sensor output before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, which means that it makes almost no difference before and after the Kalman filter algorithm is given.  Figure 11 shows that the Kalman filter has not worked well to reduce noise at the gyroscope x sensor output with a variable value Q = 10 and R = 0.01. It can be seen in the picture that shows the gyroscope sensor output before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, which means that it makes almost no difference before and after the Kalman filter algorithm is given.  Figure 12 shows that the Kalman filter has not worked well to reduce noise at the gyroscope x sensor output with a variable value Q = 100, and R = 0.1. It can be seen in the picture that shows the gyroscope sensor output before and after being given the Kalman filter algorithm. From these two lines, the red line almost covers the blue line, which means that it makes almost no difference before and after the Kalman filter algorithm is given. For more details, it can be seen in Tables 1 through Table  6. These tables contain a comparison of the differences between the data before and after being given the Kalman filter algorithm and the difference in data between before and after being given the Kalman filter algorithm. Data taken from each variable is data from 1 to 300, then the data is divided into 6. data 1 (1-50), data 2 (51-100), data 3 (101-150), data 4 (151-200), data 5 (201-250) and data 6 (251-300). The displayed value is the average value of each data. The difference between data is obtained from n-1 data -ndata. The difference in data is obtained from the data with the Kalman filter algorithm -data without the Kalman filter algorithm.  Table I shows the results of the x-axis accelerometer sensor output with variable values Q = 10 and R = 0.1. the difference in data between data 1 and 2 at the accelerometer output without the Kalman filter algorithm is 8.56, which means that the data to 2 increased by 8.56 while the output of the accelerometer with the Kalman filter decreased by 230.96. In the third data, there was a decrease of 12.4 for the accelerometer output without the Kalman filter and a decrease of 16.32 for the accelerometer output with the Kalman filter. In the 4th data, there was an increase of 2.24 for the accelerometer output without the Kalman filter and an increase of 5.6 for the accelerometer output with the Kalman filter. In the 5th data there was an increase of 14.72 for the accelerometer output without the Kalman filter and an increase of 11, 2 for the accelerometer output with the Kalman filter. In the 6th data, there was a decrease of 4 for the accelerometer output without the Kalman filter and an increase of 2.56 for the accelerometer output with the Kalman filter.
From the reading of Table 1, it can be concluded for the x-axis accelerometer output using the Kalman filter algorithm with variable values Q = 10 and R = 0.1 has a more stable movement compared to the accelerometer x output without the Kalman filter algorithm. The new output is stable in data 5 or iteration to 201. However, if we pay attention to the difference in data between the output of the accelerometer x using the Kalman filter algorithm with the output of the accelerometer x without the Kalman filter algorithm getting smaller and approaching 0, which means that both of them are almost equal in value and indicate Kalman filter does not work well. At the accelerometer x sensor output with variable values Q = 10, and R = 0.01 in Table II, the new output is stable in data 6 or iteration to 251 wherein the output without the Kalman filter algorithm an increase of 4.08 and an increase of 2 in the output with the Kalman algorithm filter. The difference in data between the accelerometer x output using the Kalman filter algorithm and the accelerometer x output without the Kalman filter algorithm is getting smaller and closer to 0, which means that both outputs are of almost the same value and indicate the Kalman filter is not working correctly. At the accelerometer x sensor output with variable values Q = 100 and R = 0.1 until the end of the 6th data or 300th iteration in Table II, the output cannot be said to be stable because the difference between the accelerometer x data using the Kalman filter algorithm is greater than the output of the accelerometer x without Kalman filter algorithm. This shows Kalman filter cannot work properly. At the gyroscope x sensor output with variable values Q = 10, and R = 0.1 in Table IV,  Rio Ikhsan Alfian, Noise Reduction in the Accelerometer and Gyroscope Sensor with the Kalman Filter Algorithm difference in data between the gyroscope x output using the Kalman filter algorithm with the gyroscope x output without the kalman filter algorithm tends to be stable. The value is not close to 0 and not too far from the actual value. This indicates that the Kalman filter works well. At the gyroscope x sensor output with variable values Q = 10, and R = 0.01 in Table V, the new output is stable on the 6th data or iteration to 251, were at the output without the Kalman filter algorithm, a decrease of 12.24 and a decrease of 12.157 at the output with Kalman filter algorithm. The difference in data between the gyroscope x output using the Kalman filter algorithm and the gyroscope x output without the Kalman algorithm is close to 0, which means that both outputs are almost identical and indicate the Kalman filter is not working well. At the gyroscope x sensor output with variable values Q = 100, and R = 0.1 in Table VI, the output cannot be said to be stable until the end of the 6th data or 300th iteration. The new output is said to be stable if the difference between the output data of the Kalman filter algorithm is smaller than the output without the Kalman filter algorithm and does not change until the end of the iteration. This shows the Kalman filter algorithm does not work well.

B. Variables Process Variance Matrix (Q) = Measurement Variance Matrix (R)
Comparison of the value of Q = R is given 1 variation, namely Q = 1, and R = 1. The results of the accelerometer x output estimation can be seen in Figure 13, and the gyroscope x output can be seen in Figure 14. The picture shows the comparison between the accelerometer sensor output data and the unfiltered gyroscope (blue) and the accelerometer sensor output data that has been filtered (Red). Figure 13 shows the accelerometer x output sensor with variable values Q = 1, and R = 1. In the figure, the accelerometer sensor output can be seen before and after the Kalman filter algorithm is given. Of the two lines, it appears that the red line is still close to the blue line, which means the difference before and after being given the Kalman filter algorithm is still very small. This shows the Kalman filter has not worked well.  Figure 14 shows that the Kalman filter has not worked well to reduce noise at the gyroscope x sensor output with variable values Q = 1, and R = 1. It can be seen in the picture that shows the gyroscope sensor output before and after being given the Kalman filter algorithm. Of the two lines, it appears that the red line is still close to the blue line, which means that the difference before and after being given the Kalman filter algorithm is still very small. For more details, it can be seen in Table 7 and Table 8. These tables contain a comparison of the differences between the data before and after being given the Kalman filter algorithm and the difference in data between before and after being given the Kalman filter algorithm. Data taken from each variable is data from 1 to 300, then the data is divided into 6. data 1 (1-50), data 2 (51-100), data 3 (101-150), data 4 (151-200), data 5 (201-250) and data 6 (251-300). The displayed value is the average value of each data. The difference between data is obtained from n-1 data -n-data. The difference is obtained from the data with the Kalman filter algorithm subtracting with data without the Kalman filter algorithm. At the x-axis accelerometer sensor output with variable values Q = 1, and R = 1 in Table VII, the new output is stable in the 6th data or iterations to 251 were at the output without the Kalman filter algorithm a decrease of 1131.16 and a decrease of 15.432 in the output with the algorithm Kalman filter. But if you pay attention to the difference in data between the output of the accelerometer x using the Kalman filter algorithm with the output of the accelerometer x without the Kalman filter algorithm getting smaller and closer to the number 0 in the 101st iteration and away from the 0 in the 151st iteration, the 251st iteration in the data reaches 1117, 31. A too-large difference also indicates that the filter is not working properly.
At the x-axis gyroscope sensor output with variable values Q = 1, and R = 1 in Table VIII, the new output is stable in data 5 or iteration to 201, were at the output without the Kalman filter algorithm an increase of 12.16 and an increase of 7.196 in the output with the algorithm Kalman filter. The difference in data between the gyroscope x output using the Kalman filter algorithm with the gyroscope x output without the Kalman filter algorithm tends to be stable. The value is not close to 0 and not too far from the actual value. This indicates that the Kalman filter works well.

C. Variables Process Variance Matrix (Q) < Measurement Variance Matrix (R)
Comparison of the values of Q <R given 2 variations, Q = 1, with R = 10, and Q = 1 with R = 100. The results of the comparison of the accelerometer x output can be seen in Figure 15 and Figure 16. The output of the gyroscope x can be seen in Figure 17 and Figure 18. The picture shows the comparison between the accelerometer sensor output data and the unfiltered gyroscope (blue) and the output data filtered accelerometer and gyroscope sensors (red). Figure 15 shows the accelerometer x output sensor with variable values Q = 1, and R = 10. In the figure, the accelerometer sensor output can be seen before and after the Kalman filter algorithm is given. Of the two lines, the red line appears more stable than the blue line, but still visible noise on the red line. This shows Kalman filter can work well, but the results are not optimal. Fig. 10. Output of accelerometer sensor x (Q = 1, and R = 10) Figure 16 shows that the Kalman filter can work well, and the maximum result is to reduce noise at the accelerometer x sensor output with variable values Q = 1 and R = 100. It can be seen in the picture that shows the results of the accelerometer x sensor output before and after being given the Kalman filter algorithm. From these two lines, the red line tends to be more stable than the blue line, and there is no visible noise on the red line.   Figure 18 shows that the Kalman filter can work well, and the maximum result is to reduce noise at the gyroscope x sensor output with variable values Q = 1 and R = 100. It can be seen in the picture that shows the results of the gyroscope x sensor output before and after being given the Kalman filter algorithm. From these two lines, the red line tends to be more stable than the blue line, and there is no visible noise on the red line. For more details, it can be seen in Table IX to Table XII. These tables contain a comparison of the differences between the data before and after being given the Kalman filter algorithm and the difference in data between before and after being given the Kalman filter algorithm. Data taken from each variable is data from 1 to 300, then the data is divided into 6. data 1 (1-50), data 2 (51-100), data 3 (101-150), data 4 (151-200), data 5 (201-250) and data 6 (251-300). The displayed value is the average value of each data. The difference between data is obtained from n-1 data -n-data. The difference is obtained from the data with the Kalman filter algorithm subtracting data without the Kalman filter algorithm. At the x-axis accelerometer sensor output with variable values Q = 1, and R = 10 Table IX, the output starts to stabilize on the 3rd data or the 101st iteration were at the output without the Kalman filter algorithm an increase of 3.68 and an increase of 3.625 on the output with the Kalman filter algorithm. However, if pay attention to the difference in data between the output of the accelerometer x using the Kalman filter algorithm with the output of the accelerometer x without the Kalman filter algorithm getting smaller and approaching 0, which means that both outputs are of almost equal value and indicate the Kalman filter is not working properly. At the x-axis accelerometer sensor output with variable values Q = 1, and R = 100 Table X, the output starts to stabilize on the 3rd data or the 101th iteration where at the output without the Kalman filter algorithm an increase of 29.92 and a decrease of 2.34 on the output with the Kalman filter algorithm. The difference in data between the accelerometer x output using the kalman filter algorithm with the accelerometer x output without the kalman filter algorithm tends to be stable, the value is not close to 0 and not too far from the actual value. This indicates that the Kalman filter works well. At the x-axis gyroscope sensor output with variable values Q = 1, and R = 10 in Table XI, the output starts to stabilize in data 3 or iteration to 101, were at the output without the Kalman filter algorithm, a decrease of 30.72 and a decrease of 29,945 in output with the algorithm Kalman filter. The difference in data between the gyroscope x output using the Kalman filter algorithm and the gyroscope x output without the Kalman filter algorithm is close to 0, which means that both outputs have almost the same value and indicate the Kalman filter is not working properly. At the x-axis gyroscope sensor output with variable values Q = 1, and R = 100 in Table XII, the output starts to stabilize in data 5 or iteration to 201, were at the output without the Kalman filter algorithm, a decrease of 19.76 and a decrease of 17.831 in the output with the algorithm Kalman filter. The difference in data between the gyroscope x output using the Kalman filter algorithm and the gyroscope x output without the Kalman algorithm is close to 0, which means that both outputs are almost identical and indicate the Kalman filter is not working well.

IV. CONCLUSION
Based on research that has been done, the Kalman filter algorithm is able to reduce noise on the accelerometer and gyroscope sensors. The value of the variable Q and variable R affects the attenuation or reduction of noise at the output of the accelerometer and gyroscope using the Kalman filter algorithm. In the variable value, Q> R Kalman filter cannot work properly because the attenuation results approach the original value of the sensor output, the value of the variable Q = R still cannot work well even though the damping results start away from the original value of the sensor family, but the distance is still too close and at the variable value Q <R can work well, the damping results away from the original value of the sensor output at Q = 1, and R = 10, and get maximum results at Q = 1, and R = 100. The greater the difference between the variables Q and R, the greater the attenuation. If the difference between the two parameters is too wide, it will make a very large attenuation and eliminate the original value of the sensor output.

ACKNOWLEDGMENT
The author would like to thank the editors and reviewers who have provided input and helped publish this manuscript.