# Temperature Control Unit--Modeling and Implementation of a Particle Filter on a Microcontroller
## 5 Experiments Results
### PF Performance Comparison  
The performance is a very important part of data processing, especially in embedded systems. In this part of the tests, we compare the results from four different platforms, including solutions in which processing is done on an outside computer unit or on an embedded board (the details are given in Table 1). The original C# code, expressing the particle filter algorithm and prepared for platforms A, B, and C, was rewritten to the C language because of the board (platform D) requirements. We also decided to prepare two different versions of the code--a standard version without any platform optimization (S), and a highly optimized code (O). The optimized version includes several specified improvements listed below:  
1. Using only float variable types instead of double (in the entire code);
2. Changing all numbers by adding f postfix (e.g., 3.0f instead of 3.0);
3. Using float-specific arithmetic functions such as cost, powf, and sqrt;
4. Enabling FPU (floating point unit);
5. Selecting--Ofast optimization level in the compiler settings. After applying the improvements, we used the STM32F4 evaluation board to recheck the performance. As STM32F4 has a limited amount of memory, we decided to reduce the maximum number of iterations and particles (additional changes made for optimizing the C code are given later in the text). Platform tests (Table 1) were repeated with the same parameters to achieve reliable results for comparison. The one-dimensional object described by Equation (6) was used for these simulation tests. The experiment data (noises and state variables) were regenerated during each experiment. Initial tests showing a comparison of the particle filter operation for the considered platforms are given in [18]. Three tests were carried out with the following number of iterations and number of particles (accordingly) used: \(N_{p}=1000\), \(M=500\); \(N_{p}=1000\), \(M=500\); and \(N_{p}=500\). The results of the tests are shown in Figure 5.  
The performance of the microcontroller with the algorithm in the standard version (S) is much worse than on the other compared platforms. The simulation of the object and the particle filter algorithm on the STM32F4 is from 57 to 360 times slower (without any platform-specific optimizations). It is a huge difference that cannot be compensated for by the simulation scenario. In this case, the microcontroller cannot be used in scenarios when a high number of iterations, a high number of particles, and real-time processing are required. The highly optimized version (O) is much more efficient and can compete with other platforms. The differences are related to clock speed, IPC (instructions per cycle), and the hardware architecture of the platform. The comparison of the standard and optimized version is additionally shown in Table 2. \begin{table}
\begin{tabular}{c c c} \hline \hline \multirow{2}{*}{Platform A} & Processor & AMD Ryzen 7 2700 (3.20 GHz) \\  & Memory & DDR4/64 GB \\  & Operating system & Microsoft Windows 10 (\(\times\)64) \\ \hline \multirow{2}{*}{Platform B} & Processor & Intel Core i5 4210M (2.60 GHz) \\  & Memory & DDR3/8 GB \\  & Operating system & Microsoft Windows 8.1 (\(\times\)64) \\ \hline \multirow{2}{*}{Platform C} & Processor & Intel Atom D525 (1.80 GHz) \\  & Memory & DDR3/4 GB \\  & Operating system & Microsoft Windows 7 (\(\times\)64) \\ \hline \multirow{2}{*}{Platform D} & Processor & STM32F407 VGT6 (168 MHz) \\  & Memory & 192 kB \\  & Operating system & n/a \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Specification of the hardware platform used in the experiments. Figure 5: The performance comparison between platform. The results were obtained for \(M=1000\) and \(N_{p}=1000\); \(M=500\) and \(N_{p}=1000\); \(M=500\) and \(N_{p}=1000\); \(M=500\) and \(N_{p}=500\); and single thread only. As embedded systems are called energy-saving, it is obvious that boards such as STM32F4 consume less energy than a powerful PC in general and offer less computational power.