📄 packetloss.m
字号:
function [Loss, Bursts] = PacketLoss(file_header)
% This function ->
% PacketLoss: Given the packets file this program finds the
% experiment 4 data and proceeds and collects the burst sizes of
% packets. This is then graphed, that is, the packet error burst
% frequency is calculated and graphed. The loss rates is also
% calculated and outputted to the screen.
% Note: If the graph of the bursts of received packet is wanted, change the
% comparison on line 58 to a '0'
filename = [file_header];
fid = fopen(filename,'r');
tline = fgets(fid);
z = 0; %lost packet
o = 0; %received packet
current = 1; %flag for a loss packet
count = 0; %typical counter
room_back = 0;
mp_back = 0;
loop_cnt = 1;
line_counter = 0;
% The Bur vector populates the index of the vector when a Bur of that
% index has been found
Bur = zeros(50000,1);
while(1)
tline = fgets(fid);
room = sscanf(tline,'%f'); % extract room number
mp = Extract(tline, 1); % extract MP
if((room == room_back) && (mp == mp_back))
break;
end
room_back = room;
mp_back = mp;
line_counter = line_counter + 1;
end
%dont miss any lines
frewind(fid)
i = 1;
while(i <= line_counter)
tline = fgets(fid);
i = i + 1;
end
while(~feof(fid))
tline = tline(9:length(tline));
for (i=1:length(tline))
if (tline(i)=='1') %1 = loss, 0 = received
o = o + 1;
if (current == 0) %Burst found
Bur(count) = Bur(count) + 1; % increment relevent Bur size
cnt(loop_cnt) = loop_cnt; %index vector for plotting
count = 0;
current = 1;
end
else
z = z + 1;
if (current == 0)
count = count + 1;
else
current = 0;
count = 1;
loop_cnt = loop_cnt + 1;
end
end
end
tline = fgets(fid);
end
Total = z+o
Loss_is = ((z/Total)*100)
fclose(fid);
% Alters the x axis of the graph to a log scale for better viewing.
for i=1:length(Bur)
if Bur(i) == 0
Bur(i) = 0;
else
Bur(i) = log(Bur(i));
end
end
figure; bar(Bur, 0.8, 'r'); axis([1 90 0 9]); title('Packet Error Burst Frequency'); xlabel('Burst Size'); ylabel('Log(Freq)');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -