Too simulate the Power-Efficient GAthering in Sensor Information System (PEGASIS) protocol in MATLAB has includes numerous steps and the PEGASIS is a chain-based routing protocol for wireless sensor networks (WSNs) which main goal is to reduce the energy consumption of nodes by establishing chains and revolving the leader node for data collection and transmission.
Hereβs a detailed procedure on how to simulate PEGASIS in MATLAB:
Steps to Simulate PEGASIS Protocol:
- Network Initialization:
- Describe the sensor network area, the amount of nodes (sensors), and their random setting out inside a certain area.
- Each node is specified a coordinate (x, y) and an initial energy level.
Example:
% Parameters
num_nodes = 50; % Number of sensor nodes
area_size = 100; % Area of the sensor field (100×100 units)
initial_energy = 1; % Initial energy of each node
% Random deployment of sensor nodes
nodes = area_size * rand(num_nodes, 2); % Random (x, y) coordinates
% Energy initialization for each node
energy = initial_energy * ones(1, num_nodes);
- Chain Formation (PEGASIS Concept):
- PEGASIS makes a chain in which each node interacts only with its nearest neighbour. The chain is built by initiating from a random node and associating it to its closest neighbor until all nodes are encompassed.
- Utilize a greedy approach to makes the chain by iteratively associating nodes to their closest unvisited neighbour.
Example:
% Chain formation (PEGASIS chain)
chain = zeros(1, num_nodes); % To store the chain sequence
visited = false(1, num_nodes); % To track visited nodes
% Start with a random node
current_node = randi(num_nodes);
chain(1) = current_node;
visited(current_node) = true;
for i = 2:num_nodes
% Find the nearest unvisited neighbor
min_distance = inf;
next_node = -1;
for j = 1:num_nodes
if ~visited(j)
distance = sqrt(sum((nodes(current_node, π – nodes(j, :)).^2));
if distance < min_distance
min_distance = distance;
next_node = j;
end
end
end
% Update the chain and mark the node as visited
chain(i) = next_node;
visited(next_node) = true;
current_node = next_node;
end
- Leader Selection:
- In PEGASIS, the leader node is liable for gathering the data from other nodes and routing it to the base station (sink). The leader role is exchanged between the nodes to balance energy consumption.
- At each round, a diverse node can be selected as the leader.
Example:
% Select a random leader for this round
leader_node = randi(num_nodes);
- Data Transmission:
- Replicate the data transmission beside the chain, in which each node sends its data to its neighbour. The leader node gathers the data and transmits it to the base station.
- The energy consumed in the course of transmission and reception can be designed by using a simple energy consumption model.
Example energy consumption model:
% Energy consumption parameters
E_tx = 50e-9; % Energy to transmit per bit (in joules)
E_rx = 50e-9; % Energy to receive per bit (in joules)
packet_size = 4000; % Packet size in bits
% Distance between nodes
for i = 1:num_nodes-1
distance = sqrt(sum((nodes(chain(i), π – nodes(chain(i+1), :)).^2));
% Transmit energy
energy(chain(i)) = energy(chain(i)) – E_tx * packet_size * distance;
% Receive energy
energy(chain(i+1)) = energy(chain(i+1)) – E_rx * packet_size;
end
% Leader sends data to the base station
base_station = [50, 50]; % Coordinates of the base station
distance_to_base = sqrt(sum((nodes(leader_node, π – base_station).^2));
energy(leader_node) = energy(leader_node) – E_tx * packet_size * distance_to_base;
- Base Station and Energy Dissipation:
- The leader node transmits the gathered data to the base station (sink), and energy dissipation for long-distance transmission is estimated.
- Simulation Rounds:
- Replicate the process for multiple rounds, in which the each round a novel leader is chosen, and the data transmission is reiterated until the network reduces the energy of most nodes.
Example simulation loop:
rounds = 100;
for round = 1:rounds
% Select a new leader for this round
leader_node = randi(num_nodes);
% Simulate data transmission and energy dissipation for this round
for i = 1:num_nodes-1
distance = sqrt(sum((nodes(chain(i), π – nodes(chain(i+1), :)).^2));
energy(chain(i)) = energy(chain(i)) – E_tx * packet_size * distance;
energy(chain(i+1)) = energy(chain(i+1)) – E_rx * packet_size;
end
distance_to_base = sqrt(sum((nodes(leader_node, π – base_station).^2));
energy(leader_node) = energy(leader_node) – E_tx * packet_size * distance_to_base;
% Check if any node runs out of energy
if any(energy <= 0)
fprintf(‘Node %d has run out of energy after %d rounds.\n’, find(energy <= 0, 1), round);
break;
end
end
- Results and Analysis:
- Evaluate the parameters like the amount of rounds earlier network failure, energy consumption over time, and the load distribution between nodes.
Plot the energy levels of nodes over time to track the network characteristics:
plot(1:num_nodes, energy);
xlabel(‘Node ID’);
ylabel(‘Remaining Energy (J)’);
title(‘Energy Levels of Nodes After Simulation’);
Additional Considerations:
- Energy Model: we can improve the energy model by containing both transmission and receiving costs according to distance such as free space or multipath fading model.
- Leader Rotation: To sense of balance energy consumption, making sure that the leader rotates occasionally in diverse simulation rounds.
- Enhancements: we could advance extension this by incorporating noise, node failures, or mobility to forms the replication more realistic.
With the help of this procedure you can obtain the knowledge and can be able to simulate the Power-Efficient GAthering in Sensor Information System project in MATLAB tool. If you are encountering difficulties in finalizing your PEGASIS Protocol Project simulation, the team at phdprime.com is available to assist you in attaining optimal results. Please share your project details with us via email, and we will provide you with the necessary guidance to ensure successful outcomes. Our specialists possess extensive expertise in chain-based routing protocols for wireless sensor networks (WSNs) using MATLAB.