## 5 Rate Adaptive MAC (RA-MAC)  
In this section, we present details of our proposed Rate Adaptive Media Access Control (RA-MAC) scheme for sensor networks. Based on Equation (11) and (12), we can select the optimal data rate to minimize network energy consumption given full knowledge of the channel condition. However, it is very difficult, if not impossible, to collect this information in advance and as discussed earlier it is quite dynamic, particularly if operating within the transition region. Therefore, we need to continually monitor the channel condition (e.g., \(n\), \(RSSI\), \(\textit{PRR}_{\textrm{data}}\), and \(\textit{PRR}_{\textrm{ack}}\)) and change the transmission data rate adaptively. The number of neighbors (\(n\)) can be easily obtained by overhearing neighbor's communications traffic. The value of the remaining parameters (\(RSSI\), \(\textit{PRR}_{\textrm{data}}\), and \(\textit{PRR}_{\textrm{ack}}\)) are time varying and RA-MAC includes algorithms to estimate them on-line in order to select the optimal transmission data rates. Algorithm 1 is used to send a data packet. The sender node estimates the received signal strength (\(\widehat{RSSI}\)) of the current packet (note that RSSI is measured at the receiver). This is based on a weighted moving average filter over previous RSSI values that were piggybacked on previous ACK packets (More sophisticated estimates could include auto-regressive terms, neural networks or even a Kalman filter. However, such algorithms are typically computationally intensive and challenging to implement on a resource-constrained sensor node. The performance and cost comparison of different estimators is beyond the scope of this paper.). Then, at Line 5, the node calculates the energy consumption based  
Figure 1: Network energy consumption _vs._ RSSI values at different data rates. (Note the Y-axis log scale). on \(\widehat{RSSI}\), \(\textit{PRR}_{\mbox{data}}\) and \(\textit{PRR}_{\mbox{ack}}\) using Equation (11) for different data rate. The node then chooses the optimal data rate \(R\) that consumes the least amount of energy (Line 6). Furthermore, in order to adapt faster to the channel condition, once it deteriorates, the node decreases data transmission rate \(R\) aggressively (Line 12). Similarly, after the channel condition improves, the node increases data transmission rate \(R\) (Line 8) in order to explore PRR at the higher rate. Here \(M\) is a protocol parameter. RA-MAC adapts faster to changing channel conditions with smaller \(M\). However, a smaller \(M\) might make RA-MAC overreact to channel noise. We use \(M=10\) in our TinyOS/TinyNode implementation. ```
1:procedure\(Transmit(Packet)\)
2:if Last transmission acknowledged then
3:\(S\Leftarrow S+1\)
4: Estimate \(\widehat{RSSI}\): \(\widehat{RSSI}\Leftarrow(1-\beta_{1})\cdot\widehat{RSSI}+\beta_{1}\cdot RSSI _{prev}\)
5: Calculate \(E(\widehat{RSSI},R)\) using Equation (11) for different \(R\)
6:\(R\Leftarrow\underset{R}{\operatorname{argmin}}\;E(R,RSSI)\)
7:if\(S>M\)then
8:\(R\Leftarrow R+1\)
9:\(S\Leftarrow 0\)
10:endif
11:else
12:\(R\Leftarrow R-1\)
13:\(S\Leftarrow 0\)
14:endif
15: Transmit packet at data rate \(R\)
16:endprocedure
```  
**Algorithm 1** Pseudo-code for transmitting a data packet  
Algorithm 2 shows the pseudo-code for a node after receiving a data packet. The receiver collects RSSI value and data rate \(R\) from the packet and calculates the Cyclic Redundancy Check (CRC). Then it updates \(\textit{PRR}_{\mbox{data}}(RSSI,R)\) using a weighted moving average (Line 5). If the CRC value is correct, the receiver piggybacks \(\textit{PRR}_{\mbox{data}}\) value and the RSSI value in the ACK packet and transmits it back to the sender. Algorithm 3 shows the pseudo-code for a sender waiting to receive an ACK packet. First, the sender sets up a retransmission timer. If the sender receives an ACK before the timer expires, it extracts the real RSSI, and the updated \(\textit{PRR}_{\mbox{data}}\) values from the ACK packet (Line 6).