1. CR网络和主网络(授权网络)共同存在于同一区域,并且使用同一频段。假设该频段共有N个信道,每个主用户或CR用户每次接入只占用一个信道。若所有信道均被主用户占用,此时CR用户到达就被阻塞。若CR用户正在使用的信道有主用户出现,此时CR用户被迫中断,并进入缓存区排队等待空闲可用信道以继续刚被中断的通信,若等待超过一定时限,则判定CR用户强制中断退离缓存区。

2. 主用户和次用户的到达服从泊松分布,参数分别为lambdap和lambdas,平均服务时间服从参数为mup和mus的负指数分布
3. 对次用户而言,主用户抢占优先。总共有N个信道,也就是最多可以有N个主用户抢占所有信道,故Z队列的长度不会超过N,这里给定Z队列长度为N。
4. 假设初始状态所有N个信道均空闲,次用户理想感知,感知延时为0.005

clear 
clc 
rand('twister',0);
blockpu=[];
blocksu=[];
for N=3:2:7
    block=[];
    for lambdap =0.01:0.01:0.5
%*****************************************

%初始化 
%***************************************** 
a = 10; %主用户数量
b = 100; %次用户数量
%N =2  %Z队列最大长度/总的信道数
%Tao=5;%切换时延门限Tao
A = [ ]; %某主用户到达时刻占用信道序号的集合
B = [ ]; %某次用户到达时刻占用信道序号的集合
C = [ ]; %切换用户占用的当前所有信道序号集合
D = [ ]; %某次用户到达时刻主用户占用信道集合
member = [ ];
member_CR = [ ];
j1=1;
%主用户参数***************************************** 
%lambdap = 0.1; 
mup =0.6; %主用户到达率与服务率
arr_meanp = 1/lambdap; 
ser_meanp = 1/mup;%主用户平均到达时间与平均服务时间 
arr_nump = a; %round(Total_time*lambdap*2);
tp = zeros(6,arr_nump); 
tp(1,:) = exprnd(arr_meanp,1,arr_nump); %按负指数分布产生各主用户到达时间间隔 
tp(1,:) = cumsum(tp(1,:)); %各主用户的到达时刻等于时间间隔的累积和 
tp(2,:) = exprnd(ser_meanp,1,arr_nump); %按负指数分布产生各主用户服务时间
%次用户参数***************************************** 
lambdas =0.4; 
mus =0.7; %次用户到达率与服务率
arr_means = 1/lambdas; 
ser_means = 1/mus; %次用户平均到达时间与平均服务时间
arr_nums = b;  
ts = zeros(6,arr_nums); 
ts(1,:) = exprnd(arr_means,1,arr_nums); %按负指数分布产生各次用户达到时间间隔
ts(1,:) = cumsum(ts(1,:)); %各次用户的到达时刻等于时间间隔的累积和 
ts(2,:) = exprnd(ser_means,1,arr_nums); %按负指数分布产生各次用户服务时间 
%切换用户参数*****************************************待计算lambdah和muh
arr_numh = 10; %切换用户排队长度设置
th = zeros(6,arr_numh); 
tsh=[];
%***************************************** 
%计算第1个主用户的信息 
%***************************************** 
if arr_nump>=1
tp(3,1) = 0; %第1个主用户进入系统后直接接受服务,无需等待 
n = ceil(rand*N); %产生一个在N范围内的随机数作为接入的信道序号
tp(4,1) = tp(1,1)+tp(2,1); %其离开时刻等于其到达时刻与服务时间之和 
tp(5,1) = 1; %其肯定被系统接纳,此时系统内共有1个主用户,故标志位置1 
tp(6,1) = n; %依次记录主用户占用信道的序号
A=[A n];
member = [1]; %其进入系统后,系统内已有成员序号为1 
else
    !echo No Primary Users!!!!
end
%***************************************** 
if arr_nums>=1
if arr_nump>=1
k1 = sum(ts(1,:) < tp(1,1));
if k1~=0
  for i =1:k1
    if i==1
        ts(3,i) = 0.005; %其等待时间为 0
        ts(4,i) = ts(1,i)+ts(2,i)+ts(3,i); %其离开时刻等于到达时刻与服务时间之和 
        ts(5,i) = 1; %其标志位置 1 ,即次用户在用当前信道
        m = ceil(rand*N); %产生一个在N范围内的随机数作为接入的信道序号
        ts(6,i) = m; %依次记录次用户占用信道的序号
        B=[B m];
        member_CR =[1];
        handoff1=find(tp(1,:)>ts(1,i));
        handoff2=find(tp(1,:)<ts(4,i));
        if isempty(handoff1)==0&&isempty(handoff2)==0
        handoff3=setdiff(handoff1,handoff2);%当前次用户通信期间(时间段)到达的主用户
        handoff=setdiff(handoff1,handoff3);
        handoff4=[];
        for puid=1:length(handoff)
           if tp(6,handoff(puid))==ts(6,i)
               handoff4=[handoff4,handoff(puid)];
               break;
           end
        end    
        if isempty(handoff4)==0
            if j1<=arr_numh                
                th(1,j1)=tp(1,handoff4(1));
                th(2,j1)=ts(4,i)-tp(1,handoff4(1));
                ts(4,i)=tp(1,handoff4(1));  
                tsh=ts(:,i);                     
                %切换到其他可用信道
                num_arrivep=find(tp(1,:)<=th(1,j1));
                num_leavep=find(tp(4,:)>=th(1,j1));
                num_present1=setdiff(num_arrivep,num_leavep);
                num_present2=setdiff(num_arrivep,num_present1);%当前在的主用户
                num_arrives=find(ts(1,:)<th(1,j1));
                num_leaves=find(ts(4,:)>th(1,j1));
                num_present3=setdiff(num_arrives,num_leaves);
                num_present4=setdiff(num_arrives,num_present3);%当前在的次用户
                num_present6=[];
wait=0;
   if j1>1
      j2=1:j1-1;
      num_arriveh=find(th(1,j2)<th(1,j1));
      num_leaveh=find(th(4,j2)>th(1,j1));
      num_present5=setdiff(num_arriveh,num_leaveh);
      num_present6=setdiff(num_arriveh,num_present5);%当前在的切换用户
      for j3=1:length(num_present6)
      wait=wait+th(3,num_present6(j3));
      end
      th(3,j1)=wait;%切换用户排队等待时间
   end
                if length(num_present2)==N
                    wait1=tp(4,num_present2(1));
                    for k=1:length(num_present2)
                    wait1=min(tp(4,num_present2(k)),wait1);
                    end
                    for k=1:length(num_present2)
                        if wait1==tp(4,num_present2(k))
                            wait2=num_present2(k);
                            break;
                        end
                    end
                   th(3,j1)=wait1-th(1,j1)+th(3,j1);
                   th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=tp(6,wait2);
                    tsh=[tsh,th(:,j1)];
                elseif isempty(num_present2)&&length(num_present4)==N
                    wait1=ts(4,num_present4(1));
                    for k=1:length(num_present4)
                    wait1=min(ts(4,num_present4(k)),wait1);
                    end
                    for k=1:length(num_present4)
                        if wait1==ts(4,num_present4(k))
                            wait3=num_present4(k);
                            break;
                        end
                    end
                    th(3,j1)=wait1-th(1,j1)+th(3,j1);
                    th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=ts(6,wait3);
                    tsh=[tsh,th(:,j1)];
                elseif length(num_present2)+length(num_present4)==N&&isempty(num_present2)==0&&isempty(num_present4)==0
                    wait1=tp(4,num_present2(1));
                    for k=1:length(num_present2)
                    wait1=min(tp(4,num_present2(k)),wait1);
                    end
                    for k=1:length(num_present4)
                    wait1=min(ts(4,num_present4(k)),wait1);
                    end
                    tps=[tp(:,num_present2),ts(:,num_present4)];
                    for k=1:length(tps)
                       if wait1==tps(4,k)
                       wait4=k;
                       break;
                       end
                    end 
                    th(3,j1)=wait1-th(1,j1)+th(3,j1);
                    th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=tps(6,wait4);
                    tsh=[tsh,th(:,j1)];
                elseif length(num_present2)+length(num_present4)<N
                    channel1=[tp(6,num_present2),ts(6,num_present4)];
                    channel=setdiff([1:N],channel1);
                    th(3,j1)=0.006+th(3,j1);
                    th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=channel(1);
                    tsh=[tsh,th(:,j1)];
                end
                j1=j1+1;
            end
        end         
        end
    elseif i >= 2
        j=1:i-1;
        number_CR = find(ts(4,j) > ts(1,i));  %当前占用信道的次用户个数
        [th1,th2]=find(th==0);
        th(:,th2)=[];
        if isempty(number_CR)&&isempty(th)
         m = ceil(rand*N); %产生一个在N范围内的随机数作为接入的信道序号
         ts(3,i) = 0.005;
         ts(4,i) = ts(1,i)+ts(2,i)+ts(3,i); %其离开时刻等于到达时刻与服务时间之和
         ts(5,i) = 1; %其标志位置 1 ,即次用户在用当前信道
         ts(6,i) = m; %依次记录次用户占用信道的序号
         B=[B m]; 
         member_CR = [member_CR,i];
         handoff1=find(tp(1,:)>ts(1,i));
        handoff2=find(tp(1,:)<ts(4,i));
        if isempty(handoff1)==0&&isempty(handoff2)==0
        handoff3=setdiff(handoff1,handoff2);%当前次用户通信期间(时间段)到达的主用户
        handoff=setdiff(handoff1,handoff3);
        handoff4=[];
        for puid=1:length(handoff)
           if tp(6,handoff(puid))==ts(6,i)
               handoff4=[handoff4,handoff(puid)];
               break;
           end
        end    
        if isempty(handoff4)==0
            if j1<=arr_numh
            th(1,j1)=tp(1,handoff4(1));
            th(2,j1)=ts(4,i)-tp(1,handoff4(1));
            ts(4,i)=tp(1,handoff4(1));
            tsh=[tsh,ts(:,i)]; 
             %切换到其他可用信道
                num_arrivep=find(tp(1,:)<=th(1,j1));
                num_leavep=find(tp(4,:)>=th(1,j1));
                num_present1=setdiff(num_arrivep,num_leavep);
                num_present2=setdiff(num_arrivep,num_present1);%当前在的主用户
                num_arrives=find(ts(1,:)<th(1,j1));
                num_leaves=find(ts(4,:)>th(1,j1));
                num_present3=setdiff(num_arrives,num_leaves);
                num_present4=setdiff(num_arrives,num_present3);%当前在的次用户
                num_present6=[];
wait=0;
   if j1>1
      j2=1:j1-1;
      num_arriveh=find(th(1,j2)<th(1,j1));
      num_leaveh=find(th(4,j2)>th(1,j1));
      num_present5=setdiff(num_arriveh,num_leaveh);
      num_present6=setdiff(num_arriveh,num_present5);%当前在的切换用户
      for j3=1:length(num_present6)
      wait=wait+th(3,num_present6(j3));
      end
      th(3,j1)=wait;%切换用户排队等待时间
   end
                if length(num_present2)==N
                    wait1=tp(4,num_present2(1));
                    for k=1:length(num_present2)
                    wait1=min(tp(4,num_present2(k)),wait1);
                    end
                    for k=1:length(num_present2)
                        if wait1==tp(4,num_present2(k))
                            wait2=num_present2(k);
                            break;
                        end
                    end
                   th(3,j1)=wait1-th(1,j1)+th(3,j1);
                   th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=tp(6,wait2);
                    tsh=[tsh,th(:,j1)];
                elseif isempty(num_present2)&&length(num_present4)==N
                    wait1=ts(4,num_present4(1));
                    for k=1:length(num_present4)
                    wait1=min(ts(4,num_present4(k)),wait1);
                    end
                    for k=1:length(num_present4)
                        if wait1==ts(4,num_present4(k))
                            wait3=num_present4(k);
                            break;
                        end
                    end
                    th(3,j1)=wait1-th(1,j1)+th(3,j1);
                    th(4,j1)=th(1,j1)+th(2,j1)+th(3,j1);
                    th(5,j1)=1;
                    th(6,j1)=ts(6,wait3);
                    tsh=[tsh,th(:,j1)];
                elseif length(num_present2)+length(num_present4)==N&&isempty(num_present2)==0&&isempty(num........................

D101

CR网络和主网络的认知无线电切换算法相关推荐

  1. 华为设备配置ipsec 与mpls用于分支网络连接主网络

    这粉红色模块的代表的是分支网络 一,配置ipsec AR6配置: 阶段一 ike proposal 1 encryption-algorithm aes-cbc-256 ||加密算法 authenti ...

  2. m认知无线电信号检测算法matlab仿真,能量检测,循环平稳检测以及自相关检测

    目录 1.算法概述 2.仿真效果预览 3.MATLAB部分代码预览 4.完整MATLAB程序 1.算法概述 频谱感测是认知无线电的一项关键技术.我们将频谱感知作为一个分类问题,提出一种基于深度学习分类 ...

  3. 把树莓派改造成无线网卡(3)-----共享无线网络,无线网络转换成有线网络,让有线网络设备连上无线网络

    本文目录 1.准备工作 2.安装DNS和配置管理软件 3.设置网络路由功能 3.1.树莓派的有线网络接口IP配置 3.2.启用路由和IP伪装 3.3.为有线网络配置DHCP和DNS服务 4.运行 5. ...

  4. 集中式服务器模型无线网络,认知无线电中次用户在重试排队和共享服务器模型下的均衡止步策略...

    摘要: 近几十年来,无线通信技术不断发展,频谱空间被划分的所剩无几,频谱资源日趋紧张,而这种资源紧张更多是由于对不同无线接入技术的频谱分配不合理引起的,认知无线电技术基于此应运而生.认知无线电技术中的 ...

  5. 认知无线电网络架构与协议体系

    认知无线电网络架构与协议体系 本文转载自中国联通通信技术 摘要:认知无线电网络具有动态.灵活.智能地使用频谱资源,提高频谱利用率的特点,其网络结构和协议体系的设计是实现上述网络功能的关键.现有基于认知 ...

  6. m认知无线电网络中频谱感知的按需路由算法matlab仿真

    目录 1.算法概述 2.仿真效果预览 3.MATLAB部分代码预览 4.完整MATLAB程序 1.算法概述 使用无线电用户的频率范围在 9kHz 到 275GHz[3],由于无线通信环境中的干扰.信道 ...

  7. 认知无线电网络中的用户

    背景 认知无线电(Cognitive radio),又称感知无线电,是利用频谱间的空隙,即频谱空洞进行动态频谱接入与传输,以达到在拥挤频谱空间进行讯息传输,提高频谱空间利用率的技术. 原文 In co ...

  8. 泰萌主今天怎么显示服务器异常,泰萌主网络请求错误怎么办?泰萌主怎么看不了了?...

    近日不少的小伙伴称打开泰萌主的时候一直显示升级更新,但是升级之后打开什么也没有,一直显示网络请求错误,重新安装还是这样,这是什么原因呢?泰萌主的下载是不是有问题?泰萌主现在看不了怎么办呢?下面就来解决 ...

  9. 网络社交媒体的情感认知与计算

    本讲座选自清华大学电子工程系信息认知与系统智能研究所副所长黄永峰在清华RONGv2.0系列论坛之 "社会关系网络与大数据技术"专场上所做的题为<网络社交媒体的情感认知与计算& ...

  10. 【免疫算法,资源分配】基于免疫算法的认知无线电资源分配研究

    1.软件版本 matlab2017b 2.本算法理论知识 在生命科学领域,人们对遗传和免疫等自然现象进行了广泛而深入的研究.20世纪60年代,Bagley和Rosenberg等先驱使用了相关的内容和知 ...

最新文章

  1. 邮箱自动转发攻击邮件服务器
  2. 利用SQL中的递归返回多行数据的连接
  3. 游戏人工智能开发之6种决策方法
  4. html网页设如何置访问密码,利用JS给单页html加上简单访问密码,需要密码才能访问!...
  5. Java 14 发布了,再也不怕NullPointerException 了!?
  6. php添加gd库,linux下为php添加GD库(重新编译php)
  7. KubeSphere配置集(ConfigMap)的使用
  8. docker 实战---使用oracle xe作为开发数据库(六)
  9. Android 一步步教你从ActionBar迁移到ToolBar
  10. nosql笔记1_早前的时候
  11. log4net配置mysql_使用独立的log4net.config文件配置log4net,将日志记录到Mysql数据库【原创】...
  12. 软件项目管理期末复习(看这一篇就够了)
  13. 机器学习 泛化误差和偏差-方差
  14. mac软件推荐(适用m1)
  15. Finger.02 - 搭建MQTT服务器
  16. 如何查询期刊的中科院分区
  17. windows安装TexStudio
  18. Qt模仿QQ聊天窗口合并功能
  19. [导入]山寨也疯狂:前卫手表造型 Cool G108 Watch手机亮相
  20. 全文检索-Elasticsearch安装、集群和使用超全解读

热门文章

  1. gxworks2使用指令手册_编程软件GX-Works2公共篇操作手册三菱GX-Works2手册 - 广州凌控...
  2. python win32api教程_解放双手——python win32api 入门
  3. 2021 CSDN查看自己关注的人
  4. 如何用matlab画圆的图像,matlab在图像上画圆
  5. GBase数据库迁移工具介绍
  6. web 前端学习之制作网页视频
  7. ad18的一个bug,修改不了封装
  8. MD5算法实验报告(XDU物联网安全)
  9. VB实际读写INI文件
  10. Visual Studio 2019 C++实现socket通信,添加ws2_32.lib库,新手代码