## 7 SMEP Algorithms
### AuxDataQueue Compression Algorithm
One of main consumers is generally a monitoring and control center that monitors external or internal environments of each sensor nodes using sensor data transmitted by them, and controls them by sending control messages to sensor nodes if necessary. In order for the final consumer to use the _SMEP_ main return values, the consumer must decompress them and recover the unselected sensor data during saving and compressing sensor data. In this section, we introduce algorithms for the decomposition of compressed sensor data and the recovery of lost sensor data. ### Sensor Data Line Interpolation Algorithm

Sensor Data Line Interpolation Algorithm uses the line interpolation method to recover the lost sensor data. The line interpolation is a very simple method to interpolate the unknown values of points between two known endpoints. Algorithm 5 illustrates _SensorDataLineInterpolation_, a line interpolation algorithm for lost sensor data recovery:
```
Parameters \(01\)\(f_{value}\): the leftmost sensor data value of an interval for recovering compressed sensor data \(02\)\(f_{pos}\): the leftmost absolute position of an interval for recovering compressed sensor data \(03\)\(l_{value}\): the rightmost sensor data value of an interval for recovering compressed sensor data \(04\)\(l_{pos}\): the leftmost absolute position of an interval for recovering compressed sensor data Global Variables Local Variables \(01\)\(x\): the absolute position of a lost sensor data to be recovered \(02\)\(R_{value}\): the value of a recovered lost sensor data with the absolute position \(x\) Procedure \(01\) Output \(f_{pos}\)\(f_{value}\) \(02\) Set \(x=f_{pos}+1\) \(03\)while(\(x\)\(<\)\(c_{pos}\)) do \(04\) Set \(R_{value}=\frac{l_{value}-f_{value}}{l_{pos}-f_{pos}}(x-f_{pos})+f_{value}\) \(05\) Output \(x\), \(R_{value}\) \(06\) Set \(x=x+1\) \(07\) endwhile Endprocedure
```
**Algorithm 5**_SensorDataLineInterpolation(\(f_{value}\), \(f_{pos}\), \(l_{value}\), \(l_{pos}\))

(\(f_{value}\), \(f_{pos}\) ) and (\(l_{value}\), \(l_{pos}\)) are two known endpoints in the algorithm. These endpoints are two pair of value and absolute position about each of two consecutive compressed sensor data in DataQueueThe procedure finds the line equation to pass two endpoints (procedure line 4). If there exist one or more absolute positions between these two endpoints, the sensor data at these absolute positions are those lost in compressions. Therefore, the procedure calculates approximately values at these absolute positions by substituting each of them into the line equation one by one (from procedure line 3 to line 7) and outputting each pair of the values and absolute positions of them (procedure line 5). This procedure is used in the _SensorDataRecovery_ procedure introduced in the next section. ### Sensor Data Recovery Algorithm

_SensorDataRecovery_ is an algorithm that receives data structures (_DataQueue_, _Zones_, _ZoneBpSeq_, _ZoneCompHistory_, and _AuxDataQueue_) and a variable (\(Ap\)) from the SMEP main via a wireless sensor network and existing networks and decompresses or recovers the compressed and lost sensor data by the SMEP main sensor node during communication failure. In fact, all of the sensor data in each zone of _DataQueue_ are the compressed or original ground sensor data finally selected in the same number of compressions. _SensorDataRecovery_ algorithm finds absolute positions of remaining sensor data in each zone. At this time, the procedure uses _FindAbsoluteAddress_ function and this function finds an absolute address using _DataQueu_, _Zones_ and _ZoneBpSeq_ arrays, when a sensor data position in _DataQueue_ is given. Since how to calculate the absolute address using these arrays has already been introduced in the form of a formula in Theorem 8 in Section 6.2, we omit the detailed procedure about that function in this paper.