matlab仿真基站、用户PPP分布

矩阵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
posted @ 2017-11-25 17:09  JokerMan  阅读(4800)  评论(8编辑  收藏  举报