Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matlab functions for node mobility
#1

matlab functions for node mobility

function simulation_example(animation)
% an example of simulation with STEPS mobility model
% author: Anh-Dung Nguyen
% email: [email protected]

simu.duration = 200; % number of time steps
simu.number_of_nodes = [500 500];
simu.alpha = [0 100];
simu.grid_size = 20;
simu.zone_size = 10;
simu.time_step = 5; % seconds
simu.rwp_speed = [3 5] / 3.6;
simu.rwp_pause_time = [1 5];
simu.zone_speed = [3 10] / 3.6;
simu.zone_time = [20 30];
simu.radio_range = 10;

disp('--STARTING SIMULATIONS--')

if animation == 1
steps_fig = figure;
s = get(0,'ScreenSize');
set(steps_fig,'OuterPosition',[s(3)*1.8/4 s(4)/5 500 500],'NextPlot','add');
steps_plot1 = plot(0);
steps_axes = get(steps_fig,'CurrentAxes');
set(steps_axes,'XLimMode','manual','XLim',[0 simu.grid_size*simu.zone_size],'YLimMode','manual','YLim',[0 simu.grid_size*simu.zone_size],'XTick',0 : simu.zone_size : simu.grid_size*simu.zone_size,'YTick',0 : simu.zone_size : simu.grid_size*simu.zone_size,'XGrid','on','YGrid','on','NextPlot','add');
steps_plot2 = plot(0);
steps_plot3 = plot(0);
set(steps_plot1,'LineStyle','none','Marker','o','MarkerSize',7,'MarkerFaceColor','b');
set(steps_plot2,'LineStyle','none','Marker','.','MarkerEdgeColor','g','MarkerSize',1);
set(steps_plot3,'LineStyle','none','Marker','.','MarkerEdgeColor','r','MarkerSize',4.7);
end

% creation of nodes
nodes = Group(simu.alpha,simu.number_of_nodes,simu.grid_size,simu.rwp_speed,simu.rwp_pause_time,simu.zone_speed,simu.zone_time,simu.zone_size,simu.time_step,simu.radio_range);

for ii = 1Confusedimu.duration
% movement of nodes
nodes.move;

% connections between nodes
C = nodes.connect;

if animation == 1
C(eye(size©)==1) = 0;
[v1 v2] = find(C==1);
links = [v1 v2];
set(steps_plot1,'YData',nodes.coords(:,2),'XData',nodes.coords(:,1))
[xc,yc] = circle(nodes.coords(:,1),nodes.coords(:,2),simu.radio_range);
set(steps_plot2,'XData',xc,'YData',yc)
if isempty(links)
n = unique(sort(links,2),'rows');
[xl,yl] = line_plot(nodes.coords(n(:,1),Smile,nodes.coords(n(:,2),Smile);
set(steps_plot3,'XData',xl,'YData',yl);
end
drawnow
end
end

disp('--SIMU DONE--')
end

function [x,y] = circle(a,b,r)
t = (0:0.01:2*pi)';
cosinus = r*cos(t);
sinus = r*sin(t);
n = length(t);
m = length(a);
x = repmat(a,n,1) + repmat(cosinus,m,1);
y = repmat(b,n,1) + repmat(sinus,m,1);
end

function [x,y] = line_plot(a,b)
t = (0:0.01:1)';
n = length(t);
m = size(a,1);
x = repmat(a(:,1),n,1) + repmat(t,m,1).*repmat(b(:,1)-a(:,1),n,1);
y = repmat(a(:,2),n,1) + repmat(t,m,1).*repmat(b(:,2)-a(:,2),n,1);
Reply

#2
i need the matlab code for sink mobility iam using a"REAR" techique for hetergeneous wireless sensor network
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.