?? strengthtime.m
字號:
function Strength = StrengthTime(num)
% This function ->
% Strength: takes input argument num to which ErrorTime.m,
% PacketLoss.m, Stats.m, Markov.m and Autocorrelation.m are run
% If only a single function is wanted, then comment out the
% corresonding function call.
% The output of this program will be:
% - Total number of `1's and 0's
% - Loss rate
% - Markov transitional probabilities
% - Equilibrium probabilities
% - eStats for RSSI:Standard_Deviation, Mean and Range
% - Autocorrelation and written auto'i'
% - Graphs include:- Time variance of Error rate
% - Packet Birst Size
% - Time Variance of SIgnal Strength
% NOTE:
% - If experiment 4 is not found within the input file, the program
% will output an error
% - Groups of 10 packets are employed and graphed because plotting
% individual RSSI values against time produced a graph was too compressed
% for visualisation.
% - The MATLAB program Extract.m has to within the working directory.
i = 1;
skip = 20;
Subtotal = 0;
SubtotalTime = 0;
group = 1;
room_back = 0;
mp_back = 0;
counter = 1;
found = 0;
error = 0;
line = 0;
times= 0;
format long g
lag = 15; %for autocorrelation (Note: lag of 15 = 30 seconds)
for (i=num:num)
file = i;
filename = sprintf('strength%d',file);
fid = fopen(filename,'r');
if (fid == -1)
disp(['ERROR: File not found or could not be opened to read. Please check your input strength file name']);
end
GROUPSIZE = 10;
% Finds exp 5
while(found < skip)
tline = fgets(fid);
line = line + 1; % how many lines scanned
room = Extract(tline, 1); % extract room
mp = Extract(tline, 2); % extract room
if (strcmp(tline,'EMPTY'))
error = error + 1;
break;
end
for (i=1:length(room))
if (room == room_back) && (mp == mp_back)
found = found + 1;
break;
else
found = 0;
end
end
room_back = room;
mp_back = mp;
end
% Need to rewind the 19 lines missed
frewind(fid)
i = 1;
line = line - (skip - 1); %skip over the first line
while(i < line)
tline = fgets(fid);
i = i + 1;
end
% if no error flagged then run ErrorTime and PacketLoss programs
if (error ~= 1)
filename = sprintf('packets%d',file);
ErrorTime(filename);
PacketLoss(filename);
MArkov(filename)
end
i = 1; % reset array index
while(~feof(fid))
if (error == 1)
break;
end
tline = fgets(fid);
g = sscanf(tline, '%f');
tline = tline(13:length(tline));
time(i) = (g - times);
RSSI(i) = Extract(tline, 7);
times = g;
Subtotal = (Subtotal + (RSSI(i)-256));
SubtotalTime = SubtotalTime + time(i);
if (rem(i,GROUPSIZE)==0)
Strength(group) = (Subtotal/GROUPSIZE);
Time(group) = (SubtotalTime);
SubtotalTime = 0;
Subtotal = 0;
group = group + 1;
end
i = i + 1;
end
fclose(fid);
if (error ~= 1)
Stats(Strength, RSSI, GROUPSIZE, Time)
end
%calculate autocorrelatioan and write to file
Autocorrelation(file, RSSI, lag)
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -