如何将认知无线电资源分配的主程序从一种用户改成两种用户?? 10C

以下是一段认知无线电的资源分配的主程序,但这是单种用户的,如何能将其改成分成授权用户和认知用户,不需要检测过程,只需要在程序中定义这两种用户,通过识别授权用户和认知用户,如果是授权用户则按照单用户的方法分配,如果是认知用户则调用一个子载波分配算法来计算剩余功率。
我是个新手,还请各路大神帮帮忙,帮忙看看要怎么分成两种用户。
% SIPS 2004 Main Simulation File

clear all;
worstpower=1.1565;
N0=worstpower*1e-8;
Ptot=1;
BER = 1e-3;
Gap = -log(5*BER)/1.6;

channel=10;
samplenum=10;
numuser = 8;

epsilong=1e-3;
maxNumOfNewton=0;
maxTotalNewtonIteNum=0;

avenonlintime = zeros(1,numuser);
aveshentime = zeros(1,numuser);
aveiantime = zeros(1,numuser);

diffuservector = [];
iancapamat = [];
shencapamat = [];

cc = 1;

clear shencapa iancapa
N=64;
B=1000000;

noise=B*N0/N;
clear ch

%for different user number
for ii=1:numuser,
diffuser=2*ii;
diffuservector(ii)=diffuser;
K=diffuser;

totaliancapa=0;
totalshencapa=0;
totalnonlincapa = 0;

shencapavec = zeros(1,diffuser);
iancapavec = zeros(1,diffuser);

iannorm = 0;
shennorm = 0;
nonlinnorm = 0;


%for different channel
for chan=1:channel,
    [env,I,Q]=chtry(K,samplenum,30);
    h = rand(1,K);
    gamma = .064*(h < .5) + .128*((h >= .5) & (h < .8)) + .256*(h>.8);

    %for diff samples
    for diffsamp=1:samplenum,
        for i=1:K
            user=I(i,:,diffsamp)+sqrt(-1)*Q(i,:,diffsamp);
            ch(i,:)=abs(fft(user,N)).^2/Gap;
        end


        % Shen's subcarrier allocation
        [rheecapa,rheesuballo]=rheesub(Ptot,ch, N, K, noise, gamma);

        % Shen's power allocation
        t=cputime;  shenp = shenpowerallo(ch,rheesuballo,N,K,Ptot,noise,gamma); shentime = cputime-t;
        aveshentime(ii) = aveshentime(ii) + shentime;

        % Ian's subcarrier allocation
        [iancapa,iansuballo]=wongsuballo(Ptot, ch, N, K, noise, gamma);

        % Ian's power allocation
        t=cputime; ianp = wongpowerallo(ch,iansuballo,N,K,Ptot,noise,gamma); iantime = cputime-t;
        aveiantime(ii) = aveiantime(ii) + iantime;

        for i=1:K,
            shencapa(i) =  waterfilling(shenp(i),rheesuballo(i,:).*ch(i,:)/noise)/N;
            iancapa(i) = waterfilling(ianp(i),iansuballo(i,:).*ch(i,:)/noise)/N;
        end;

        totalshencapa=totalshencapa+sum(shencapa);
        totaliancapa=totaliancapa+sum(iancapa);

        if (chan == 1),
            shencapavec = shencapavec + shencapa;
            iancapavec = iancapavec + iancapa;
            if (chan ==  1 & diffsamp == 1),
                figure(2);
                bar([gamma/sum(gamma); iancapavec/sum(iancapavec); shencapavec/sum(shencapavec)]', 'grouped');%; nonlincapavec/sum(nonlincapavec)]', 'grouped');
                title('snapshot');
            end;
        end;
        iannorm = iannorm + norm(iancapa/sum(iancapa) - gamma/sum(gamma), inf);
        shennorm = shennorm + norm(shencapa/sum(shencapa) - gamma/sum(gamma), inf);
    end

    if (chan == 1),
        iancapavec = iancapavec/(channel*samplenum);
        shencapavec = shencapavec/(channel*samplenum);
        figure(5);
        bar([gamma/sum(gamma); iancapavec/sum(iancapavec); shencapavec/sum(shencapavec)]', 'grouped');
        legend('Gamma', 'LINEAR', 'ROOT-FINDING');
    end;
    %end diff channel
end
maxNumOfNewton;
maxTotalNewtonIteNum;
totalshencapavec(ii)=totalshencapa/(channel*samplenum);
totaliancapavec(ii)=totaliancapa/(channel*samplenum);
iannormvec(ii) = iannorm/(channel*samplenum);
shennormvec(ii) = shennorm/(channel*samplenum);

end

% total capacities plot
figure(1)
plot(diffuservector,totaliancapavec, 'ko--', diffuservector, totalshencapavec, 'b+-.');%, diffuservector, totalnonlincapavec, 'rx-.');
iansumcapa = sum(totaliancapavec)
shensumcapa = sum(totalshencapavec)

grid on
xlabel('number of users')
ylabel('capacity (bit/s/Hz)')
legend('LINEAR', 'ROOT-FINDING');%, 'NONLIN');
hold off

aveshentime = aveshentime/(channel*samplenum)
aveiantime = aveiantime/(channel*samplenum)

figure(3);
semilogy(diffuservector,aveiantime, 'ko--', diffuservector,aveshentime, 'b+-.');%, diffuservector, avenonlintime, 'rx-.');
grid on
xlabel('number of users')
ylabel('Ave CPU time (s)')
legend('LINEAR', 'ROOT-FINDING');%, 'NONLIN');
title('Average CPU time comparison');

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!