✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,代码获取、论文复现及科研仿真合作可私信。
个人主页:Matlab科研工作室
个人信条:格物致知。
更多Matlab完整代码及仿真定制内容点击
智能优化算法 神经网络预测 雷达通信 无线传感器 电力系统
信号处理 图像处理 路径规划 元胞自动机 无人机
LEACH 协议(Low-Energy Adaptive Clustering Hierarchy)是一种分层聚类路由协议,用于无线传感器网络。该协议将传感器节点组织成簇,每个簇由一个簇头负责收集数据并将其发送到基站。簇头通过轮换的方式产生,以避免某个节点成为永久的簇头而耗尽能量。
LEACH 协议的主要优点是能够有效地平衡能量消耗,延长网络寿命。此外,LEACH 协议还具有自适应性强、鲁棒性好等优点。
LEACH 协议的具体实现步骤如下:
簇头选举
每个节点随机生成一个介于 0 和 1 之间的数。如果该数小于等于阈值 T,则该节点成为簇头。阈值 T 的计算公式为:
T = P / (1 - P * (r mod 1/P))
其中,P 是期望的簇头比例,r 是当前轮次。
簇的形成
非簇头节点根据接收到的簇头广播信息,选择一个距离最近的簇头加入。
数据收集
簇头收集簇内节点的数据,并将其聚合在一起。
数据传输
簇头将聚合后的数据发送到基站。
簇的解散
在每轮结束时,簇头解散,并重新进行簇头选举。
LEACH 协议的性能主要体现在以下几个方面:
能量消耗:LEACH 协议能够有效地平衡能量消耗,延长网络寿命。
吞吐量:LEACH 协议的吞吐量随着网络规模的增大而减小。
时延:LEACH 协议的时延随着网络规模的增大而增大。
鲁棒性:LEACH 协议具有较强的鲁棒性,能够抵抗节点故障和信道干扰。
% LEACH PROTOCOL FOR WIRELESS SENSOR NETWORKS%
% IMPLEMENTED BY ZAIN EJAZ (Github ZainEjaz24)
Sum_DEAD(r+1)=deadNum; %dead nodes in each rounds
SRP(r+1)=srp; %SRP->number of sent routing packets in each round %%srp->number of sent routing packets in the current round.
RRP(r+1)=rrp; %receiving routing packets
SDP(r+1)=sdp; %sending data packets
RDP(r+1)=rdp; %received data packets
CLUSTERHS(r+1)=countCHs; %the number of cluster heads in each round
alive=0; %variable alive that initially 0
SensorEnergy=0; %variable SensorEnergy that initially 0
for i=1:n %loop to all nodes
if Sensors(i).E>0 %if energy is greater than 0
alive=alive+1; %then node will alive
SensorEnergy=SensorEnergy+Sensors(i).E; %adding energy
end
end
AliveSensors(r)=alive; % represents the number of alive nodes at the end of the current round.
SumEnergyAllSensor(r+1)=SensorEnergy; %stores the cumulative energy of all nodes
AvgEnergyAllSensor(r+1)=SensorEnergy/alive; %stores the average energy per node up to the current round (r+1).
ConsumEnergy(r+1)=(initEnergy-SumEnergyAllSensor(r+1))/n; %is an array that tracks the average energy consumption per node in each round.
En=0; % 'En' would represent the sum of squared deviations of the remaining energy of alive nodes from the average energy.
for i=1:n
if Sensors(i).E>0
En=En+(Sensors(i).E-AvgEnergyAllSensor(r+1))^2; %%node's remaining energy from the average energy.
end
end
%%calculates the energy heterogeneity
Enheraf(r+1)=En/alive; % indicates greater heterogeneity in the remaining energy distribution among the nodes.
title(sprintf('Round=%d,Dead nodes=%d', r+1, deadNum)) %set the title of the plot
%dead
if(n==deadNum) %all nodes are dead
lastPeriod=r; %round set to variable lastPeriod
break;
end
STATISTICS.Alive(r+1)=n-deadNum; %Records the number of alive nodes in the network
STATISTICS.Energy(r+1)=SumEnergyAllSensor(r+1); % Records the total energy of all sensors
x=r+1; %Sets the variable x to the current round number '(r+1)'
end % for r=0:1:rmax
r=1:x-1; %Creates a vector r representing the rounds from 1 to 'x-1'
figure(2) %graph of statistics between alive nodes and rounds
plot(r,STATISTICS.Alive(r+1)); %plotting graph
xlabel 'Rounds'; %x-axis
ylabel 'No of live sensor Nodes'; %y-axis
title('Life time of Sensor Nodes') %title
figure(3) %graph showing how increase in rounds will affect the energy of nodes
plot(r,STATISTICS.Energy(r+1)); %plotting graph
xlabel 'Rounds';%x-axis
ylabel 'Energy(in j)';%y-axis
title('Avergae Residual energy ');%title
disp('End of Simulation'); %The disp function is used to display the message "End of Simulation" in the command window.
toc;%toc is used to measure the elapsed time since the start of the timer created by tic
filename=sprintf('leach%d.mat',n) ; %The sprintf function is then used to create a filename based on the value of n (number of nodes) for saving the simulation results in a MAT file.
%% Save Report
save(filename);
LEACH 协议已被广泛应用于各种无线传感器网络应用中,例如环境监测、工业自动化和医疗保健等。
LEACH 协议是一种分层聚类路由协议,用于无线传感器网络。该协议能够有效地平衡能量消耗,延长网络寿命。此外,LEACH 协议还具有自适应性强、鲁棒性好等优点。LEACH 协议已被广泛应用于各种无线传感器网络应用中。
2.1 bp时序、回归预测和分类
2.2 ENS声神经网络时序、回归预测和分类
2.3 SVM/CNN-SVM/LSSVM/RVM支持向量机系列时序、回归预测和分类
2.4 CNN/TCN卷积神经网络系列时序、回归预测和分类
2.7 ELMAN递归神经网络时序、回归\预测和分类
2.9 RBF径向基神经网络时序、回归预测和分类