## 3 SWIFTNET: Protocol for Fast-Reactive Monitoring
### Signal Reconstruction Algorithm  
Algorithm 1 shows our proposed signal reconstruction algorithm. We assume the sink to be sufficiently powerful e.g., a node directly connected to a laptop or to a high-end PC with enough computational resources. The sink node should be capable of recovering the compressed packets received stored in a vector \(comp_{vector}\) shown in Line 2 of the algorithm. On Lines 4 to 11 the LFSR measurement matrix is generated. Following this the signal is reconstructed shown on Lines 13 to 16. The function _dcmtx_ represents the DCT \(\Psi\) basis and the _SolveBP_ function executes the linear programming (LP) code written in MATLAB obtained from Sparselab [55]. However, to be able to recover the signals, the sink node must have a knowledge of the sensing matrix used by the node for compression. To achieve this, the nodes must be able to generate such a matrix and then communicate it with the sink. Unfortunately, the leaf nodes have limited memory capabilities to store the matrix. Moreover, transmitting several columns of vectors will equally require the radio to be in \"ON\" mode, and this would be counter-productive to the goal of minimizing energy consumption in the network. A solution to the above problem will be to find a matrix that we can construct without storing it on the leaf nodes or transmitting it to the sink. Thus we generated the measurement matrix \(\Phi\) by sampling \(n\) column vectors from a uniform distribution using the LFSR as described in the previous section. Consequently, the matrix can be generated on the leaf nodes with a \"seed\" and simultaneously we can perform data compression. This way it is not needed to store the generated matrix on the nodes, rather the LFSR matrix using the same \"seed\" can be utilized for the reconstruction process by applying the proper basis \(\Psi\) at the sink node. In a nutshell, the compression phase is accomplished within the network using Equation (5). In contrast, the decompression of the signal is performed at the sink using Algorithm 1, as long as it has the knowledge of the measurement matrix \(\Phi\). With this method of matrix generation and simultaneously performing compression at the nodes, the memory usage is optimized, as we have been able to avoid storing the \(n\times n\) matrix for transmission to the sink. In addition, the nodes are able to work autonomously. An important observation from the experiments reveal that, if the signal is averagely sparse, the signals can be recovered with a high accuracy. From the above algorithm design, the solution to the problem of reconstruction requires \(N\geq cK\) random projections, with \(c(S)=O(log(1/S))\) and \(S=K/N\) denoting the sparsity rate of the signal. Obviously, the recovery error depends on the number of samples taken, and ideally, the error decreases for an increasing value of \(N\). In [56], they provided a statistical estimation for when \(K\) is far less than \(N\); they asserted that the data can be reconstructed with a high probability when \(c\approx[3,4]\), _i.e._, taking \(N\geq 3K\approx 4K\) random measurements should suffice. Thus, we set \(K\) to be 25% of the original signal. ```
1:lfsr --- 44257 #Initialize LFSR seed
2:\(comp_{(vector)}\); \(Sizeof\,Historytable\);
3:#Create the measurement matrix by sampling \(n\) column LFSR vector:
4:for (\(i\ in\ 1\): len(\(comp_{(vector)}\))) do
5:for (\(i\ in\ 1\): \(Sizeof\,Historytable\)) do
6: #Generate the LFSR vector used for compression at the source nodes:
7: bit := ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
8: lfsr := (lfsr >> 1) | (bit << 15);
9: matrix(i,j) := lfsr;
10:endfor
11:endfor
12:#Signal reconstruction using LFSR generated matrix:
13:CompA := matrix \(\times\)\(comp_{(vector)}\);
14:\(B_{rec}:=\) dctmtx(matrix) \(\times\) len(\(comp_{(vector)}\));
15:CoefBP := SolveBP(matrix \(\times\)\(B^{\prime}_{rec}\), CompA, len(\(comp_{(vector)}\)));
16:Recon := (\(B^{\prime}_{rec}\)\(\times\) CoefBP);
```  
**Algorithm 1** Reconstruction algorithm using LFSR measurement matrix.