⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventmodel.m

📁 run these simulations of wireless sensor networks written in matab.event model,event simulations.
💻 M
字号:
%%%%% Modeling of a 2-D event driven network%%%%%

clear all;
close all;
                                
R = 250;  %side of the square region.
N = 1000;   %number of sensors deployed in the region.   

X_max = R/2;
Y_max = R/2;

r_sense = 10;
r_radio = 2*r_sense;

X_sink = 0;
Y_sink = 0;

count = 0;
node_data = zeros(3,N);
coverage = zeros(R+1,R+1);
coverage_fraction = 0;


for z = 1:5
    
    coverage_count = 0;
    for n = 1:N
    
        x = ceil(R*rand(1,1)-(R/2));
        y = ceil(R*rand(1,1)-(R/2));
    
        if (x < -X_max | x > X_max | y < -Y_max | y > Y_max | (x == 0 & y == 0))
        
            n = n-1;
    
        else
        
            node_data(1,n) = x;
            node_data(2,n) = y;
    
        end
    end

% hold on
% 
% for n = 1:N
%     
%     plot(node_data(1,n),node_data(2,n),'.');
% end
% 
% plot(X_sink,Y_sink,'r*');
% 
% hold off



%%%%%%    checking connectivity of the sensor network    %%%%%%%%%%%%%%%

    for i = 1:N
    
        for j = 1:N
        
            if (j ~= i)
            
                if (((node_data(1,i)- node_data(1,j))^2 + (node_data(2,i)- node_data(2,j))^2)^0.5 <= r_radio)
                
                    node_data(3,i) = 1;
                
                    break;
                end
            end
        end
    end

    

    for n = 1:N
    
        if (node_data(3,n) == 1)
        
        count = count + 1;
        end
    end

    
%%%%%%%%%      Evaluating Coverage of Sensor network  %%%%%%%%%

    for i = -X_max : 1 : X_max
    
        for j = -Y_max : 1 : Y_max
        
            for k = 1 : N
            
                if (((i - node_data(1,k))^2 + (j - node_data(2,k))^2)^0.5 <= r_sense)
                
                    coverage(i+(R/2)+1,j+(R/2)+1) = 1;
                    break;
                end
            end
        end
    end

    for i = -X_max : 1 : X_max
    
        for j = -Y_max : 1 : Y_max
            
            if(coverage(i+(R/2)+1,j+(R/2)+1) == 1)
                
                coverage_count = coverage_count + 1;
            end
        end
    end
    
    coverage_fraction = coverage_fraction + coverage_count/((R+1)^2);

    
end

count = (count/(5*N))*100 ;
coverage_fraction = (coverage_fraction)/5;


% temp = size(count);
% 
% hold on
% 
% for k = 1:temp(1,2)
%     
%     plot(count(1,k),count(2,k),'*');
% end
% 
% hold off

























⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -