✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
无线传感网(Wireless Sensor Network,WSN)是信息技术革命的重要组成部分,被广泛的应用于军事,医疗护理,环境监测,目标跟踪等领域,是一种重要的信息采集手段。在实际应用中,无线传感网节点的位置信息是其提供各种应用服务的基础,虽然GPS(Global Positioning System)是当前应用最广泛、技术最成熟的全球定位系统,但是由于无线传感网具有节点数量大,体积小,传感节点能量有限的特点;使得高能耗,体积较大,成本较高的GPS定位装置在应用于大规模的WSN时受到限制。对于大规模的无线传感器网络,目前主要的节点定位算法主要分为两类;一类是基于测距的定位算法,即首先通过RSSI(Rdio Signal Strength Indicator),TDOA(Time Difference of Arrival)等各种测距技术测得未知节点到已知节点的距离,列出方程组,再通过最大似然估计法、三边测量法等求解此非线性方程组,最终完成对未知节点的定位;另一种是基于非测距的定位算法,主要是在无线传感网上部署特殊的通信协议,通过网络的连通性来估计节点间的距离,从而完成定位过程,比较典型的算法主要有DV-HOP(Distance vector-hop),质心算法等。粒子群优化算法是一种新兴的群体智能优化算法,主要用于求解非线性优化问题,具有搜索速度快,实现简单的特点,被广泛的应用于路径规划,经济预测等领域.
⛄ 部分代码
close all
clear
clc
addpath(genpath(cd))
warning('off')
%%
N=10; % number of nodes
area=[10,10]; % nodes deployment area in meter
Trange=2; % transmission range of sensor node in meter
nodes.pos=area(1).*rand(N,2);% nodes geographical locations
lambda=0.125; % signal wavelength in meter
nodes.major = Trange; % major axis for ellpitical range in meter
nodes.minor = lambda*Trange; % minro axis for ellipitical range in meter
% redundantNo=9; % number of healing nodes
redundantNo=round(10*N/100);
%% plot the nodes deployment
cnt=1;
for ii=1:N
for jj=1:N
if ii~=jj
nodes.distance(ii,jj)=pdist([nodes.pos(ii,:);nodes.pos(jj,:)]);
if nodes.distance(ii,jj)<Trange || nodes.distance(ii,jj)==Trange
nodes.inrange(ii,jj)=1;
else
nodes.inrange(ii,jj)=0;
end
end
end
end
figure
F5=plot(nodes.pos(:,1),nodes.pos(:,2),'.','color','r');
hold on
for ii=1:N % plot the circular transmission range
[nodes.circle.x(ii,:),nodes.circle.y(ii,:)]=circle(nodes.pos(ii,1),nodes.pos(ii,2),Trange);
F6=fill(nodes.circle.x(ii,:),nodes.circle.y(ii,:),[0.25,0.25,0.25]);
alpha 0.3
hold on
end
axis on
xlabel('x(m)')
ylabel('y(m)')
title('Initial Placement of Nodes with circular transmission range')
%% plot delauny triangle
TRI = delaunay(nodes.pos(:,1),nodes.pos(:,2));
figure(2)
F5 = plot(nodes.pos(:,1),nodes.pos(:,2),'.','color','r');
hold on
for ii=1:N % plot the circular transmission range
[nodes.circle.x(ii,:),nodes.circle.y(ii,:)]=circle(nodes.pos(ii,1),nodes.pos(ii,2),Trange);
F6=fill(nodes.circle.x(ii,:),nodes.circle.y(ii,:),[0.25,0.25,0.25]);
alpha 0.3
hold on
end
axis on
xlabel('x(m)')
ylabel('y(m)')
title('Coverage hole in initila position of Nodes')
hold on
triplot(TRI,nodes.pos(:,1),nodes.pos(:,2))
%% Hole detection
[holeDetected.circle,Circmcenter.circle,circumradius.circle]=holeDetection(TRI,nodes,F5,F6,Trange,area,2,1);
display(['--> No of detected Holes for Circular = ',num2str(numel(find(holeDetected.circle)))])
%% PSO optimize position of rest wsn nodes to cover the hole
nvars = 2*(N);
fun=@(x)objf(x,Trange,area);
lb=zeros(nvars,1);
ub=area(1).*ones(nvars,1);
options = optimoptions(@particleswarm,'Display','iter','MaxIterations',100,'PlotFcn','pswplotbestf');
[x,fval] = particleswarm(fun,nvars,lb,ub,options);
finalPos = reshape(x,[numel(x)/2,2]);
% plot the final tuned Node' pos
figure
plot(finalPos(:,1),finalPos(:,2),'o','color','r');
hold on
for ii=1:N % plot the circular transmission range
[finalcircle.x(ii,:),finalcircle.y(ii,:)]=circle(finalPos(ii,1),finalPos(ii,2),Trange);
fill(finalcircle.x(ii,:),finalcircle.y(ii,:),[0.25,0.25,0.25]);
alpha 0.3
hold on
end
axis on
xlabel('x(m)')
ylabel('y(m)')
title('Optimized location of Nodes with circular transmission range')
⛄ 运行结果
⛄ 参考文献
[1]刘伟. 基于改进粒子群优化算法的WSN节点定位的研究[D]. 南京邮电大学.