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

📄 aloha.m

📁 R. Lin and A.P. Petropulu, 揂 New Wireless Medium Access Protocol Based On Cooperation,擨EEE Trans. on
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                          aloha.m
% This program is designed for aloha protocol in random access network.  It gives
% the maximum throughput vs. aggregated traffic load (including newly generated 
% packets and retransmitted packets) under a certain SNR.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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; %Total number of independent Bernoulli trails

threshold=0.1; % threshold for active user detection.

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

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


for ii=1:length(P)
    ii
    Successes = 0;
    
    for jj = 1:numTrial
        Load  = rand(1,J);
        Trans = Load <= P(ii);
        num_active=sum(Trans);
        if num_active == 1
            
            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,1)-0.5)+j*sign(rand(N1,1)-0.5)];
            noise = sqrt(1/(10^(snr/10)))*(randn(N/2,1)+j*randn(N/2,1));
            
            y = packet*HA(active, t1) + noise;  
            
            %%%%%%%%%% BS side %%%%%%%%%%%%%%%%%%%%
            alpha=ID'* y(1:J, :)/J/2;
            
            %......... active user detection
            num_DetUser = sum(abs(alpha(:,1))>threshold);
            DetUser = find(abs(alpha(:,1))>threshold);
            
            if ( num_DetUser == 1 ) & (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);
                
                bbb=mapper2(packet(J+1:end,1),1);
                sss=mapper2(rev(:,1),1);
                look=bbb-sss;
                IBER=find(abs(look)>0);
                BIT_ERROR_RATE=length(IBER)/N;
                if (BIT_ERROR_RATE <= fec)
                    Successes = Successes + 1;
                end
                
            end %if (num_DetUser...
            
        end %end if num_active==1
        
    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 + -