To simulate the Low-Energy Adaptive Clustering Hierarchy (LEACH) using MATLAB environment which is a well-known routing protocol for wireless sensor networks (WSNs). LEACH works by categorizing nodes into clusters along with a cluster head (CH), which combines data from their member nodes before sending it to a central base station (BS). The key aim of LEACH is to minimize energy consumption by turning the CH role between nodes and executing the data aggregation.
Please feel free to reach out to phdprime.com via email, and we will provide you with the finest guidance on simulations, accompanied by comprehensive explanations. Our team specializes in nodes and data aggregation, offering you detailed insights into network comparisons. For simulating Leach Routing Projects using the MATLAB tool, we at phdprime.com are committed to delivering the ultimate solution with complete support throughout the process.
Here’s a step-by-step instructions to simulate the LEACH Protocol in MATLAB.
Steps to Simulate LEACH Routing in MATLAB
- Define Network Parameters and Node Positions:
- Describe the amount of nodes, the network area, and the base station’s location.
- Set the nodes arbitrarily within the described area.
% Parameters
numNodes = 100; % Total number of sensor nodes
areaSize = 100; % Area (100 x 100 meters)
baseStation = [50, 50]; % Position of the base station
clusterHeadPercentage = 0.05; % Percentage of nodes to be chosen as CHs
initialEnergy = 0.5; % Initial energy for each node (Joules)
% Randomly place nodes in the area
nodePositions = rand(numNodes, 2) * areaSize;
nodeEnergy = ones(numNodes, 1) * initialEnergy;
- Define LEACH Parameters:
- Indicate the amount of rounds, the possibility of turning out to be a CH, and the energy consumption model metrics.
% LEACH Parameters
numRounds = 20; % Number of LEACH rounds
p = clusterHeadPercentage; % Probability of becoming a CH
% Energy model parameters
E_tx = 50e-9; % Transmit energy per bit (50 nJ/bit)
E_rx = 50e-9; % Receive energy per bit (50 nJ/bit)
E_fs = 10e-12; % Free space model energy (10 pJ/bit/m^2)
E_mp = 0.0013e-12; % Multi-path model energy (0.0013 pJ/bit/m^4)
d0 = sqrt(E_fs / E_mp); % Threshold distance (meters)
packetSize = 4000; % Packet size in bits
- Cluster Formation and Cluster Head Selection:
- In each round, choose the nodes as CHs according to a probability.
- Each non-CH node connects with the closest CH.
% Function to calculate energy consumption for transmission
function E = energyConsumption(distance, packetSize)
if distance < d0
E = packetSize * (E_tx + E_fs * distance^2);
else
E = packetSize * (E_tx + E_mp * distance^4);
end
end
% Run LEACH for the specified number of rounds
for round = 1:numRounds
disp([‘Round ‘, num2str(round)]);
% Step 1: Cluster Head Selection
clusterHeads = rand(numNodes, 1) < p;
for i = 1:numNodes
if nodeEnergy(i) <= 0
clusterHeads(i) = 0; % Depleted nodes cannot be CHs
end
end
% Step 2: Cluster Formation
clusters = cell(numNodes, 1); % Each cell stores members of the cluster
for i = 1:numNodes
if ~clusterHeads(i) && nodeEnergy(i) > 0
% Find the closest cluster head
distancesToCH = sqrt(sum((nodePositions(clusterHeads, 🙂 – nodePositions(i, :)).^2, 2));
[~, closestCHIdx] = min(distancesToCH);
clusterHeadIndex = find(clusterHeads);
clusters{clusterHeadIndex(closestCHIdx)} = [clusters{clusterHeadIndex(closestCHIdx)}, i];
end
end
% Step 3: Data Transmission to Cluster Heads
for i = 1:numNodes
if clusterHeads(i)
% Aggregated data packet to BS
distanceToBS = norm(nodePositions(i, 🙂 – baseStation);
nodeEnergy(i) = nodeEnergy(i) – energyConsumption(distanceToBS, packetSize);
else
% Send data to cluster head
for chIdx = 1:numNodes
if ismember(i, clusters{chIdx})
distanceToCH = norm(nodePositions(i, 🙂 – nodePositions(chIdx, :));
nodeEnergy(i) = nodeEnergy(i) – energyConsumption(distanceToCH, packetSize);
nodeEnergy(chIdx) = nodeEnergy(chIdx) – packetSize * E_rx; % CH receives data
end
end
end
end
% Display remaining energy of nodes
disp([‘Remaining Energy after Round ‘, num2str(round), ‘:’]);
disp(nodeEnergy);
end
- Plot Network Topology and Clustering (Optional):
- Envision the network that displaying the positions of nodes, cluster heads, and the base station.
plot(nodePositions(:, 1), nodePositions(:, 2), ‘bo’); % Plot nodes
plot(baseStation(1), baseStation(2), ‘rs’, ‘MarkerSize’, 10); % Plot BS
title([‘LEACH Network Topology – Round ‘, num2str(round)]);
xlabel(‘X Position (m)’);
ylabel(‘Y Position (m)’);
legend(‘Sensor Nodes’, ‘Base Station’);
% Mark Cluster Heads
plot(nodePositions(clusterHeads, 1), nodePositions(clusterHeads, 2), ‘go’, ‘MarkerSize’, 8);
hold off;
- Analyze Network Lifetime and Energy Efficiency (Optional):
- After each round, monitor the amount of active nodes and compute the network lifetime depends on the number of rounds until a specified percentage of nodes are exhaust its energy.
% Calculate network lifetime based on the number of active nodes
activeNodes = sum(nodeEnergy > 0);
disp([‘Number of active nodes after Round ‘, num2str(round), ‘: ‘, num2str(activeNodes)]);
% Determine network lifetime when a certain percentage of nodes die
deadNodes = sum(nodeEnergy <= 0);
if deadNodes >= 0.9 * numNodes
disp([‘90% nodes dead at Round ‘, num2str(round)]);
break;
end
Explanation of Key Components
- Cluster Head Selection: Nodes probabilistically turn out to be CHs, which balancing the energy burden by revolving this role between the nodes.
- Cluster Formation: Non-CH nodes connect the closest CH that reducing the distance for intra-cluster communication.
- Energy Consumption Model: Energy consumption based on the transmission type (to CH or BS) and distance. Multi-path and free-space models replicate the energy loss depends on distance.
- Data Transmission: Before sending to the base station, each CH combines data from their cluster members, which minimizing the total energy consumed on transmission.
- Network Lifetime and Energy Efficiency: The network’s operational lifetime is assessed by the amount of rounds until a critical number of nodes deplete its energy.
Possible Extensions
- Multi-hop Communication: Enable multi-hop routing to the base station once direct communication is very expensive.
- Dynamic Clustering: Adapt dynamically clustering probability (p) rely on energy levels to expand the network lifetime.
- Implement Other LEACH Variants: Attempt variant such as LEACH-C (centralized) in which a central controller allocates the CHs depends on energy and location.
We used MATLAB environment to perform detailed simulation process, which goal is to minimize energy consumption on Leach Routing Projects that were simulated and analysed. Should it be needed, we are ready to provide deeper insights and relevant information.