├── README.md ├── Chapter_edit.docx ├── Result └── Fuzzy │ ├── FIS1.JPG │ ├── FIS2.JPG │ ├── FIS3.JPG │ ├── FIS4.JPG │ ├── FIS5.JPG │ └── FIS6.JPG ├── plot1.m ├── fig.m ├── prob.m ├── clusterOptimum.m ├── start.m ├── newRound.m ├── plotResults.m ├── newNodes.m ├── dissEnergyCH.m ├── createfigure.m ├── dissEnergyNonCH.m ├── newCluster.m ├── leach.m └── newNetwork.m /README.md: -------------------------------------------------------------------------------- 1 | # LeachWithFuzzy -------------------------------------------------------------------------------- /Chapter_edit.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Chapter_edit.docx -------------------------------------------------------------------------------- /Result/Fuzzy/FIS1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS1.JPG -------------------------------------------------------------------------------- /Result/Fuzzy/FIS2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS2.JPG -------------------------------------------------------------------------------- /Result/Fuzzy/FIS3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS3.JPG -------------------------------------------------------------------------------- /Result/Fuzzy/FIS4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS4.JPG -------------------------------------------------------------------------------- /Result/Fuzzy/FIS5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS5.JPG -------------------------------------------------------------------------------- /Result/Fuzzy/FIS6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darshil93/Wireless-Sensor-Networks---LEACH/HEAD/Result/Fuzzy/FIS6.JPG -------------------------------------------------------------------------------- /plot1.m: -------------------------------------------------------------------------------- 1 | figure(1), hold on 2 | plot(nodeArch.nodesLoc(:, 1), nodeArch.nodesLoc(:, 2),... 3 | '.', 'MarkerSize',15); 4 | plot(netArch.Sink.x, netArch.Sink.y,'o', ... 5 | 'MarkerSize',8, 'MarkerFaceColor', 'g'); -------------------------------------------------------------------------------- /fig.m: -------------------------------------------------------------------------------- 1 | function fig(data, r, n, yLabel, Title) 2 | % plot data vs. round 3 | 4 | figure(2); 5 | subplot(1, 3, n); 6 | plot(1:r, data); 7 | xlabel('Round'); 8 | ylabel(yLabel); 9 | title(Title); 10 | end -------------------------------------------------------------------------------- /prob.m: -------------------------------------------------------------------------------- 1 | function P = prob(r, p) 2 | % Probability function for elect the node as CH 3 | % Input: 4 | % r round no 5 | % p p? 6 | % Example: 7 | % P = prob(1, 0.1); 8 | % 9 | % Hossein Dehghan, hd.dehghan@gmail.com 10 | % Ver 1. 2/2013 11 | % 12 | if ~exist('p','var') 13 | p = 0.1; 14 | end 15 | 16 | P = p / (1-p * mod(r, round(1 / p))); 17 | end -------------------------------------------------------------------------------- /clusterOptimum.m: -------------------------------------------------------------------------------- 1 | function kOpt = clusterOptimum(netArch, nodeArch, dBS) 2 | % calculate the optimum valuse for number of nodes 3 | % 4 | % Input: 5 | % netArch network model 6 | % nodeArch nodes model 7 | % dBS length from base station 8 | % Example: 9 | % dBS = sqrt(netArch.Sink.x ^ 2 + netArch.Sink.y ^ 2); 10 | % numClusters = clusterOptimum(netArch, nodeArch, dBS); 11 | 12 | N = nodeArch.numNode; % number of nodes 13 | M = sqrt(netArch.Yard.Length * netArch.Yard.Width); 14 | kOpt = sqrt(N) / sqrt(2*pi) * ... 15 | sqrt(netArch.Energy.freeSpace / netArch.Energy.multiPath) * ... 16 | M / dBS ^ 2; 17 | kOpt = round(kOpt); 18 | end -------------------------------------------------------------------------------- /start.m: -------------------------------------------------------------------------------- 1 | clc, clear all, close all 2 | 3 | numNodes = 100; % number of nodes 4 | p = 0.1; 5 | 6 | netArch = newNetwork(100, 100, 50, 175); 7 | nodeArch = newNodes(netArch, numNodes); 8 | roundArch = newRound(); 9 | 10 | plot1 11 | 12 | par = struct; 13 | 14 | for r = 1:roundArch.numRound 15 | r 16 | clusterModel = newCluster(netArch, nodeArch, 'leach', r, p); 17 | clusterModel = dissEnergyCH(clusterModel, roundArch); 18 | clusterModel = dissEnergyNonCH(clusterModel, roundArch); 19 | nodeArch = clusterModel.nodeArch; % new node architecture after select CHs 20 | 21 | par = plotResults(clusterModel, r, par); 22 | if nodeArch.numDead == nodeArch.numNode 23 | break 24 | end 25 | end 26 | 27 | 28 | -------------------------------------------------------------------------------- /newRound.m: -------------------------------------------------------------------------------- 1 | function NetRound = newRound(numRound, packetLength, ctrPacketLength) 2 | % Create the round architecture for specific parameters 3 | % 4 | % Input: 5 | % numRound Number of rounds 6 | % packetLength Length of packet that sent for CH to BS 7 | % ctrPacketLength Length of packet that sent for nodes to CH 8 | % Example: 9 | % NetRound = newRound(); 10 | 11 | if ~exist('numRound','var') 12 | NetRound.numRound = 9999; % default of the maximum round is 9999 13 | else 14 | NetRound.numRound = numRound; 15 | end 16 | if ~exist('packetLength','var') 17 | NetRound.packetLength = 6400; % default of the packet length is 6400 18 | else 19 | NetRound.packetLength = packetLength; 20 | end 21 | if ~exist('ctrPacketLength','var') 22 | NetRound.ctrPacketLength = 200; 23 | else 24 | NetRound.ctrPacketLength = ctrPacketLength; 25 | end 26 | end -------------------------------------------------------------------------------- /plotResults.m: -------------------------------------------------------------------------------- 1 | function par = plotResults(clusterModel, r, par) 2 | nodeArch = clusterModel.nodeArch; 3 | netArch = clusterModel.netArch; 4 | 5 | 6 | %%%%% number of packets sent from CHs to BS 7 | if r == 1 8 | par.packetToBS(r) = clusterModel.numCluster; 9 | else 10 | par.packetToBS(r) = par.packetToBS(r-1) + clusterModel.clusterNode.countCHs; 11 | end 12 | % Figure packet to BS 13 | % fig(par.packetToBS, r, 1, '# of packets sent to BS nodes', ... 14 | % 'Number of packet sent to BS vs. round'); 15 | 16 | %%%%% Number of dead neurons 17 | par.numDead(r) = nodeArch.numDead; 18 | % Figure number of dead node 19 | % fig(par.numDead, r, 2, '# of dead nodes', 'Number of dead node vs. round'); 20 | 21 | %%%%% Energy 22 | par.energy(r) = 0; 23 | node = clusterModel.nodeArch; 24 | for i = find(~node.dead) 25 | if node.node(i).energy > 0 26 | par.energy(r) = par.energy(r) + node.node(i).energy; 27 | end 28 | end 29 | % fig(par.energy, r, 3, 'sum of energy', 'Sum of energy of nodes vs. round'); 30 | 31 | createfigure(1:r, par.energy, par.packetToBS, par.numDead); 32 | end 33 | -------------------------------------------------------------------------------- /newNodes.m: -------------------------------------------------------------------------------- 1 | function nodeArch = newNodes(netArch, numNode) 2 | % Create the node model randomly 3 | % 4 | % Input: 5 | % netArch Network architecture 6 | % numNode Number of Nodes in the field 7 | % Output: 8 | % nodeArch Nodes architecture 9 | % nodesLoc Location of Nodes in the field 10 | % Example: 11 | % netArch = createNetwork(); 12 | % nodeArch = createNodes(netArch, 100) 13 | 14 | if ~exist('netArch','var') 15 | netArch = newNetwork(); 16 | end 17 | 18 | if ~exist('numNode','var') 19 | numNode = 100; 20 | end 21 | for i = 1:numNode 22 | % x cordination of node 23 | nodeArch.node(i).x = rand * netArch.Yard.Length; 24 | nodeArch.nodesLoc(i, 1) = nodeArch.node(i).x; 25 | % y cordination of node 26 | nodeArch.node(i).y = rand * netArch.Yard.Width; 27 | nodeArch.nodesLoc(i, 2) = nodeArch.node(i).y; 28 | % the flag which determines the value of the indicator function? Ci(t) 29 | nodeArch.node(i).G = 0; 30 | % initially there are no cluster heads, only nodes 31 | nodeArch.node(i).type = 'N'; % 'N' = node (nun-CH) 32 | nodeArch.node(i).energy = netArch.Energy.init; 33 | 34 | nodeArch.node(i).CH = -1; % number of its CH ? 35 | nodeArch.dead(i) = 0; % the node is alive 36 | end 37 | nodeArch.numNode = numNode; % Number of Nodes in the field 38 | nodeArch.numDead = 0; % number of dead nodes 39 | end -------------------------------------------------------------------------------- /dissEnergyCH.m: -------------------------------------------------------------------------------- 1 | function clusterModel = dissEnergyCH(clusterModel, roundArch) 2 | % Calculation of Energy dissipated for CHs 3 | % Input: 4 | % clusterModel architecture of nodes, network 5 | % roundArch round Architecture 6 | % Example: 7 | % r = 10; % round no = 10 8 | % clusterModel = newCluster(netArch, nodeArch, 'def', r); 9 | % clusterModel = dissEnergyCH(clusterModel); 10 | 11 | nodeArch = clusterModel.nodeArch; 12 | netArch = clusterModel.netArch; 13 | cluster = clusterModel.clusterNode; 14 | 15 | d0 = sqrt(netArch.Energy.freeSpace / ... 16 | netArch.Energy.multiPath); 17 | if cluster.countCHs == 0 18 | return 19 | end 20 | n = length(cluster.no); % Number of CHs 21 | ETX = netArch.Energy.transfer; 22 | ERX = netArch.Energy.receive; 23 | EDA = netArch.Energy.aggr; 24 | Emp = netArch.Energy.multiPath; 25 | Efs = netArch.Energy.freeSpace; 26 | packetLength = roundArch.packetLength; 27 | ctrPacketLength = roundArch.ctrPacketLength; 28 | for i = 1:n 29 | chNo = cluster.no(i); 30 | distance = cluster.distance(i); 31 | energy = nodeArch.node(chNo).energy; 32 | % energy for aggregation the data + energy for transfering to BS 33 | if(distance >= d0) 34 | nodeArch.node(chNo).energy = energy - ... 35 | ((ETX+EDA) * packetLength + Emp * packetLength * (distance ^ 4)); 36 | else 37 | nodeArch.node(chNo).energy = energy - ... 38 | ((ETX+EDA) * packetLength + Efs * packetLength * (distance ^ 2)); 39 | end 40 | nodeArch.node(chNo).energy = nodeArch.node(chNo).energy - ... 41 | ctrPacketLength * ERX * round(nodeArch.numNode / clusterModel.numCluster); 42 | end 43 | 44 | clusterModel.nodeArch = nodeArch; 45 | end -------------------------------------------------------------------------------- /createfigure.m: -------------------------------------------------------------------------------- 1 | function createfigure(X1, Y1, Y2, Y3) 2 | %CREATEFIGURE(X1,Y1,Y2,Y3) 3 | % X1: vector of x data 4 | % Y1: vector of y data 5 | % Y2: vector of y data 6 | % Y3: vector of y data 7 | 8 | % Auto-generated by MATLAB on 31-Jan-2013 18:49:05 9 | 10 | % Create figure 11 | figure1 = figure(2); 12 | 13 | % Create subplot 14 | subplot1 = subplot(1,3,3,'Parent',figure1); 15 | box(subplot1,'on'); 16 | hold(subplot1,'all'); 17 | 18 | % Create plot 19 | plot(X1,Y1,'Parent',subplot1,'LineWidth',2,'Color',[0 1 0]); 20 | 21 | % Create xlabel 22 | xlabel('Round','FontWeight','bold','FontSize',11,'FontName','Cambria'); 23 | 24 | % Create ylabel 25 | ylabel('sum of energy','FontWeight','bold','FontSize',11,... 26 | 'FontName','Cambria'); 27 | 28 | % Create title 29 | title('Sum of energy of nodes vs. round','FontWeight','bold','FontSize',12,... 30 | 'FontName','Cambria'); 31 | 32 | % Create subplot 33 | subplot2 = subplot(1,3,1,'Parent',figure1); 34 | box(subplot2,'on'); 35 | hold(subplot2,'all'); 36 | 37 | % Create plot 38 | plot(X1,Y2,'Parent',subplot2,'LineWidth',2); 39 | 40 | % Create xlabel 41 | xlabel('Round','FontWeight','bold','FontSize',11,'FontName','Cambria'); 42 | 43 | % Create ylabel 44 | ylabel('# of packets sent to BS nodes','FontWeight','bold','FontSize',11,... 45 | 'FontName','Cambria'); 46 | 47 | % Create title 48 | title('Number of packet sent to BS vs. round','FontWeight','bold',... 49 | 'FontSize',12,... 50 | 'FontName','Cambria'); 51 | 52 | % Create subplot 53 | subplot3 = subplot(1,3,2,'Parent',figure1); 54 | box(subplot3,'on'); 55 | hold(subplot3,'all'); 56 | 57 | % Create plot 58 | plot(X1,Y3,'Parent',subplot3,'LineWidth',2,'Color',[1 0 0]); 59 | 60 | % Create xlabel 61 | xlabel('Round','FontWeight','bold','FontSize',11,'FontName','Cambria'); 62 | 63 | % Create ylabel 64 | ylabel('# of dead nodes','FontWeight','bold','FontSize',11,... 65 | 'FontName','Cambria'); 66 | 67 | % Create title 68 | title('Number of dead node vs. round','FontWeight','bold','FontSize',12,... 69 | 'FontName','Cambria'); 70 | 71 | -------------------------------------------------------------------------------- /dissEnergyNonCH.m: -------------------------------------------------------------------------------- 1 | function clusterModel = dissEnergyNonCH(clusterModel, roundArch) 2 | % Calculation of Energy dissipated for CHs 3 | % Input: 4 | % clusterModel architecture of nodes, network 5 | % roundArch round Architecture 6 | % Example: 7 | % r = 10; % round no = 10 8 | % clusterModel = newCluster(netArch, nodeArch, 'def', r); 9 | % clusterModel = dissEnergyCH(clusterModel); 10 | 11 | nodeArch = clusterModel.nodeArch; 12 | netArch = clusterModel.netArch; 13 | cluster = clusterModel.clusterNode; 14 | if cluster.countCHs == 0 15 | return 16 | end 17 | d0 = sqrt(netArch.Energy.freeSpace / ... 18 | netArch.Energy.multiPath); 19 | ETX = netArch.Energy.transfer; 20 | ERX = netArch.Energy.receive; 21 | EDA = netArch.Energy.aggr; 22 | Emp = netArch.Energy.multiPath; 23 | Efs = netArch.Energy.freeSpace; 24 | packetLength = roundArch.packetLength; 25 | ctrPacketLength = roundArch.ctrPacketLength; 26 | 27 | locAlive = find(~nodeArch.dead); % find the nodes that are alive 28 | for i = locAlive % seach in alive nodes 29 | %find Associated CH for each normal node 30 | if strcmp(nodeArch.node(i).type, 'N') && ... 31 | nodeArch.node(i).energy > 0 32 | 33 | locNode = [nodeArch.node(i).x, nodeArch.node(i).y]; 34 | countCH = length(clusterModel.clusterNode.no); % Number of CHs 35 | % calculate distance to each CH and find smallest distance 36 | [minDis, loc] = min(sqrt(sum((repmat(locNode, countCH, 1) - cluster.loc)' .^ 2))); 37 | minDisCH = cluster.no(loc); 38 | 39 | if (minDis > d0) 40 | nodeArch.node(i).energy = nodeArch.node(i).energy - ... 41 | ctrPacketLength * ETX + Emp * packetLength * (minDis ^ 4); 42 | else 43 | nodeArch.node(i).energy = nodeArch.node(i).energy - ... 44 | ctrPacketLength * ETX + Efs * packetLength * (minDis ^ 2); 45 | end 46 | %Energy dissipated 47 | if(minDis > 0) 48 | nodeArch.node(minDisCH).energy = nodeArch.node(minDisCH).energy - ... 49 | ((ERX + EDA) * packetLength ); 50 | end 51 | end % if 52 | end % for 53 | clusterModel.nodeArch = nodeArch; 54 | end -------------------------------------------------------------------------------- /newCluster.m: -------------------------------------------------------------------------------- 1 | function clusterModel = newCluster(netArch, nodeArch, ... 2 | clusterFun, clusterFunParam, p_numCluster) 3 | % Create the network architecture with desired parameters 4 | % 5 | % Input: 6 | % clusterFun Function name for clustering algorithm. 7 | % clusterFunParam Parameters for the cluster function 8 | % numCluster Number of clusters (CHs) 9 | % netArch Network model 10 | % nodeArch Nodes model 11 | % Example: 12 | % clusterModel = newCluster(); 13 | 14 | % set the parameters 15 | if ~exist('clusterFun','var') 16 | clusterFun = 'leach'; % default for clustering the node is leach algorithm 17 | end 18 | if strcmp(clusterFun, 'def') 19 | clusterFun = 'leach'; % default for clustering the node is leach algorithm 20 | end 21 | clusterModel.clusterFun = clusterFun; 22 | 23 | if ~exist('clusterFunParam','var') 24 | clusterFunParam = []; 25 | end 26 | clusterModel.clusterFunParam = clusterFunParam; 27 | 28 | if ~exist('netArch','var') 29 | netArch = newNetwork(); 30 | end 31 | clusterModel.netArch = netArch; 32 | 33 | if ~exist('nodeArch','var') 34 | nodeArch = newNodes(); 35 | end 36 | clusterModel.nodeArch = nodeArch; 37 | 38 | if ~exist('p_numCluster','var') 39 | dBS = sqrt((netArch.Sink.x - netArch.Yard.Length) ^ 2 + ... 40 | (netArch.Sink.y - netArch.Yard.Width) ^ 2); 41 | numCluster = clusterOptimum(netArch, nodeArch, dBS); 42 | p = 1 / numCluster; 43 | else 44 | if p_numCluster < 1 45 | p = p_numCluster; 46 | numCluster = 1 / p; 47 | else 48 | numCluster = p_numCluster; 49 | p = 1 / numCluster; 50 | end 51 | end 52 | %p = Optimal Election Probability of a node to become cluster head 53 | clusterModel.numCluster = numCluster; 54 | clusterModel.p = p; 55 | 56 | % run the clustering algorithm 57 | addpath Cluster % put the clustering algorithm in the cluster folder 58 | [nodeArch, clusterNode] = feval(clusterFun, clusterModel, clusterFunParam); % execute the cluster function 59 | 60 | clusterModel.nodeArch = nodeArch; % new architecture of nodes 61 | clusterModel.clusterNode = clusterNode; % the CHs 62 | end -------------------------------------------------------------------------------- /leach.m: -------------------------------------------------------------------------------- 1 | function [nodeArch, clusterNode] = leach(clusterModel, clusterFunParam) 2 | % Create the new node architecture using leach algorithm in beginning 3 | % of each rond. This function is called by newCluster function. 4 | % 5 | % Input: 6 | % clusterModel Cluster model by newCluster function 7 | % clusterFunParam Parameters for the cluster function 8 | % [r ] 9 | % Example: 10 | % [nodeArch, clusterNode] = feval('leach', clusterModel, clusterFunParam); 11 | % 12 | % Hossein Dehghan, hd.dehghan@gmail.com 13 | % Ver 1. 2/2013 14 | 15 | nodeArch = clusterModel.nodeArch; 16 | netArch = clusterModel.netArch; 17 | r = clusterFunParam(1); % round no 18 | p = clusterModel.p; 19 | N = nodeArch.numNode; % number of nodes 20 | 21 | %%%%%%%% reset the CH afret numCluster round 22 | if (mod(r, clusterModel.numCluster) == 0) 23 | for i = 1:N 24 | nodeArch.node(i).G = 0; % not selected for CH 25 | end 26 | end 27 | 28 | %%%%%%%% Checking if there is a dead node 29 | locAlive = find(~nodeArch.dead); % find the nodes that are alive 30 | for i = locAlive 31 | if nodeArch.node(i).energy <= 0 32 | nodeArch.node(i).type = 'D'; 33 | nodeArch.dead(i) = 1; 34 | else 35 | nodeArch.node(i).type = 'N'; 36 | end 37 | end 38 | nodeArch.numDead = sum(nodeArch.dead); 39 | 40 | %%%%%%%% find the cluster head 41 | % define cluster structure 42 | clusterNode = struct(); 43 | % 44 | locAlive = find(~nodeArch.dead); % find the nodes that are alive 45 | countCHs = 0; 46 | for i = locAlive % seach in alive nodes 47 | temp_rand = rand; 48 | if (nodeArch.node(i).G <= 0) && ... 49 | (temp_rand <= prob(r, p)) && ... 50 | (nodeArch.node(i).energy > 0) 51 | 52 | countCHs = countCHs+1; 53 | 54 | nodeArch.node(i).type = 'C'; 55 | nodeArch.node(1,1).G = round(1/p)-1; 56 | clusterNode.no(countCHs) = i; % the no of node 57 | xLoc = nodeArch.node(i).x; % x location of CH 58 | yLoc = nodeArch.node(i).y; % y location of CH 59 | clusterNode.loc(countCHs, 1) = xLoc; 60 | clusterNode.loc(countCHs, 2) = yLoc; 61 | % Calculate distance of CH from BS 62 | clusterNode.distance(countCHs) = sqrt((xLoc - netArch.Sink.x)^2 + ... 63 | (yLoc - netArch.Sink.y)^2); 64 | end % if 65 | end % for 66 | clusterNode.countCHs = countCHs; 67 | end -------------------------------------------------------------------------------- /newNetwork.m: -------------------------------------------------------------------------------- 1 | function NetArch = newNetwork(Length, Width, sinkX, sinkY, initEnergy... 2 | , transEnergy, recEnergy, fsEnergy, mpEnergy, aggrEnergy) 3 | % Create the network architecture with desired parameters 4 | % 5 | % Input: 6 | % Length Length of the yard 7 | % Width Width of the yard 8 | % sinkX x cordination of base station 9 | % sinkY y cordination of base station 10 | % initEnergy Initial energy of each node 11 | % transEnergy Enery for transferring of each bit (ETX) 12 | % recEnergy Enery for receiving of each bit (ETX) 13 | % fsEnergy Energy of free space model 14 | % mpEnergy Energy of multi path model 15 | % aggrEnergy Data aggregation energy 16 | % Example: 17 | % NetArch = createNetwork(); 18 | 19 | %%%% Create the yard 20 | Yard.Type = 'Rect'; % Rectangular 21 | if ~exist('Length','var') 22 | Yard.Length = 100; % default of the yard is 100 in x cordination 23 | else 24 | Yard.Length = Length; 25 | end 26 | if ~exist('Width','var') 27 | Yard.Width = 100; % default of the yard is 100 in y cordination 28 | else 29 | Yard.Width = Width; 30 | end 31 | 32 | %%%% Create base station 33 | % x and y Coordinates of the base station 34 | % default of the base station is in the center of the yard 35 | if ~exist('sinkX','var') 36 | Sink.x = Yard.Length / 2; 37 | else 38 | Sink.x = sinkX; 39 | end 40 | if ~exist('sinkY','var') 41 | Sink.y = Yard.Width / 2; 42 | else 43 | Sink.y = sinkY; 44 | end 45 | 46 | %%%% Energy Model (all values in Joules) 47 | % Initial Energy 48 | if ~exist('initEnergy','var') 49 | Energy.init = 0.5; 50 | else 51 | Energy.init = initEnergy; 52 | end 53 | 54 | % Enery for transferring of each bit (ETX) 55 | if ~exist('transEnergy','var') 56 | Energy.transfer = 50*0.000000001; 57 | else 58 | Energy.transfer = transEnergy; 59 | end 60 | if ~exist('recEnergy','var') 61 | Energy.receive = 50*0.000000001; 62 | else 63 | Energy.receive = recEnergy; 64 | end 65 | 66 | % Transmit Amplifier types 67 | if ~exist('recEnergy','var') 68 | Energy.freeSpace = 10*0.000000000001; 69 | else 70 | Energy.freeSpace = fsEnergy; 71 | end 72 | if ~exist('recEnergy','var') 73 | Energy.multiPath = 0.0013*0.000000000001; 74 | else 75 | Energy.multiPath = mpEnergy; 76 | end 77 | 78 | %Data Aggregation Energy 79 | if ~exist('recEnergy','var') 80 | Energy.aggr = 5*0.000000001; 81 | else 82 | Energy.aggr = aggrEnergy; 83 | end 84 | 85 | NetArch = struct('Yard', Yard, ... 86 | 'Sink', Sink, ... 87 | 'Energy', Energy); 88 | end --------------------------------------------------------------------------------