一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【RWM】基于matlab路由无线传感器网络模拟随机路点运动模型【含Matlab源码 1565期】
获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
clc;
clear all;
close all;
global EexL X Y Xb Yb N nodesCH alpha beta A SN
pause(4)
rng default;
stop1=0;
RoutingId=3;
%3 --- Modified Dijikstra
N=80; % No. of nodes
t1='800x800';
t2=strsplit(t1,'x');
min1=0;
max1=str2double(t2(2));
X = min1+(max1-min1)*rand(1,N);
Y = min1+(max1-min1)*rand(1,N);
%%
figure,
plot(X,Y,'o','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',7');
xlabel('X in m')
ylabel('Y in m')
for i2 = 1:N
text(X(i2), Y(i2), num2str(i2),'FontSize',10);
hold on;
end
hold on
xlabel('x');
ylabel('y');
%% RWM model
% velocity distribution min and max (0,2)
minVel=-4;
maxVel=4;
% PauseTime (0,1)
minPause=0;
maxPause=1;
simTime=350;% Round750
Rc=150; % coverage Area
%Rc=280; %sensor field Radius
% position of source node
tb='0x0';
t2=strsplit(tb,'x');
Xs =str2double(t2(1));
Ys =str2double(t2(2));
hold on
plot(Xs,Ys,'s','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',12');
xlabel('X in m')
ylabel('Y in m')
text(Xs, Ys, 'Source','FontSize',10);
hold on;
% position of sink node
%t1='410x410';
t2=strsplit(t1,'x');
Xb =str2double(t2(1));
Yb =str2double(t2(2));
hold on
plot(Xb,Yb,'s','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','y',...
'MarkerSize',12');
xlabel('X in m')
ylabel('Y in m')
text(Xb, Yb, 'Base','FontSize',10);
hold on;
%%
alpha=0.01;%0.001 energy per distance% 0.001 %% node to CH power Ratio
beta=0.045;%0.0015 %% CH to sink distance power ratio
Sector1=1;
nodes=N;% Total No. of Nodes
%% Energy
mi1=0; mi2=25; mi3=50;
ma1=50;ma2=75; ma3=100;
Ep =4*1e3; % 4000 mW
E1=Ep.*(mi1+(ma1-mi1).*rand(1,round(nodes/3)))./100
E2=Ep.*(mi2+(ma2-mi2).*rand(1,round(nodes/3)))./100
E3=Ep.*(mi3+(ma3-mi3).*rand(1,nodes-2*round(nodes/3)))./100
E=[E1 E2 E3]
%E=4.*ones(1,nodes); % intial Energy 4W
PackSize=2; % 2Mb/sec
nodesCH=10;% no of cluster head
EexL=E;
E1=E;
%% Ch selection
chalg1='chselalg.m'
chalg=strrep(chalg1,'.m','');
varName=matlab.lang.makeValidName(chalg);
chselalg=str2func(varName)
%% Routing
Route_type = 'custom';
%% EnergyFunction
Efun1='Energyfun.m'
Efun=strrep(Efun1,'.m','');
varName=matlab.lang.makeValidName(Efun);
Efun=str2func(varName)
A=3;
if(strcmp(Route_type,'custom'))
Ralg1='DjisktraRoute.m';
Ralg=strrep(Ralg1,'.m','');
varName=matlab.lang.makeValidName(Ralg);
Ralgfun=str2func(varName)
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.