Denoising MAX6675 reading using Kalman filter and factorial design

This paper aims to tune the Kalman filter (KF) input variables, namely measurement error and process noise, based on two-level factorial design. Kalman filter then was applied in inexpensive temperature-acquisition utilizing MAX6675 and K-type thermocouple with Arduino as its microprocessor. Two levels for each input variable, respectively, 0.1 and 0.9, were selected and applied to four K-type thermocouples mounted on MAX6675. Each sensor with a different combination of input variables was used to measure the temperature of ambient-water, boiling water, and sudden temperature drops in the system. The measurement results which consisted of the original and KF readings were evaluated to determine the optimum combination of input variables. It was found that the optimum combination of input variables was highly dependent on the system's dynamics. For systems with relatively constant dynamics, a large value of measurement error and small value of process noise results in higher precision readings. Nevertheless, for fast dynamic systems, the previous input variables' combination is less optimal because it produced a time-gap, which made the KF reading differ from the original measurement. The selection of the optimum input combination using two-level factorial design eased the KF tuning process, resulting in a more precise yet low-cost sensor.


INTRODUCTION
In response to the rapid development of technology, the information and knowledge nowadays are freely accessible around the world as indicated by massive open access and open source platforms. Arduino, one of the open-source platforms, eases many people, including makers and scientists to acquire data and control things. Microcontroller like Arduino breaks the obstacle of expensive commercial instruments such as data acquisition (DAQ) [1], [2]. Economical Arduino-DAQ can easily be made to monitor the system with the help of low-cost sensors and modules. However, as the response of vast deployment of low-cost sensor and module [3], the resulted measurements are corrupted with noise [4] which need to be filtered first to know the real value of the parameter being measured.
From so many filtering techniques out there, Kalman filter (KF) has been widely applied in many fields, because of its simple algorithm, good filter quality in reducing variance, does not take up much memory, and can be applied in real-time [5]- [8]. However, to get the optimum filter results from KF, the three initial statistical assumptions or herein called the three input variables, namely estimation error, process

LITERATURE REVIEW 2.1. Kalman filter
Kalman filter (KF) is an algorithm which estimates the true value of hidden variable based on previous measurement which full of noise and inaccuracy [5], [24]. KF combines the predicted states and noisy measurements to produce optimal and unbiased estimates of the system parameter. This algorithm is widely used for prediction or estimation, but is called a filter because of its optimal ability to minimize variance [25]. According to Mohinder and Angus, Kalman Filter is possibly the greatest discovery in the 20th century [26], because of its application that has been widely used in the inertial navigation system [27]- [33], freeway traffic modelling [34]- [37], object tracking [38]- [42], image processing [43]- [48], even modelling the marine ecosystem [49]. The basic principle of the Kalman algorithm is determined by (1) and (2). Kalman models the output measurement of the sensor ( ) at a certain time ( ) as a linear function of the parameter of interest ( ) combined with the conversion matrix ( ) as a measurement converter accompanied by measurement noise ( ).
The dynamic of the parameter of interest ( ) at time ( ) is modelled as a linear combination of the previous state ( at − 1) combined with the transition matrix ( ), the input control ( ) and its transition matrix ( ), as well as process noise ( ).
To distinguish between measurement noise ( ) and the actual value of the parameter of interest ( ) from a sensor reading ( ), the Kalman algorithm uses several mathematical equations listed in Table 1. The block diagram of Kalman Filter's algorithm is shown in Figure 1. Based on the schematic in Figure 1, the system must be modelled priorly with three input variables, namely estimation error ( ), process noise ( ) and measurement error ( ) before KF can filter noise from output measurement using (3)-(6). Estimation error ( ) is an initial estimation of the measured parameter. The value of this variable can be filled with any number because KF will adjust the value to the actual condition based on the sensor measurement results.
Process noise ( ) relates to system dynamics or often is illustrated by how fast the state of the system changes. The value of this variable is in the range of 0 to 1. If this variable is equal to 0 then the system is modelled to be in constant or stable condition. Meanwhile, if this variable has a value of 1 then the Current State Estimation as filtering equation

METHOD
The Kalman filter was applied to four K-type thermocouples mounted on MAX6675 to measure the ambient water temperature for 24 hours, the boiling water temperature, and sudden change of temperature in the system. Ambient water was used as a comparison to the natural low-dynamics system, while water in the boiling process is categorized as the unnatural low-dynamics system. The sudden change of the system's temperature is a simulation of a system-failure which categorized as fast dynamics system. The fast dynamics system is a modification of the low-dynamics system where the four sensors that were measuring the boiling water temperature suddenly released into the ambient air. The experimental set-up of this experiment can be seen in Figure 2. The four sensors were first used to measure the temperature of ambient water for 24 hours, then the heater was turned on to boil the water with 100 Watt power and 200 Volt input voltage which already been stabilized by the regulator. After the water was boiling for a while, the four sensors were exposed to ambient air. The four K-type thermocouples and MAX6675 sensors were connected to Arduino Mega as the microprocessor to input both the measurement commands and the algorithm of Kalman filter as in (3)- (6). The four sensors measured the system temperature every 100 ms to be stored as text in the SD card. Compatibility of Arduino and SD Card creates an inexpensive data-logger [1], [51] which reduce electricity consumption.
Each K-type thermocouple mounted on MAX6675 sensor has different values of KF's input variables, which can be seen in the second to fourth columns of Table 2. All sensors were placed relatively near to each other in the same system, so all sensors were set to have the same value of estimation error, 10 ºC. The estimation error value was set far from the ambient water temperature to see resilience of the filter or how long the filter results converge withf the actual temperature as measured by the sensor. In order to select the optimal combination of input variables to produce a smaller deviation, two of the three Kalman input variables, namely the process noise and measurement errors will be analyzed using two-level factorial designs. The same value of high and low level, respectively 0.9 and 0.1, was selected for each variable, as conservative estimates which fall within the range of process noise value, 0 to 1, but not the exact 0 or 1 because mostly we don't really know the actual state of the system during observation. Although the uncertainty of K-type thermocouple mounted on MAX6675 sensor based on previous study was between 0.22 ºC to 0.26 ºC [21], the sensor uncertainty in this study was set to 0.1 and 0.9 to see the effect of the unstandardized values of measurement error to the filter results.

RESULTS AND DISCUSSION
The results of each sensor's original reading and KF's reading in ambient water temperature for 24 hours are shown in Figure 3. The original readings of each sensor (TC-i) are shown in black line, while the Kalman filter's readings (TCF-i) are shown in red. All the four sensors of K-type thermocouples mounted on MAX6675 were placed relatively close to each other and came from the same manufacturer, but the accuracy of each sensor is slightly different between one another. The four of them showed the same trend in reading the dynamics of water temperature for 24 hours, but with big oscillation. The difference between measured value at time and could reach up to 1.5 ºC, even though the datasheet of MAX6675 stated that the noise already been filtered in the internal circuit of the sensor [52].
Based on Figure 3, Kalman algorithm worked well in filtering the original readings of sensors, but the results differ between sensors because the performance is very dependent on the input variable as in Table 2. The KF's input variables for the first sensor produced the smallest deviation among the other. While the input variables for the second sensor produced filter results that hardly differ from its original reading. The KF's input variables for the third and fourth sensors produced filter results that appear to be the same to each other, with deviations smaller than the original deviations of the sensors but greater than the deviation generated by the KF's input variables on the first sensor. The calculated deviations before and after filtering are shown in the last two columns of Table 2.
As shown in Figure 3, the KF results on the first and fourth sensors did not immediately converge to the sensors' output measurement at the beginning. The algorithm on those two sensors took approximately one second to converge to the original output measurement. This is most likely due to a large value of 3822 measurement error variable so the Kalman gain value was smaller on both sensors which makes the KF algorithm trust the output measurement less than the calculated estimate value. The relationship between the deviation produced and the input variable of each sensor was analysed using two-level factorial design, as shown in Figure 4. Sensor 1 to sensor 4 is denoted by S1 to S4, with the value of input variables and its resulting deviation based on Table 2. If the level of measurement error was increased, the average deviation decreased around 0.055 ºC. This indirectly indicates that the KF algorithm knows that the greater the sensor's measurement error, the measurement input given by the sensor is very noisy so the resulting filter became more precise. The deviation was increased by approximately 0.075 ºC if the level of the process noise was increased. This is reasonable, given the system was in ambient state which doesn't tend to change drastically, so the smaller the value of the process noise, the better it is in modelling the real system dynamics which affects to the smaller deviation produced by KF. The interaction effect of the two input variables was less significant in changing the KF deviation in a natural low-dynamic system, only 0.005 ºC. For natural and low-dynamic systems, simply reducing the value of the process noise will result in a more precise reading. The performance of Kalman Filter in reading the temperature changes in boiling process is shown in Figure 5, which consists of a close-up view of the boiling process. The results of KF readings in this process were almost same with the readings in ambient water. The input variables of the first sensor produced the smallest deviation between the other input variables and the input variables of the second sensor produced a filter reading that is almost the same to the original sensor reading. The effect of the input variables to the deviation produced by KF in reading the temperature changes in boiling process using two-level factorial design is shown in Figure 6. Compared to Figure 4, only the effect of measurement error variable that has not changed. This indicates the independency of sensor's measurement error to the state of system. The effect of process noise which was smaller than the value calculated on natural low-dynamics system, indirectly indicates that Kalman Filter algorithm knows that the system being measured has different dynamics from the previous system. For systems with additional input energy from the outside, although changing the value of the process noise could change the deviation of the KF reading, it was less significant than when the system is in a natural state. A significant change in deviation will occur when the measurement error value is greater. The interaction between the two variables had a greater influence in changing the sensor deviation than the results obtained in ambient conditions. For low dynamics systems, large value of measurement error and small value of process noise were possibly the optimum combination of KF input variables to produce more precise readings. Measurement error values that were not in accordance with sensor specifications also did not affect KF performance. The performance of the four combinations of KF input variables in reading sudden temperature changes is shown in Figure 7. When there is a swift temperature drop, the first sensor with large value of measurement error and small value of process noise produced a filter result that somewhat different from the original sensor readings. A time-gap or delay around one second existed before the KF reading on the first sensor adjusted its dynamics to the sensor's original measurement. In a fast-dynamic system, the factorial design analysis regarding input variables influenced the deviation produced was somehow inappropriate because of the delay. The response time of each KF input variable was analyzed instead. Graphically, the combination of input variables for the second sensor produced the same dynamic between KF results and the original output measurement from sensor, therefore deviation resulted were not much different from the original sensor's reading. The KF readings on the third and fourth sensors illustrated the real-time dynamics of the sensors without delay with smaller deviations. Hence, it indicated the efficacy of KF algorithm in filtering the original measurement with the proposed input variables. The deviation produced by KF on the third and fourth sensors was smaller than the original deviation of the sensor but not as precise as the KF results on the first sensor. Referring back to Figure 3, the combination of input variables on the fourth sensor required a warm-up time or adjustment time when used for the first time. This can be neglected with changing the value of estimation error as close to real condition. However, it can be a consideration in choosing the right combination of input variables.

CONCLUSION
The performance of the four pairs of MAX6675 and K-type thermocouple using Arduino as temperature-acquisition have been evaluated. All of the sensors showed great tendency to be used as inexpensive DAQ because they produced the same trend in reading temperature from ambient to almost 10 ºC. However, they produced different readings between each other, which compromise the accuracy of the sensors. Further calibration process is recommended to make the temperature acquisition based on MAX6675 and K-type thermocouple more valid. The output measurements resulting from K-type thermocouple and MAX6675 also have huge oscillations, around 0.22-0.25 ºC. Therefore, the filtering process, such as Kalman Filter, was needed to make the sensors' readings more precise.
The application of Kalman filter on K-type thermocouples and MAX6675 sensor produced fairly precise real-time readings when used with the right combination of input variables. The two-level factorial design could simplify the tuning process of the input variables by looking at the main effect and the interaction effect between variables. In the constant-dynamic systems, a combination of large value of measurement error and small value of process noise resulted in a more precise reading with small deviation of 0.02 ºC. However, the previous combination produced a time-gap or delay when applied to a fast-dynamic system. The delay slows the filter results in responding to the system's real dynamics. For systems with fast dynamics, it would be better to use a combination of measurement error and process noise values at the same level because the filter readings adequately represented the actual system dynamics without delay and produced smaller deviations than the sensor's original measurement, around 0.07-0.09 ºC.