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

📄 classify_packets.m

📁 一个UWB仿真程序包
💻 M
📖 第 1 页 / 共 2 页
字号:
           chest_done = chest_done_before(end);
           
           %overlaps during sync phase
           
           %if interference present during sync, check percentage of sync
           %that saw interference from data, preamble
           
           stop = sync_ok;
           %check for interfering preambles first
           start = sync_start - pre_len;
           temp = if_pkts_start;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_pre_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
                   max(sync_start,if_pre_start_times(k));
               uoi_pkts(pkt_num,15) = uoi_pkts(pkt_num,15) + overlap_samples/(stop-sync_start+1);
           end

           %now the same for interfering data parts
           start = sync_start - packet_len;
           temp = if_pkts_start+pre_len;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_data_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
                   max(sync_start,if_data_start_times(k));
               uoi_pkts(pkt_num,16) = uoi_pkts(pkt_num,16) + overlap_samples/(stop-sync_start+1);
           end

           %overlaps during chest phase
           %if interference present during sync, check percentage of sync
           %that saw interference from data, preamble

           stop = chest_done;
           %check for interfering preambles first
           start = sync_ok + 1 - pre_len;
           temp = if_pkts_start;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_pre_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
                   max(sync_ok + 1,if_pre_start_times(k));
               uoi_pkts(pkt_num,17) = uoi_pkts(pkt_num,17) + overlap_samples/(stop-sync_ok);
           end

           %now the same for interfering data parts
           start = sync_ok + 1 - packet_len;
           temp = if_pkts_start+pre_len;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_data_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
                   max(sync_ok+1,if_data_start_times(k));
               uoi_pkts(pkt_num,18) = uoi_pkts(pkt_num,18) + overlap_samples/(stop-sync_ok);
           end
           %overlaps during sfd search phase
           %if interference present during sync, check percentage of sync
           %that saw interference from data, preamble

           stop = sfd_fa(j);
           %check for interfering preambles first
           start = chest_done + 1 - pre_len;
           temp = if_pkts_start;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_pre_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
                   max(chest_done+1,if_pre_start_times(k));
               uoi_pkts(pkt_num,19) = uoi_pkts(pkt_num,19) + overlap_samples/(stop-chest_done);
           end

           %now the same for interfering data parts
           start = chest_done + 1 - packet_len;
           temp = if_pkts_start+pre_len;
           temp(temp>stop)=0;
           temp(temp<start)=0;
           if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
           for k=1:length(if_data_start_times)
               %calculate the percentage of our packet affected
               overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
                   max(chest_done+1,if_data_start_times(k));
               uoi_pkts(pkt_num,20) = uoi_pkts(pkt_num,20) + overlap_samples/(stop-chest_done);
           end

          

           diff_sync = sync_ok-sync_start;
           diff_sfd = sfd_fa(j)-sync_ok;
           uoi_pkts(pkt_num,21) = diff_sync;
           uoi_pkts(pkt_num,22) = diff_sfd;
        end
    end
    
    %now from the last 3 fields, make an overall decision
    SYNC_MISSED = 1; %we missed the SYNC
    SFD_MISSED = 2; %we missed the SFD
    SYNC_IF = 3; %we synchronized with an interferer
    
    if(~sum(uoi_pkts(pkt_num,7:9)))
        uoi_pkts(pkt_num,10) = SYNC_MISSED;
    elseif(uoi_pkts(pkt_num,9))
        uoi_pkts(pkt_num,10) = SYNC_IF;
    elseif(uoi_pkts(pkt_num,7) && ~uoi_pkts(pkt_num,8))
        uoi_pkts(pkt_num,10) = SFD_MISSED;
    else
        uoi_pkts(pkt_num,10) = -1; %aka one we have not thought of
    end


end %end packets missed

%for the packets found, what kind of if did they see in all the phases?
%and what was the length of the channel mask -> result in mask_len
pkts_found_idx = find(uoi_pkts(:,6));
for i=1:length(pkts_found_idx)
    pkt_num = pkts_found_idx(i);
    
    %find the correpsonnding sfd ok (closest one)
    [diff2closest, closest_idx] = min(abs(times_sfd_ok - uoi_pkts_data_start(pkt_num)));
    sfd_ok = times_sfd_ok(closest_idx);
    
    %get the corresponding sync ok
    sync_ok_before = times_sync_ok(times_sync_ok<sfd_ok);
    sync_ok = sync_ok_before(end);
    %get the corresponding sync start
    sync_start_before = times_sync_start(times_sync_start<sync_ok);
    sync_start = sync_start_before(end);
    %get the corresponding chest done
    chest_done_before = times_chest_done(times_chest_done<sfd_ok);
    chest_done = chest_done_before(end);

    %get the corresponding mask length
    if(~isempty(mask_len)) %is possibly because not all sims printed masklen
      mask_idx = find(mask_len(:,1)==chest_done);
      uoi_pkts(pkt_num,23)=mask_len(mask_idx,2);
    else
      uoi_pkts(pkt_num,23)=-1;
    end
    %overlaps during sync phase

    %if interference present during sync, check percentage of sync
    %that saw interference from data, preamble

    stop = sync_ok;
    %check for interfering preambles first
    start = sync_start - pre_len;
    temp = if_pkts_start;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_pre_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
            max(sync_start,if_pre_start_times(k));
        uoi_pkts(pkt_num,15) = uoi_pkts(pkt_num,15) + overlap_samples/(stop-sync_start+1);
    end

    %now the same for interfering data parts
    start = sync_start - packet_len;
    temp = if_pkts_start+pre_len;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_data_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
            max(sync_start,if_data_start_times(k));
        uoi_pkts(pkt_num,16) = uoi_pkts(pkt_num,16) + overlap_samples/(stop-sync_start+1);
    end

    %overlaps during chest phase
    %if interference present during sync, check percentage of sync
    %that saw interference from data, preamble

    stop = chest_done;
    %check for interfering preambles first
    start = sync_ok + 1 - pre_len;
    temp = if_pkts_start;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_pre_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
            max(sync_ok + 1,if_pre_start_times(k));
        uoi_pkts(pkt_num,17) = uoi_pkts(pkt_num,17) + overlap_samples/(stop-sync_ok);
    end

    %now the same for interfering data parts
    start = sync_ok + 1 - packet_len;
    temp = if_pkts_start+pre_len;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_data_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
            max(sync_ok+1,if_data_start_times(k));
        uoi_pkts(pkt_num,18) = uoi_pkts(pkt_num,18) + overlap_samples/(stop-sync_ok);
    end
    %overlaps during sfd search phase
    %if interference present during sync, check percentage of sync
    %that saw interference from data, preamble

    stop = sfd_ok;
    %check for interfering preambles first
    start = chest_done + 1 - pre_len;
    temp = if_pkts_start;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_pre_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_pre_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_pre_start_times(k)+pre_len)- ...
            max(chest_done+1,if_pre_start_times(k));
        uoi_pkts(pkt_num,19) = uoi_pkts(pkt_num,19) + overlap_samples/(stop-chest_done);
    end

    %now the same for interfering data parts
    start = chest_done + 1 - packet_len;
    temp = if_pkts_start+pre_len;
    temp(temp>stop)=0;
    temp(temp<start)=0;
    if_data_start_times = nonzeros(temp); %the starting times of interfering preamble
    for k=1:length(if_data_start_times)
        %calculate the percentage of our packet affected
        overlap_samples = min(stop,if_data_start_times(k)+packet_len)- ...
            max(chest_done+1,if_data_start_times(k));
        uoi_pkts(pkt_num,20) = uoi_pkts(pkt_num,20) + overlap_samples/(stop-chest_done);
    end

    diff_sync = sync_ok-sync_start;
    diff_sfd = sfd_ok-sync_ok;
    uoi_pkts(pkt_num,21) = diff_sync;
    uoi_pkts(pkt_num,22) = diff_sfd;
    
    
end% packets found

return;

⌨️ 快捷键说明

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