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

📄 final_sim_dapc.m

📁 RFID系统密集读写PPC算法的设计和仿真
💻 M
字号:
% Final DAPC simulation
clc;clear all;close all;

display(' *** Load System Parameters ***');
reader_m;

topodir = 'Topo';
dirname = 'Results_DAPC';

for m = 3:3
    for runs = 1:length(nn)
        for mindists = 1:length(mindist)
            for j = 1:length(vars)

            toponame = strcat(topodir, '/', 'TOPO_R', num2str(nn(runs)), '_D', num2str(mindist(mindists)), '_V', int2str(vars(j)), '.mat')
            display(' *** Load Topology ***');
            load(toponame);

            power = pinitial*ones(nn(runs), 1);

            rb_count = (-1)*ones(nn(runs), 1);
            mode_op=zeros(nn(runs),1);
            need_var = zeros(nn(runs),1);
            percentage = zeros(nn(runs),1);
            rd_each = rd * ones(nn(runs),1);
            alpha_est = zeros(nn(runs),1);
         
            display(' *** Run Simulation ***');
            tic;

            %Calculate distance between all nodes
            for self = 1:nn(runs)         %loop through all nodes
                for nodes = 1:nn(runs)    %loop through all other nodes to calculate interference
                        dist(self, nodes) = distfn(coordinate(nodes,1), coordinate(nodes,2), coordinate(self,1), coordinate(self,2))^2; %calculate distance
                end
            end

            for i=1:t                         %loop through time
                for self = 1:nn(runs)         %loop through all nodes
                    interference(self) = nf;
                    for nodes = 1:nn(runs)    %loop through all other nodes to calculate interference
                        if self ~= nodes
                            %dist(nodes) = distfn(coordinate(nodes,1), coordinate(nodes,2), coordinate(self,1), coordinate(self,2)); %calculate distance
                            interference(self) = interference(self) + c1*power(nodes)/dist(self, nodes);    %add interference
                        end
                    end
                    
                    %avg_interference(self) = avg_interference(self) * (t-1)/t + interference(self)/t;
                    interference_out(self, i) = interference(self);
                    SNR(self) = (c2/rd_each(self)^4)*power(self)/interference(self);   %calculate SNR

    %%%%%%%%%%%%% Interference Estimation
                    error(self) = SNR(self)-SNR_q;
                    alpha_est(self) = alpha_est(self) + sigam*SNR(self)*error(self);
                    %alpha_est(self) = alpha_est(self) + sigam*SNR(self)*error(self) - abs(1-SNR(self)^2)*alpha_est(self);
                    %alpha_est_out(self, i) = alpha_est(self);
                    power_new(self) = min((interference(self)/(c2/rd_each(self)^4))*(SNR_q-alpha_est(self)*SNR(self)+k_v*error(self)), pmax);
                    power_new(self) = max(power_new(self), pmin);
                    %SNR_out(self, i) = SNR(self);
                    range(self) = rd_each(self)*(SNR(self)/SNR_q)^(1/4);
                    if range(self) > tolerance * rd
                        percentage(self) = ((i-1)*percentage(self)+1)/i;
                    else
                        percentage(self) = (i-1)*percentage(self)/i;
                    end

    %%%%%%%%%%%%% Selective Backoff
                    if mode_op(self) == 0
                        if power_new(self) == pmax
                            mode_op(self) = 1;
                            %power_new(self) = pmin;
                            %rb_count(self) = ceil(randseeder*rand() + jj(m)*(exp(kk(m)*percentage(self))-1));
                            rb_count(self) = ceil(randseeder*rand() + 10*(log10(percentage(self)+0.01)+2));
                        end
                    elseif mode_op(self) == 1
                        power_new(self) = pmin;
                        rb_count(self) = rb_count(self) - 1;
                        if rb_count(self) == 0
                            mode_op(self) = 0;
                        end
                    end
                    
%                    rb_count_out(self, i) = rb_count(self);
                    power_out(self, i) = power_new(self);
                    range_out(self,i) = range(self);
                end
                power = power_new;
            end

            toc;
            
            display(' *** Save Data ***');
            sim_name = strcat(dirname, '/', 'RANGE_OUT_R', num2str(nn(runs)), '_D', num2str(mindist(mindists)), '_V', int2str(vars(j)), '_M', num2str(m), '.mat');
            save(sim_name, 'range_out');
            sim_name = strcat(dirname, '/', 'POWER_OUT_R', num2str(nn(runs)), '_D', num2str(mindist(mindists)), '_V', int2str(vars(j)), '_M', num2str(m), '.mat');
            save(sim_name, 'power_out');
            sim_name = strcat(dirname, '/', 'INTERFERENCE_OUT_R', num2str(nn(runs)), '_D', num2str(mindist(mindists)), '_V', int2str(vars(j)), '_M', num2str(m), '.mat');
            save(sim_name, 'interference_out');
            sim_name = strcat(dirname, '/', 'PERCENTAGE_OUT_R', num2str(nn(runs)), '_D', num2str(mindist(mindists)), '_V', int2str(vars(j)), '_M', num2str(m), '.mat');
            save(sim_name, 'percentage');
            end
        end
    end
end

⌨️ 快捷键说明

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