首页 > 行业资讯 > 【WSN定位】基于非测距的定位算法Dv-Hop算法实现二维和三维节点定位附matlab代码

【WSN定位】基于非测距的定位算法Dv-Hop算法实现二维和三维节点定位附matlab代码

时间:2022-06-02 来源: 浏览:

【WSN定位】基于非测距的定位算法Dv-Hop算法实现二维和三维节点定位附matlab代码

天天Matlab 天天Matlab
天天Matlab

TT_Matlab

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,完整matlab代码或者程序定制加qq1575304183。

收录于合集 #雷达通信matlab源码 56个

1 简介

2 部分代码

% BorderLength-----正方形区域的边长,单位:m % NodeAmount------网络节点的总个数 % BeaconAmount---信标节点数 % UNAmount--------未知节点数 % Sxy-----------------用于存储节点的序号,横坐标,纵坐标的矩阵 % Beacon------------信标节点坐标矩阵 % UN-----------------未知节点坐标矩阵 % Distance-----------未知节点到信标节点距离矩阵 % X------------------未知节点估计坐标初始矩阵 % R------------------节点的通信距离,一般为 10 - 100 m clear,close all; BorderLength= 100 ;%正方形区域的边长 NodeAmount= 100 ;%网络节点的总个数 BeaconAmount= 10 ; UNAmount=NodeAmount-BeaconAmount; R= 50 ; Dall=zeros(NodeAmount,NodeAmount,NodeAmount); %距离初始矩阵 h=zeros(NodeAmount,NodeAmount,NodeAmount); %初始跳数矩阵 X=zeros( 2 ,UNAmount,NodeAmount); %未知节点估计坐标初始矩阵 %~~~~~~~~~在正方形区域内产生均匀分布的随机拓扑~~~~~~~~~~~~~~~ site=BorderLength.*rand( 2 ,NodeAmount); %随机产生节点坐标 Sxy=[ 1 :NodeAmount ;site]; %带序号的节点坐标 Beacon=[Sxy( 2 , 1 :BeaconAmount );Sxy( 3 , 1 :BeaconAmount )]; %信标节点坐标 UN=[Sxy( 2 ,(BeaconAmount+ 1 ) :NodeAmount );Sxy( 3 ,(BeaconAmount+ 1 ) :NodeAmount )]; %未知节点坐标 %~~~~~~~~画出节点分布图~~~~~~~~~~~~~~~~~ figure( 1 ) plot(Sxy( 2 , 1 :BeaconAmount ),Sxy( 3 , 1 :BeaconAmount ), ’r*’ ,Sxy( 2 ,(BeaconAmount+ 1 ) :NodeAmount ),Sxy( 3 ,(BeaconAmount+ 1 ) :NodeAmount ), ’k.’ ) xlim([ 0 ,BorderLength]); ylim([ 0 ,BorderLength]); title( ’红色*表示信标节点 黑色.表示未知节点’ ) end A= 2 *(a ’); %’ 表示求矩阵的转置 B=zeros(BeaconAmount- 1 , 1 ); for m= 1 :UNAmount for i= 1 : (BeaconAmount- 1 ) B(i, 1 )=d(BeaconAmount,m)^ 2 -d(i,m)^ 2 +Beacon( 1 ,i)^ 2 -Beacon( 1 ,BeaconAmount)^ 2 +Beacon( 2 ,i)^ 2 -Beacon( 2 ,BeaconAmount)^ 2 ; %B=b矩阵 end X1=inv(A ’*A)*A’ *B; %inv表示求矩阵的逆矩阵 X( 1 ,m)=X1( 1 , 1 ); X( 2 ,m)=X1( 2 , 1 ); %将求得的未知节点的坐标依次存入X矩阵 end error=zeros( 1 ,UNAmount); %未知节点的定位误差 for i= 1 :UNAmount error(i)=(((X( 1 ,i)-UN( 1 ,i))^ 2 +(X( 2 ,i)-UN( 2 ,i))^ 2 )^ 0 . 5 ); %每个未知节点的定位误差 end figure( 2 ) stem(error) xlabel( ’未知节点序号’ ) title( ’每个未知节点的误差’ ) Berror=sum(error)/UNAmount %平均定位误差 Accuracy= Berror /R %定位精确度

3 仿真结果

4 参考文献

[1]张佳, 吴延海, 石峰,等. 基于DV-HOP的无线传感器网络定位算法[J]. 计算机应用, 2010(2):4.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

5 代码下载

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐