Вы находитесь на странице: 1из 6

Wireless Sensor Networking in Matlab: Step-by-Step

Milan Simek, Patrik Moravek and Jorge sa Silva

AbstractWe present an extensive guide for the researchers that aim to validate proposed algorithms for wireless sensor networks in Matlab environment. In this paper, we describe step by step all necessary tasks that must be accomplished for the full operation of the Matlab WSN simulation model. The goal of this paper is to describe processes how to simulate the lifetime of the WSN network during a data gathering. We describe tasks such as topology generation and visualization, data routing and communication cost calculation. To estimate lifetime of network, we have proposed the Matlab energy model that goes from the analysis of the real Zigbe network. Index Termswireless sensor networks, Matlab, implementation, simulation, guide, matrix.

position p of each vertice i is identied by the set of coordinates pi = (xi , yi and zi respective). An euclidean length di,j between two vertices i, j V is refferred to as E . The network topology is then interpreted by a three/four row matrix, where the 2D/3D position of nodes are stored in individual columns, see Table I. Furthermore for a simplicity, only the 2D plane is considered for the simulation.
TABLE I T OPOLOGY MATRIX ID X coor Y coor 1 x1 y1 2 x2 y2 3 x3 y3 ... ... ... N xN yN

I. I NTRODUCTION HIS paper introduces step-by-step implementation of the wireless sensor networking in Matlab environment(particularly Matlab 2007b). It aims to bring detailed directions for under/postgraduate students and researches dealing with the wireless sensor simulation under the Matlab environment. Hence a longterm data gathering is the fundamental task of the wireless sensor networks, we show how to implement all necessary tasks related with the data gathering processes. In the considered simulation, each battery equipped node unicasts in the regular intervals (refferred to as rounds of data gathering) a one packet with the dened size. The packets are multihoped through the network to the base station that is power supplied. Simulation ends when there is no path to the base station, meaning that all neighbors of base station are out of energy. The results of the simulation are presented by the colored topology showing the residual energy on each node and a plot of number of alive nodes in the network during increasing number of gathering rounds. The rest of paper is structured as follows: Section I brings the steps of network topology denition. In Section II, we show how to nd the shortest path between two nodes in ad-hoc network. An evaluation of communication cost is introduced in Section III, while Section IV describes the proposed energy model. The result of the entire simulation are presented in Section V. The section VI brings the conclusion and future work.

For the simulations, the networks are considered to be fully connected, meaning that all nodes are reachable due to the multihop communication. The connectivity depends on the radio range, thus the radio range of the nodes should be congured optimally. One can estimate the optimal radio range empirically or to use an Eq. 1 that estimates the minimum radio range ensuring the full connectivity. R= log N N (1)

II. N ETWORK T OPOLOGY A network with N nodes can be modeled as a N -vertex undirected graph G = (V = {1, ..., N }, E ), where 2D/3D
Manuscript received December 15, 2010; revised January 11, 2010. M. Simek and Patrik Moravek are with the Department of Telecommunication of Brno University of Technology, Czech Republic, email:simek@feec.vutbr.cz Jorge sa Silva is with Department of Informatics, University of Coimbra, Portugal, email:sasilva@dei.uc.pt.

The parameter stands for a 2D plane diameter directly proportional to the number of nodes N . Calculating the R for the 100 nodes randomly placed in the 2D plane with the 300m x 500m dimension, the minimal R should be 82 meters. According to the experiences with the Crossbow IRIS 2.4 GHz node [7], the radio range of 82 meters corresponds to the transmitting power of 3.2 dBm. Once the network matrix is created and radio range calculated, the network topology can be printed. The layout of the network consists of the vertices and edges between vertices. The edge or link between two nodes can be printed only in case that the euclidean distance di,j between two nodes i, j is smaller than R of the considered nodes. Since the wireless links are considered to be bidirectional and symmetric then di,j = dj,i . A pseudocode of the layout printing is introduced in more details in the following section. In the real wireless network, a distance between two nodes can be derived from RSSI parameter (Receive Signal Strength Indication) or estimated by methods such as ToA (Time of Arrival) or AoA (Angle of Arrival) [11]. These techniques suffer from the certain distance estimation error and thus this error should be also implemented into the simulation model.

We consider that range-error of the distance measurement methods has a Gaussian distribution. The range error r is modeled by the Gaussian distribution with a mean = 0 and a standard deviation . In contrast to the many current researchers dealing with the range errors modeling, it is considered that is spread on the both sides from the value. Thus, the distance ri,j measured under the r can be calculated as shown in Eq. (2). The employed approach expresses situations where the measured signal strength is either strengthened by the interferences or suppressed by walls and obstacles. A decision about adding or subtracting the error portion to the distance should be made randomly. ri,j = di,j di,j r 100 (2)

100 Probability of connectivity [%]

80

60

40

20

10 12 14 16 18 20 22 Average node degree []

24

26

28

30

Fig. 1. Probability of connected network for 802.15.4 radio range (redrawn from [4]).

Algorithm: E=createNbrTable 1: row=1; 2: for all node pairs 3: 4: 5: 6: 7: 8: 9: 10: 11: x=abs(xi -xj ); y =abs(yi -yj ); dist=sqrt(x2 + y 2 ); if disti,j <R; plot([xi , xj ],[yi , yj ]; % draw edge E(row,1)=IDi ; E(row,2)=IDj ; E(row,3)=disti , j ; row + +;

If some WSN algorithms are to be investigated and theirs performance compared, they should be tested under the identical conditions. Hence, it is recommended to use the identical set of the networks graphs that should have different topologies (grid, random, L-shape, T-shape), scales (ten nodes up to thousands nodes) and node degrees (8 up to 26 neighbors per node). For the storing of all prepared networks, the struct function can be used. %STORE someName=struct(); someName.network(:,:,1)=network_1; save(file.mat,someName); %LOAD load file.mat; network_1=someName.network(:,:,1); In the previous paragraph we have mention that range of the node degree should be between 8 and 26. This range was taken from the work of Bettstetter [2] and Xue and Kumar [14]. They investigated the required R radio range and average node degree m (average number of neighbors) to ensure the connectivity of network. They stated that network is connected if for every pair of nodes there exists one-hop link or one multihop link respective. Results of these works showed that node degree in WSNs considered for probability of the connectivity greater than 0 has range of < 8, 26 > (see Fig. 1). Thus, this node degree range was implemented into the network models so that for each network size N = 50, 100, 400 nodes, ten degrees models were implemented, creating the set of 30 networks with different network size and degrees. This network database together with the demonstration Matlab les can be found in [10]. III. ROUTING IN A D H OC N ETWORK The data routing in wireless sensor network is realized on the links comparison base. The considered links between a sender and a receiver can be compared in terms of the length, link quality or residual energy of the node pairs. Nevertheless, the path with the smallest investigated value is selected as the route for the data delivery. For the discovering of the optimal

E matrix
IDi 1 1 1 2 2 . . . IDj 2 3 8 1 8 . . . disti,j 15.65 9.21 21.54 15.65 11.12 . . .

Fig. 2. Pseudocode of layout visualization and E matrix denition. E matrix is illustrated bellow code.

route between two nodes in the graph data structure, a Matlab implementation of Dijkstras algorithm can be used. The Dijkstras algorithm is implemented within a grShortPath function that is included in grTheory Matlab toolbox [8]. [dSP,spi,j ]=grShortPath(E,IDi ,IDj ); The grShortPath function takes a E matrix of neighbors, source i and destination j node as an input arguments. It returns a dSP matrix with the shortest path between all node pairs in the network. Furthermore, it returns an sp vectors with the nodes constituting the shortest path between nodes i, j . The E matrix must have an exact form for the

correct grShortPath algorithm processing. It contains three columns, where the rst two columns contains the all nodes in the network that are neighbors of each other and third column contains the euclidean distance in meters between them. The E matrix can be created during the network layout printing, see Fig. 2. As was mentioned before, the link lengths between all node pairs are compared with the uniform radio range R and if the condition di,j < R is accomplished the link is displayed. The E matrix is created within this condition since all required parameters such as IDs of two neighbors and their distance d is known and condition of lengths is accomplished. The context of the E matrix is visualised also in Fig 2. If the link quality or residual energy are to be used instead of the distance between nodes for the route establishment, the information in the third column of E matrix can be substituted by the required information. Then the path between two nodes is selected as the path with the highest quality or path with the maximum energy. Fig. 3 shows results of the described functions. Source le oneRound.m for the WSN routing can be found in [10].
300 50 77 2534 58 1 40 60 16 80 75 78 27 76 5 42 46 43 24

studied by Basu and Redi [1]. For the simulation, it is considered to employ a Store-and-Forward mechanism. The nodes receive whole incoming message and after checking the header in the buffer take decision about a further processing. Hence, the energy cost EOx of the overhearing process can equal to the ERx . The n1 spends energy E1 = ETx + ERx . Furthermore, the relaying nodes receive message (1 ERX ), forward message (1 ETx ) and overhears the message sent from downstream node (1 EOx ). The energy dissipated by the relaying nodes equals to Erel = ETx + 2ERx . This assumption is implemented into the simulation network model.
a) Unicast cost
m1 x Rx n M1 R

b) Broadcast cost ni
Rxi n M3 Rxi Txi Rxi Rxi Rxi Tx3 Rx4

Radio Wave symbol explanation


... induces reception process Rx at all neighbors

n1

Tx1 m2 x Rx

Rxi

Rxi

n2
n M2

Tx2 m3 x Rx

n3

Relay node forwarding unicast message receives a one copy from the downstream neighbor: Ei=ETxi+2ERxi

n4

Transmission of one broadcast message induces a multiple receptions of its copy on same node: Ei=ETxi+mi ERxi+1

One transmission process Tx ...

2 250 81 73 200 45 y [m] 9 7 150 56 19 38 6 66 61 36

Fig. 4. Estimation of number of messages processed during unicast and broadcast transmissions

20 67 55 39 33 29 23 63 31 53 12 14 17 6249 65 41 35 30 10 54 57 18 26 71 44 37 68 13 21 3 48 79 8

11

64 70 74

100 4

72

50

47 32

22 69

51

52 5928 15 0 50 100 150 200 250 x [m] 300 350 400 450 500

Fig. 3. Network layout with the highlighted shortest path estimated by the grShortPath function.

To express the broadcast cost, the WMA (Wireless Multicast Advantage) introduced by Wieselthier et al. [13] was employed. The WMA describes rebroadcasting process as follows: All nodes lying within the communication range of the broadcasting node can receive its transmission. Considering the broadcast transmission where all nodes represent destinations of the demanded message, the communication cost of node ni (see Fig.4 b) ) that rebroadcasts message is affected by the presence of its own neighbors. Meaning that as node ni receives and rebroadcasts the message while consumes ERx + ETx , it also subsequently overhears the communication of all neighbors. This broadcast overhearing process is refereed to as a passive acknowledgment. The energy consumed by the broadcasting nodes can be expressed as: Ei = ERx + ETx + (mi 1)ERx (3)

IV. C OMMUNICATION C OST OF DATA G ATHERING Once the paths from all nodes to the given node representing the base station is known, the number of messages per each node processed during the data gathering can be estimated. Consider line of nodes n1 up to n4 in Fig. 4, where the n1 node initiates the unicast transmission. Given message is propagated to its neighbors due to the omnidirectional nature of the transmission. The desired neighbor n2 receives message, checks the routing information, checks cyclic redundancy (CRC) and forwards this message through the downstream path. As nodes use an omnidirectional antenna, a copy of this message with changed destination address is again received by the initiator node n1 . But at this moment, after the whole message is received, it is discarded since its destination address does not complies with an ID of a demanded node. Node n1 thus overhears the message that was not addressed for it. The overhearing effect in dense sensor networks was detaily

The (mi 1) parameter represents a convention that ni overhears the broadcast message from all nodes Mi , except one which receives message from. The Mi parameter stands for the set of the neighbor nodes of ni . This communication model was used in many recent works such as [12] and [13]. Readers interested in multicast transmissions we reffer to reference [6]. Calculation of the communication cost during a data gathering process can be easily realized by the periodic route establishment from all nodes to the base station and by recording of the message number processed by each node on the each route. The numbers of messages processed can be recorded into the RxTx matrix (see example in Table. II) that can classify the number of messages received, transmitted and overheard. The message processed by node is recorded only in case that given node has a sufcient energy to process it. This

TABLE II R X T X MATRIX ID Rx Tx Ox TOTAL 1 10 2 15 27 2 44 56 89 189 3 6 15 22 43 ... ... ... ... ... N 154 89 354 597

condition is guaranteed as follows. If node i are to send the message, the shortest route to the base station is established. Subsequently, for each node in the route is launched control mechanism that checks if all nodes has the sufcient energy to perform required task such as transmitting and forwarding (pure receiving process is realized only by the base station that is power supplied). To do so, energy model of message processing is dened and introduced in the following section. V. E NERGY M ODEL OF M ESSAGE P ROCESSING To dene the energy model we have studied a Zigbee specication [9] and supported it with the Zigbee protocol analysis with Daintree Sensor Network Analyzer [3]. The PHY and MAC of Zigbee nodes layers are dened by IEEE 802.15.4 while upper communication layers (NWK and APS layers) are dened by a Zigbee specication. The energy consumption of the certain communication mode such as sleep, idle, receive, transmit is directly proportional to time that given device spent in this mode. Energy consumption of the communication modes can be found in the device datasheets. For the simulation we use the information from Memsic IRIS datasheets [7]. A ATRF230 radio chip implemented in IRIS consumes 8A in sleep mode, 8 mA in idle mode, 16 mA during Rx and 17 mA in Tx mode. If a node wants to send a message, it turns on the radio chip into the the active mode and before accessing to the medium it waits a random time in units of backoff period and subsequently performs CCA (Clear Channel Assessment). The random number is integer from a range < 0; 2BE 1 >, whereas the BE value is incremented with each unsuccessful attempt [9]. Then the access time to the wireless medium can be calculated according to Eg. 4 [5]. The CCA detection time is dened as a period of a 8 symbols (16 s/symbol). InitiallBackof f P eriod + CCA = = (2BE =3 1) U nitBackof f P eriod + CCA = 7 320 s + 128 s = 2.368 ms If the node successfully accesses to the medium, it rst sends a Data Request message including ID of the demanded neighbor. The time that device spends in Rx/Tx mode during message processing is derived from the message size and the bitrate [kbps] of the radio chip (b =250 kbps for ATRF230). It was found by the analysis that size of the Data Request message is k =12 bytes, see Fig. 5. (4)

Fig. 5.

Estimation of Data Request message size.

Thus, the process time of k size message is equal to tk = (k 8)/(b 1000) = 0.38 ms for Data Request message. Then the energy consumed during transmitting ET x equals to: U [V] I [A] t[s] = 2.4 V 17 mA 0, 32 ms = 15 J. Here U parameter stands for a voltage supplement and I parameter stands for the current consumption in Tx(power of 3.2 dBm) mode.

Zigbee NWK (8 B) IEEE 802.15.4 (9 B) Zigbee APS (8 B) Payload (3 B) FCS (2 B)

Fig. 6.

Analysis of Zigbee data packet.

When the Data Request message is received by the receiver device, it transits from Rx to Tx mode (192 s) and sends back ACK message (size of ACK = 5 bytes). Once the ACK is received by the origin node it starts with transmitting of required data. Size of DATA message equals to the size of DATA PAYLOAD (data eld) plus necessary OVERHEAD (headers of the APS, NWK, MAC, PHY layers). It was studied by means of the Daintree analyzer that APS and NWK layer add 8 bytes plus 8 bytes and MAC and PHY layer extend the message for 9+2(FCS) bytes, see Fig. 6. Thus the overall size of DATA message with the 3 bytes payload equals to

30 bytes. The energy consumption during transmission of 30 bytes message equals to 3.9 mJ. The received data are again acknowledged by the ACK message. It is worthwhile no notice that Zigbee does not specify CCA and CSMA/CA method to applied for ACK messages. For illustration of the entire energy calculation, we assume only active mode to be included in the calculation together with the condition that IRx = IT x . Then the entire energy E consumed by the transmitting device can be derived from the time that it spends in the active mode: ttotal = (CCA)+(Tx data request)+(Rx/Tx receiver)+ + (Rx ack)+(Rx/Tx sender)+(Tx data)+ + (Rx/Tx receiver)+(Rx ack)= = 2.368 + 0.32 + 0.192 + 0.16 + 0.192+ + 0.96 + 0.192 + 0.16 = 4.54 ms (5) The entire energy dissipated by the sender radio chip equals to: Esender = 2.4 [V] 17 [mA] 4.54 [ms] = 185 J. Detailed description of the IEEE 802.15.4 time processing can be found in [5]. In same way, the energy consumption for all nodes in the unicast route can be estimated. However, the energy model should be optimized with the exact current consumption of the Rx and Tx processes, we have showed only simplied calculation. VI. S IMULATION OF DESCRIBED MODEL The introduced model was implemented in the Matlab environment to validate its performance. We have congured a scenario with N = 100 randomly deployed node, where each node had energy storage of 1 J. The data from all nodes is unicasted in rounds meaning that during one round, all nodes unicast data toward the base station (randomly selected node). The residual energy of the nodes should be visualized by the color of nodes. The result of simulation is the energy colored topology and graph of the live nodes number in dependency on the number of rounds. As was mentioned in the Introduction section, the simulation ends when there is no way how to route data to the base station. It means that all one-hop nodes around base station depleted own energy. Results of the simulation are shown in Fig.7 and Fig. 8. One can notice from Fig. 7 that nodes placed close to the base station (placed on the x-axis) are loaded with the enormous network trafc since their residual energy is half in comparison to the far-away nodes. The simulation statistics showed that nodes with one Joule transmitted 2243 messages. We can see from Fig. 8 that network operated more than 160 rounds while the rst nodes depleted energy before the 80th round (2243 messages transmitted). From the mentioned implies that with the 1 Joule origin energy, the entire wireless sensor network can transmit maximally 160 measurements. VII. C ONCLUSION This paper does not aim to bring the novel results from the wireless sensor networking. Instead it aims to serve as

100-81%
110

81-60%

61-40%

41-20%

< 20%

100

90

80

70

60 y [m] 50 40 30 20 10 R 0 0 10 20 30 Base station 40 50 x [m] 60 70 80 90 100 110

Fig. 7.

Energy map after simulation.


100 99

percentage of alive nodes []

98 97 96 95 94 93 92 91 90 0 20 40 60 80 100 rounds [] 120 140 160 180

Fig. 8.

Percentage of live nodes during simulation.

the guideline for the student and researchers that want to validate in Matlab environment own algorithm proposed for the WSN applications. We have showed how to proposed and visualize WSN topology and how to route data through the multihop paths. We have also proposed energy model that can be used for transformation of the communication cost to the energy consumption. The ideas in proposed energy model were supported by the analysis of the real Zigbee network. We notify, that only simplied energy model was stated here. The nodes spent most of time in the sleep mode and thus the signicant attention should be devoted to this factor. ACKNOWLEDGMENT This paper was prepared within the framework of No. FRVS IS18049001 project of the Czech Ministry of Education, Youth and Sports and No. FRTI2/571 grant project of the Ministry of Industry and Trade of the Czech Republic R EFERENCES [1] P. Basu and J. Redi, Effect of Overhearing Transmissions on Energy Efciency in Dense Sensor Networks,

[2]

[3]

[4]

[5] [6]

[7] [8]

[9] [10]

[11]

[12]

[13]

[14]

in IPSN 04: Proceedings of the 3rd international symposium on Information processing in sensor networks. New York, NY, USA: ACM, 2004, pp. 196204. C. Bettstetter, On the Minimum Node Degree and Connectivity of a Wireless Multihop Network, in MobiHoc 02: Proceedings of the 3rd ACM international symposium on Mobile ad hoc networking & computing. New York, NY, USA: ACM, 2002, pp. 8091. Daintree Networks. (2010) Sensor Network Analyzer(SNA)@ONLINE. [Online]. Available: http://www.daintree.net/sna/sna.php J. C. Hou, N. Li, and I. Stojmenovic, Topology construction and maintanance in wireless sensor networks, in Handbook of Sensor Networks: Algorithms and Architectures, I. Stojmenovic, Ed. John Wiley and Sons, Sep. 2005, pp. 311341. Jennic., Jennic Inc., Calculating 802.15.4 Data Rates, 2006. M. Koutny, J. Misurec, and P. Mlynek, The new approaches of a multicasting in the wireless sensor networks, in 33rd International Conference on TELECOMMUNICATIONS AND SIGNAL PROCESSING TSP 2010. Budapest, Szent Istvn krt. 7.: Asszisztencia Szervezo Kft., 2010, pp. 342345. Memsic Technology Inc., IRIS XM2110CA Data Sheet. [Online]. Available: http://www.memsic.com I. Sergii. (2009) grTheory - Graph Theory Toolbox, MATLAB CENTRAL@ONLINE. [Online]. Available: http://www.mathworks.com/matlabcentral/leexchange/4266 F. Shanin, Zigbee Wireless Networks and Transceivers. Oxford: Elsevier, 2008. M. Simek. (2010) Low Power Wireless & Sensor Laboratory@ONLINE. [Online]. Available: http://wsnbase.utko.feec.vutbr.cz , Reference Node Selection for Anchor free Localization in Wireless Sensor Networks, Ph.D. dissertation, Brno University of Technology, Purkynova 118, 612 00, Brno, Czech Republic, September 2010. S. Singh and C. S. Raghavendra, PAMASPower Aware Multi-Access Protocol with Signalling for Ad hoc Networks, SIGCOMM Comput. Commun. Rev., vol. 28, no. 3, pp. 526, 1998. J. E. Wieselthier, G. D. Nguyen, and A. Ephremides, On the Construction of Energy-Efcient Broadcast and Multicast Trees in Wireless Networks, in INFOCOM 2000. Nineteenth Annual Joint Conference of the IEEE Computer and Communications Societies. Proceedings. IEEE, vol. 2, 2000, pp. 585594 vol.2. [Online]. Available: http://dx.doi.org/10.1109/INFCOM.2000.832232 F. Xue and P. R. Kumar, The Number of Neighbors Needed for Connectivity of Wireless Networks, Wirel. Netw., vol. 10, no. 2, pp. 169181, 2004.

Вам также может понравиться