## 3 System Architecture and Design
### Vehicle Detection and Traffic Event Gathering  
To measure traffic information such as speed, occupancy, and volume, the fundamental function is to accurately detect the approach or departure of a vehicle regardless of the kind of vehicle or the state it is in. A T-Sensor node is responsible for detecting an APPROACH or DEPARTURE event caused by a vehicle, and the main role of the T-Sink node is to take a time stamp for each event packet and to filter out unpaired event packets and retransmitted application-level packets. In this sub-section, the vehicle detection algorithm is summarized. To detect a vehicle, a magneto-resistive sensor is used and the overall detection flow is described in Figure 7. Since the Earth itself is a big magnet, there is an ambient magnetic field everywhere on Earth. When a T-Sensor node is turned on, it initializes the baseline for the ambient magnetic field. A ferrous object that drives by, such as a vehicle, distorts the ambient magnetic field. To monitor the distortion, the T-Sensor node samples the ambient magnetic field with a build-in Analog to Digital Converter (ADC) for a sampling period of Ps, which is decided by the maximum detectable speed and the minimum detectable length of a vehicle. The raw sampled data, R(_k_), usually has noise, which is filtered out by the noise filter. The refined data, D(_k_), is provided to both the Baseline Adapter block and the State Machine-based Decision block. It is worthwhile to refer to the gathered data (Figure 8), D(k), for different vehicles with different speeds from a prototype sensor node to continue to describe  
Figure 6: Overall operation procedure of T-Sensor node S/W. the remaining blocks. The State Machine-based Decision block decides the next state, S(\(k\)), based on D(\(k\)), B(\(k\)), and the current state. To provide hysteresis, two different thresholds are applied to the difference of D(k) and B(k) depending on the current state. The higher threshold is used to detect an approaching vehicle to a T-sensor node while the lower threshold is compared to detect a departing vehicle from the sensor node with the difference. To separate two consecutive vehicles is not so difficult, for there is enough space between two moving vehicles. Of course, the lower threshold should not be too small. If so, the sensor node regards them as a single vehicle. On the other hand, the Earth's magnetic field varies by small amounts day-to-day [36]. In addition, temperature changes on the sensor due to the movement of the sun and clouds result in the slow change of the sensed magnetic field [36]. To cope with those two sources of drift, the baseline adapter block is designed to adapt the baseline to those environmental changes. Depending on the output state of the State machine-based decision block, the baseline adapter modifies the baseline quickly or slowly to the recent trend of D(k). Once the next state, S(k), is decided by the decision block, the Event Packet Generator block prepares an event packet (APPROACH or DEPARTURE) with the current battery-level and sends the event to the T-Sink node. When the T-Sink node receives the event packet, it updates the packet's timestamp field with its local time (tick) and forwards it to the T-BS-com. The T-BS-com gathers every packet from TSN and forwards them to the T-Mon Host via USB interface. For the case of failure of T-Mon Host, it saves only event packets in its local SD card. The speed of a vehicle is easily calculated with \(v=\) (the separation of T-Sensor nodes in the same lane)/(time difference of APPROACH packets from them). The length of a vehicle is also estimated by \(v\times\) (time interval between the paired APPROACH/DEPARTURE packets of one of T-Sensor nodes). Figure 8: Refined data, D(k), gathered by prototype hardware. Figure 7: Overall flow of event detection in a T-Sensor node. Volume (or count) of traffic is measured by the paired APPROACH/DEPARTURE packets of one of the T-Sensor nodes. The occupancy is calculated by (time interval between APPROACH and DEPARTURE packets)/(unit time).