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

📄 multicastgprs.asv

📁 这是一个基于matlab/RUNE环境的移动通信网络仿真程序包
💻 ASV
字号:
% Multicast scheme in GPRS network.
% One cell implementation.
% With Link Adaptation

% Clear workspace
%clear
%clc

% Maximum time for simulation
t_max = 15*60; % seconds

% Sampling time
t_samp = 0.02; % the time is discrete, with sampling time is 20 ms

% Number of Time slots
num_ts = 4;

% Carrier to Interference Ratio for user (as an input from channel part)
ctoi = CIR;

%ctoi = 6*ones(30,(t_max/t_samp));
cs = CIR_to_CS(CIR_multi,6,12,18); %coding scheme

% Create Traffic
user_traffic = traff;

% Initialization
buffhist = zeros(1,30);
overall_th = zeros(1,30);
packet_loss = zeros(1,30);
bits_loss = zeros(1,30);

% to make a graph, user 2-50

for N_user = 2:30
    
    N_user
    
    % Create Buffer
    buffer = 0;
    
    %user throughput
    average_th = zeros(1,N_user);
    data = zeros(1,N_user);

    % User's delay 
    delay = zeros(1,N_user);

    % Loss channel
    p_loss_chan = zeros(1,N_user); %packet
    b_loss_chan = zeros(1,N_user); %bits

    % Let it start!!!
    t_old = 0;
    t_new = t_old + t_samp;

    index = 1; % number of packets received/enter buffer

    while (t_new<t_max-0.0001)
    
        % Update buffer 
        buffer = buffer + sum(user_traffic(floor(t_old/t_samp+1):floor((t_new/t_samp)))); % fill buffer with packet
        
        % buffhist(state,:) = buffer; % record buffer
        % if (user_traffic((2*(t_old/t_samp)+1):(2*t_new/t_samp)) ~= 0)
        % index = index + 1; % calculate number of packet ( 1 index = 15 frames/packets)
        % end
        
        % transmitting data
        switch (cs(N_user,floor((t_old/t_samp)+1)))
            case 1
                bitrate = num_ts*9050; %coding scheme 1
            case 2
                bitrate = num_ts*13400; %coding scheme 2
            case 3
                bitrate = num_ts*15600; %coding scheme 3
            case 4
                bitrate = num_ts*21400; %coding scheme 4
        end

        transmitted = bitrate * 0.0046 * 4; %4 RLC blocks
    
        if (buffer < transmitted)
            transmitted = buffer;
        end
    
        % emptying buffer
        buffer = buffer-transmitted; 
    
        %calculating throughput
        a = per(cs(N_user,floor((t_old/t_samp)+1)),ctoi(1:N_user,floor((t_old/t_samp)+1))');
        aa = ones(num_ts,1)*a;
        b = rand(num_ts,N_user); % create a random for each ue on each TS 
   % calculate in a time step(20ms or more?) the received right and error bits     
        for ts = 1:num_ts
            success = find (b(ts,:) >= aa(ts,:));
            data(success) = data(success) + (transmitted/num_ts);
            fail = find (b(ts,:) < aa(ts,:));
            p_loss_chan(fail) = p_loss_chan(fail) + 1 ;
            b_loss_chan(fail) = b_loss_chan(fail) + (transmitted/num_ts);
        end
        
        %         %calculating throughput(OLD)
%         a = per(cs(N_user,floor((t_old/t_samp)+1)),ctoi(1:N_user,floor((t_old/t_samp)+1))');
%         b = rand(1,N_user) ;
%         success = find (b>=a);
%         data(success) = data(success) + transmitted;
%         fail = find (b<a);
%         p_loss_chan(fail) = p_loss_chan(fail) + num_ts*1 ;
%         b_loss_chan(fail) = b_loss_chan(fail) + transmitted;

        
        t_old = t_new;
        t_new = t_new + t_samp; % update time
    end

    % Overall throughput
    average_th = data/t_max;
    overall_th(N_user) = sum(average_th)/N_user;
    %average packet loss
    all_packet = N_user*(t_max/t_samp)*4;
    packet_loss(N_user) = sum(p_loss_chan)/(all_packet);
    %average bits loss
    bits_loss(N_user) = sum(b_loss_chan)/(N_user*t_max);
    %buffer history
    buffhist(N_user) = sum(buffer);  
        
end

th_multi = overall_th;
pl_multi = packet_loss;
buff_multi = buffhist;

x = 2:1:30;
figure(5)
subplot(2,2,1);
plot(x,overall_th(2:30));
grid on;title('Multicast Throughput');
%figure(2);
subplot(2,2,2);
plot(x,packet_loss(2:30));
grid on;title('Multicast RLC Blocks Loss');
%figure(3);
subplot(2,2,3);
plot(x,bits_loss(2:30));
grid on;title('Multicast Bits Loss');
%figure(4);
subplot(2,2,4);
plot(x,buffhist(2:30));
grid on;title('Multicast Buffer Occupancy');
% figure(5)
% plot(x,average_delay);
% grid on;

clear overall_th buffhist packet_loss bits_loss ctoi average_th t_old t_new cs data N_user a b p_loss_chan b_loss_chan success fail transmitted user all_packet bitrate delay index user_traffic CIR_multi CIR_uni CIR buffer traff aa
save multi




























% Overall delay
    % delay counted as the time packet stays/waits in the buffer, thus
    %difference between buffhist with value equals to zero (excluding 
    %consecutive zeros)


    % for j = 1:N_user
    %     A = find(buffhist(:,j)==0);
    %     for k = 1:length(A)-1
    %         if( (A(k+1)-A(k)) > 1)
    %         delay(j) = delay(j) + (t_samp*(A(k+1)-A(k)));
    %         end
    %     end   
    %     delay(j) = delay(j)/index;
    % end
    % average_delay(N_user) = sum(delay)/N_user;

⌨️ 快捷键说明

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