📄 runeffh.m
字号:
function [res, par, sys] = runeffh(par,sta,sys) % DESCRIPTION [res, par, sys] = runeffh(par,sta,sys)% The basic rune dynamic function with rayleigh fading taken% into consideration.% INPUT% all inputs are optional% par -- basic enviromental entitities% .cellradius -- cell radius [m]% .km -- km^2+lm^2+km*lm => the number of sites% .lm -- related to km above% .sps -- Number of sectors per site% .ncluster -- number of clusters equals ncluster^2% .kpc -- number of allocated channels per cell% .gainconst -- gain at 1 meter distance [dB] % .noise -- thermal noise floor [dBm]% .alpha -- distance attenuation coefficient% .sigma -- standard deviation for the log-normal fading [dB]% .raa -- lognormal correlation down link (typical 0.5)% .corrdist -- lognormal fading correlation distance [m]% .offtraf -- average number of offered calls to a cell [Erlang/cell] % .mht -- mean holding time [seconds] % .amean -- acceleration [m/s/s]% .vmean -- speed [m/s]% .pinit -- init power set to each new link [dBm]% .sirmin -- C/I level under which a call is dropped [dB] % .homargin -- gain margin between two bases used at Hand Off [dB]% .dt -- time interval in the simulation loop [s]% .maxiter -- number of iterations in the main loop % .seed -- seed to all random sequencies in the simulation% sta -- state % .xym -- Position in complex form [m]% .xyv -- Speed imag <=> north real <=> east [m/s] % .m -- mobile identity number% .b -- base station index% .k -- channel number% .pul -- transmitted power up link [dBm]% .cul -- received carrier power up link [dBm]% .iul -- interference power up link [dBm]% .sirul -- signal to interference ratio up link [dB]% .pdl -- transmitted power down link [dBm]% .cdl -- carrier downlink [dBm]% .idl -- interference down link [dBm]% .sirdl -- signal to interference down link [dB]% .mtop -- max mobile number used sofar% .obk -- the allocation of channels% .seed -- the seed before next iteration% sys -- all intermediate values needed to simulate % .xyb -- base positions [m]% .fib -- cell center vector [m]% .rombvec -- stem vectors [m]% .lobevector -- antenna gain diagram [dB]% .iniobk -- channel plan% .lognmap -- log-normal map [dB]% .mapvec -- log-normal map vectors [m]% OUTPUT% -- res -- cellarray of sta collected for each iteration% of the simulation% -- par -- same as input otherwise created within the function% -- sys -- same as input otherwise created within the function % TRY % [res, par, sys] = runeffh% by Magnus Almgren 000517 % Set simulation parameter par if not present as an input.if ~exist('par','var') par = setpar;end% Create the sys variable if not present as an input.if ~exist('sys','var') % generate base station position and directions [sys.xyb, sys.fib, sys.rombvec] = crecells(par.cellradius,par.sps,par.km,par.lm,par.ncluster); % Antenna gain for all directions, size == [360 1]. if all(abs(sys.fib)>0) sys.lobevector = sinclobe; else sys.lobevector = omnilobe; end % Create a channel plan for the system. % Number of channels that is used in each cluster: nk = length(sys.xyb)/par.ncluster.^2*par.kpc; sys.iniobk = crechanplan(length(sys.xyb),nk,par.ncluster); % Allocate channels to cells. % Create a lognormal map. if par.sigma > 0 % Is a lognormal map needed (takes a few seconds to generate). % The log-normal map is dependent on the seed. oseed = setseed(par.seed); % Set seed of pseudo random generator for the map. [sys.lognmap, sys.mapvec] = crelognmap(sys.xyb, sys.rombvec, par.corrdist); setseed(oseed); % Restore seed to original value. else sys.lognmap = 0; % Give fake arguments to pathgain, sys.mapvec = 0; % the values doesn't matter anyway endend[sys.raylmap, sys.rmapvec] = creraylmap(sys.rombvec); % init of state variable% The variables below are altered in the for loop and save after% each iterationif ~exist('sta','var') e = zeros(0,1); sta.xym = e; sta.xyv = e; sta.m = e; sta.b = e; sta.k = e; sta.pul = e; sta.cul = e; sta.iul = e; sta.sirul = e; sta.pdl = e; sta.cdl = e; sta.idl = e; sta.sirdl = e; sta.mtop = 0; sta.obk = sys.iniobk; sta.seed = par.seed;endoseed = setseed(sta.seed); % Set seed in random generators. SM 000713% the simulation loopfor iter = 1:par.maxiter % Terminate some calls and drop calls with bad quality. terones = ~isnan(sta.k)&(rand(size(sta.xym)) < 1-exp(-mdiv(par.dt,par.mht))); % Natural terminated calls. drones = (min([sta.sirul sta.sirdl],[],2) < par.sirmin); % quality dropping % Terminate by setting b and k to nan and obk to 1 [sta.b,sta.k,sta.obk] = terminate(sta.b,sta.k,sta.obk,drones|terones); % Make a realisation of new users. nmob = mrequest(par.offtraf * length(sys.xyb), mdiv(par.dt,par.mht)); nt = nans(nmob,1); % NaN vector used to concatenate with below. mn = sta.mtop+(1:nmob)'; % new mobile id numbers sta.mtop = sta.mtop+nmob; % highest mobile id so far % Clean variables. e = isfinite(sta.xym); % Keep all calls. % Refresh vector structure by removing released calls and adding new ones. sta.xym=[sta.xym(e); nt]; sta.xyv=[sta.xyv(e); nt]; sta.m=[sta.m(e); mn]; sta.b=[sta.b(e); nt]; sta.k=[sta.k(e); nt]; sta.pul=[sta.pul(e); nt]; sta.cul=[sta.cul(e); nt]; sta.iul=[sta.iul(e); nt]; sta.sirul=[sta.sirul(e); nt]; sta.pdl=[sta.pdl(e); nt]; sta.cdl=[sta.cdl(e); nt]; sta.idl=[sta.idl(e); nt]; sta.sirdl=[sta.sirdl(e); nt]; % Move old users and initiate a position to newcomers. [sta.xym,sta.xyv] = mobmove(sta.xym,sta.xyv,par.amean,par.vmean,par.dt,sys.rombvec); % Calculate the gain matrix. sta.g = pathgain(sta.xym, sys.xyb, sys.fib, sys.rombvec, ... par.gainconst, par.alpha, par.sigma, par.raa, ... sys.lobevector, sys.lognmap, sys.mapvec); % Calculate flat multipath gain. rg = useraylmap(mplus(sta.xym,10*irandn(size(sys.xyb))),sys.raylmap,sys.rmapvec); sta.g = sta.g + 2*lin2db(abs(rg)); % Perform handoff and allocate new mobiles to a channel if possible. [sta.b,sta.k,sta.obk] = handoff(sta.b,sta.k,sta.g,sta.obk,par.homargin); % Try to assign channels to new calls. [sta.b,sta.k,sta.obk] = assign(sta.b,sta.k,sta.g,sta.obk,par.homargin); % Set power to new users. sta.pul(isnan(sta.pul)) = par.pinit; sta.pdl(isnan(sta.pdl)) = par.pinit; % Reset power of terminated users. sta.pul(isnan(sta.k)) = nan; sta.pdl(isnan(sta.k)) = nan; % Perform the transmission from the sending to the receiving side, % all in dB or dBm. % up link [sta.cul, sta.iul, sta.sirul] = transmitul(sta.b, sta.k, sta.pul, sta.g, par.noise); % down link [sta.cdl, sta.idl, sta.sirdl] = transmitdl(sta.b, sta.k, sta.pdl, sta.g, par.noise); % Collect results. sta.seed = setseed; % the seed before next iteration res{iter} = sta; % Save current state.endsetseed(oseed); % Restore seed to original value. Sofia Mosesson 000713
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -