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

📄 coop_ng.m

📁 R. Lin and A.P. Petropulu, 揂 New Wireless Medium Access Protocol Based On Cooperation,擨EEE Trans. on
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                          coop_ng.m
% This program is designed for the cooperative retransmission scheme
% in random access network.  It shows the maximum possible throughput
% vs. traffic load (not only newly generated load) under a certain SNR.
% All the nodes share the whole bandwidth.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


clear all; close all;
snr = 20;

% Simulation parameters
J = 32; %32; % total number of users                 
N = 424; % length of packet

N1 = N/2 - J; %number of data symbols per packet (QPSK)
ID = hadamard(J)+j*hadamard(J);      % every user has an ID orthogonal to others'
M = 20000;
numTrial = 2000; %number of independent Bernoulli trails


threshold=0.1; %threshold for active user detection

P = 0.1:0.5:5.6;
P=P/J;

fec = 0.02; % packets received with BER higher than fec is considered lost/corrupted

%..load channel transfer matrix
load channel_ng;


for ii=1:length(P)
    ii
    Successes = 0;
    
    for jj = 1:numTrial
        succ = 0;
        Load  = rand(1,J);
        Trans = Load <= P(ii);
        num_active=sum(Trans);

        if num_active > 0
            rand('state',ii*171+jj*23+822);
        
            t1 = randsrc(1, 1, [1:M]); %random start time instant
            
            active = find(Trans)';
            packet = [ID(:,active); sign(rand(N1,num_active)-0.5)+j*sign(rand(N1,num_active)-0.5)];
            noise = sqrt(1/(10^(snr/10)))*(randn(N/2,1)+j*randn(N/2,1));
            
            y = packet*HA(active, t1) + noise;  
            
            % ....Possible retransmissions..........
            
            for mm=1:num_active-1
                relay = mod(t1+mm, J)+1;
                
                tt = find(active == relay);
                if (~isempty(tt))
                    y1 = packet(:,tt)*HA(relay, t1+mm);
                else
                    
                    noise = sqrt(1/(10^(snr/10)))*(randn(N/2,1)+j*randn(N/2,1));
                    
                    y1 = packet*HH(active, relay, t1) + noise;
                    
                    y1 = sqrt(N)*y1./norm(y1)*HA(relay,t1+mm);
                end
                noise = sqrt(1/(10^(snr/10)))*(randn(N/2,1)+j*randn(N/2,1));
                y1 = y1 + noise;
                y = [y, y1];
            end
            
            %%%%%%%%%% BS side %%%%%%%%%%%%%%%%%%%%
            
            %....active user detection........
            alpha=ID'* y(1:J, :)/J/2;
            num_DetUser = sum(abs(alpha(:,1))>threshold);
            DetUser = find(abs(alpha(:,1))>threshold);
            
            if ( num_DetUser == num_active ) & (DetUser == active) 
                
                A = alpha(DetUser, :);
                
                % Linear Decoding (Zero Forcing)                    
                tt = y(J+1:end, :)*A'*inv(A*A');
                rev = sign(real(tt)) + j*sign(imag(tt));
                
                %Maximum Likelihood Decoding                
%                rev = decodpac(y(J+1:end, :), A);
                
                for kk=1:num_DetUser
                    bbb=mapper2(packet(J+1:end,kk),1);
                    sss=mapper2(rev(:,kk),1);
                    look=bbb-sss;
                    IBER=find(abs(look)>0);
                    BIT_ERROR_RATE=length(IBER)/N;
                    if (BIT_ERROR_RATE <= fec)
                        succ = succ + 1;
                    end
                end
                
            end %if (num_DetUser...
            if num_DetUser ~= 0
                succ = succ/num_DetUser;
            end
            
        end %end if num_active>0
        
        Successes = Successes + succ;
    end %end of jj = 1:numTrial
    
    Throughput(ii) = Successes/numTrial;
end %end of ii=1:length(Ns)

plot(P*J, Throughput, '-*');
% temp = Throughput./(P*J);
% figure; plot(P*J, temp);

⌨️ 快捷键说明

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