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

📄 final_sim_ppc.m

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

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

topodir = 'Topo';
dirname = 'Results_PPC';

for m = 1:length(a)
    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);

            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));
                            interference(self) = interference(self) + c1*power(nodes)/dist(self, nodes);
                        end
                    end
                    
                    interference_out(self, i) = interference(self);

                    SNR(self) = (power(self)*c2/rd^4)/interference(self);
                    
                    range(self) = rd*(SNR(self)/SNR_q)^(1/4);
                    range_out(self,i) = range(self);
                    
                    power_new(self) = betarnd(a(m), b(m))*10;
                    power_out(self, i) = power_new(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)), '_a', num2str(a(m)), '_b', num2str(b(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)), '_a', num2str(a(m)), '_b', num2str(b(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)), '_a', num2str(a(m)), '_b', num2str(b(m)), '.mat');
            save(sim_name, 'interference_out');
            
            end
        end
    end
end

⌨️ 快捷键说明

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