1. 程式人生 > >matlab仿真基站、用戶PPP分布

matlab仿真基站、用戶PPP分布

mean close with find position dex roc fun 比較

矩陣A的第i列 A(;,i)
矩陣A的第i行 A(i,:)
復制mxn個矩陣A B=repmat(A,m,n)
找到最小值以及索引 [min_value,index]=min(values)
兩值比較大小返回0/1布爾值 a>b

PPP分布在2D空間:根據lambda均值生成點的個數n,然後n個點的坐標在x方向和y方向上滿足均勻分布

代碼:

function [matrix_UE_BS] = Model_Init(BS_lambda, UE_lambda, R)
clc;close all;
%INPUT: lambda of BS and UEs, the range of BS station
%OUTPUT: the map of UE and its corresponding BS.The first column is the closest BS index, the second column % is the distance from UE to the closest BS, the third column is the service BS of UE.If the value in the third %column is 0, that means there is no BS could provide service for UE. %according to lambda, assign the position of BS and UE.
[BS_pos, BS_num]=poisson2d(BS_lambda); [UE_pos, UE_num]=poisson2d(UE_lambda); plot(BS_pos(:, 1), BS_pos(:, 2), ‘pr‘); hold on; plot(UE_pos(:, 1), UE_pos(:, 2), ‘.b‘); %compute the distance from BS to every UE dist = zeros(UE_num,BS_num); for i= 1:BS_num ith_BS_pos=repmat(BS_pos(i,:),UE_num,1); d=ith_BS_pos-UE_pos; dist(:,i)=sqrt(sum(d.^2
,2)); end %find the minumum distance [min_dist,index]=min(dist‘); %R is the range of BS service. According to the thersold of R,judge UE is in service or not. matrix_UE_BS=zeros(UE_num,3); matrix_UE_BS(:,1)=index‘; matrix_UE_BS(:,2)=min_dist‘; matrix_UE_BS(:,3)=index‘.*(R>min_dist‘); end

其中引用的函數poisson2d.m代碼:

function [ pproc,npoints ] = poisson2d( lambda )
% POISSON2D generate and plot Poisson process in the plane 
%   (square [0,1]x[0,1]). 
% 
% [pproc] = poisson2d(lambda)
%
% Inputs: lambda - intensity of the process
%
% Outputs: pproc - a matrix with 2 columns with coordinates of the
%          points of the process

  % the number of points is Poisson(lambda)-distributed
  npoints = poissrnd(lambda);

  % conditioned that the number of points is N,
  % the points are uniformly distributed
  pproc = rand(npoints, 2);

  % plot the process
  %plot(pproc(:, 1), pproc(:, 2), ‘pr‘)
end

matlab仿真基站、用戶PPP分布