# Investigation of Energy Cost of Data Compression Algorithms in WSN for IoT Applications
## 4 Hybrid Model for Run Length Encoding with Adaptive Huffman Encoding
### Hybrid Algorithm
_VCC_ = 3.3 V, _FCLK_ = 3.3 MHz, and _IMSP430_ = 1.85 mA is the current consumption of the TIMSP430 while in active mode. As a result, Equation (2) provides the power consumption per clock cycle of the MSP430 microcontroller. Equation (3) shows how much energy is used to send and receive one bit of data [45,46]. \[E_{CLK}=V_{cc}\times I_{MSP430}/F_{CLK}=1.85\text{nJ} \tag{2}\]

\[S_{bit}=V_{cc}\times I_{TX}\ /\ D_{r}=230\text{nJ} \tag{3}\]

where _Vcc_ = 3.3 V, _ITX_ = 17.4 mA and _Dr_ = 250 kbps

Table 2 shows how basic CPU activity cycles may be utilised to indicate the energy required to transport data while using compression. Finally, we use the design components to figure out the computational complexity (in number of clock cycles) of different data compression algorithms for compressing the input data using the _ECalgo_ (_L1_, _K_). Where _ECalgo_ is the energy consumption of algorithms (RLE, AHE, H-RLEAHE an H-AHERLE), _L1_ is the actual input data size and \(K\) is the compressed data. We have used actual data input of 1500 bits and the data compressed for difference algorithms is mentioned below. Further, we have evaluated the CPU and transmission cost. 1. CPU cost for RLE is formulated as in Equation (4) \[EC_{RLE}=\left(\left(\left(2\times 184\right)+\left(1\times 37\right)\right) \times L1\right)\times 1.85\times 10^{-9}\] (4) where _L1_ is the compressed data of RLE and compressed bits is 70 bits, CPU cost is 0.00018731 J and transmission cost is _Sbit_ \(\times\) 70 bits is 1.61 \(\times\) 10\({}^{-5}\) J. RLE algorithim uses two addition operators and one comparison operator. 2. CPU cost for AHE is formulated as in Equation (5) \[EC_{AHE}=\left(\left( \begin{pmatrix}(9\times 184)+\left(4\times 177\right)+ \left(1\times 395\right)+\\ \left(1\times 405\right)+\left(14\times 37\right)\end{pmatrix} \right)\times L1 \right)\times 1.85\times 10^{-9}\] (5) where _L1_ is the compressed data of AHE and compressed data is 330 bits, CPU cost is 0.0017029 J and transmission cost is _Sbit_ \(\times\) 30 bits is 7.59 \(\times\) 10\({}^{-5}\) J. In Equation (5) there are 9 addition operators 4 subtratctions, 1 multiplication, 1 division and 14 comaprison operators. 3. CPU cost for H-RLEAHE is formulated as in Equation (6) \[EC_{H-RLEAHE}=\left( \begin{array}{c}\left(\left(2\times 184\right)+\left(1 \times 37\right)\right)\times L1+\\ \left(\left(9\times 184\right)+\left(4\times 177\right)+\left(1\times 395\right)+ \left(1\times 405\right)+\left(14\times 37\right)\right)\times K_{H1}\end{array}  \right)\times 1.85\times 10^{-9}\] (6) where _L1_ is the compressed data of RLE, the _KH1_ is the compressed data of H-RLEAHE and data compressed is 82, CPU cost is 0.00025543 J and transmission cost is \(S_{bit}\times\) 82 bits is 1.886 \(\times\) 10\({}^{-5}\) J. From equation 6 we can observe that there are two addition operators, one comparison, 23 addition operators, 4 subtractions, 1 division and multiplication and 1 comparison operators. \begin{table}
\begin{tabular}{l l} \hline \hline
**Operations** & **Number of CPU Cycles** \\ \hline Addition & 184 \\ Subtraction & 177 \\ Multiplication & 395 \\ Division & 405 \\ Comparison & 37 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: CPU cycles for the TIMSP430 microoctroller [45]. * CPU cost for H-AHERLE is formulated as in Equation (7) \[\text{EC}_{H-AHERLE}=\left( \begin{array}{c}((9\times 184)+(4\times 177)+(1\times 395)+(1 \times 405)+(14\times 37))\times L1\\ +((2\times 184)+(1\times 37))\times K_{H2}\end{array} \right)\times 1.85 \times 10^{-9}\] (7) where \(L1\) is the compressed data of AHE, \(K_{H2}\) is the compressed data of H-AHERLE and data compressed is 1360, CPU cost is 0.0019502 J and transmission cost is \(S_{hit}\times 1360\) bits is 0.0003128 J. Operators used in Equation (7) is 23 additions, 4 subtractions, 1 multiplication and division, and 1 comparison. It can be clearly seen that the transmission cost and CPU cost for RLE is better than the other data compression algorithms.