📄 scm.m
字号:
scmpar.NumPaths=6; N=6;
warning('MATLAB:NumPathsChangedAoa',['Using fixed AoD/AoAs, scmpar.NumPaths changed to ' num2str(scmpar.NumPaths) '.'])
end
% GENERATION OF RANDOM "BULK" PARAMETERS FOR ALL LINKS
switch (ni)
case (3) % do the basic thing
% check that M=20
if (M ~= 20)
scmpar.NumSubPathsPerPath=20; M=20;
warning('MATLAB:NumSubPathsChanged','NumSubPathsPerPath is not 20! Using NumSubPathsPerPath=20 instead.')
end
% generate bulk parameters for all links
bulkpar=generate_bulk_par(scmpar,linkpar,antpar);
% for interpolation
aods=bulkpar.aods;
aoas=bulkpar.aoas;
case (4) % do not generate random link parameters, use initial values
% take bulk parameters from input struct
bulkpar=initvalues;
% for interpolation
aods=bulkpar.aods;
aoas=bulkpar.aoas;
end
% ANTENNA FIELD PATTERN INTERPOLATION
% Interpolation is computationally intensive, so avoid it if possible.
% Since SCM does not support elevation, dismiss the elevation dimension (for now)
% NOTE: aods/aoas should be given in degrees.
BsGainIsScalar=0;
MsGainIsScalar=0;
if numel(BsGainPattern)>1
if (strcmp(ScmOptions,'polarized')==1)
BsGainPatternInterpolated = zeros([2 S size(aods)]); % [polarizations(2) elements links N(6) M(20)]
BsGainPatternInterpolated(1,:,:,:,:)=feval(InterpFunction,squeeze(BsGainPattern(:,1,1,:)),BsGainAnglesAz,aods, InterpMethod); % V
BsGainPatternInterpolated(2,:,:,:,:)=feval(InterpFunction,squeeze(BsGainPattern(:,2,1,:)),BsGainAnglesAz,aods, InterpMethod); % H
BsGainPatternInterpolated=permute(BsGainPatternInterpolated,[3 2 1 4 5]); % [link rx_element polarization path subpath]
else
BsGainPatternInterpolated=feval(InterpFunction,squeeze(BsGainPattern(:,1,1,:)),BsGainAnglesAz,aods, InterpMethod); % V only
BsGainPatternInterpolated=permute(BsGainPatternInterpolated,[2 1 3 4]);
end
else % if BsGainPattern is scalar
if (strcmp(ScmOptions,'polarized')==1)
BsGainPatternInterpolated=repmat(BsGainPattern, [NumLinks S 2 N M]); % [link rx_element polarization path subpath]
BsGainIsScalar=1;
else
BsGainPatternInterpolated=repmat(BsGainPattern, [NumLinks S N M]);
BsGainIsScalar=1;
end
end
if numel(MsGainPattern)>1
if (strcmp(ScmOptions,'polarized')==1)
MsGainPatternInterpolated=zeros([2 U size(aoas)]);% [polarizations(2) elements links N(6) M(20)]
MsGainPatternInterpolated(1,:,:,:,:)=feval(InterpFunction,squeeze(MsGainPattern(:,1,1,:)),MsGainAnglesAz,aoas, InterpMethod); % V
MsGainPatternInterpolated(2,:,:,:,:)=feval(InterpFunction,squeeze(MsGainPattern(:,2,1,:)),MsGainAnglesAz,aoas, InterpMethod); % H
MsGainPatternInterpolated=permute(MsGainPatternInterpolated,[3 2 1 4 5]); % [link Ms_element polarization path subpath]
else
MsGainPatternInterpolated=feval(InterpFunction,squeeze(MsGainPattern(:,1,1,:)),MsGainAnglesAz,aoas, InterpMethod); % V only
MsGainPatternInterpolated=permute(MsGainPatternInterpolated,[2 1 3 4]);
end
else % if MsGainPattern is scalar
if (strcmp(ScmOptions,'polarized')==1)
MsGainPatternInterpolated=repmat(MsGainPattern, [NumLinks U 2 N M]); % [link rx_element polarization path subpath]
MsGainIsScalar=1;
else
MsGainPatternInterpolated=repmat(MsGainPattern, [NumLinks U N M]);
MsGainIsScalar=1;
end
end
% Note: The gain patterns at this point have size(MsGainPatternInterpolated) = [link rx_element path subpath]
% OR
% size(MsGainPatternInterpolated) = [link rx_element polarization path subpath]
% (the same for BsGainPatternInterpolated)
% Do antenna field pattern interpolation for the LOS path
if (strcmpi(ScmOptions,'los')==1)
if numel(BsGainPattern)>1
BsGain_Theta_BS= feval(InterpFunction,squeeze(BsGainPattern(:,1,1,:)),BsGainAnglesAz,ThetaBs(:), InterpMethod); % V only
BsGain_Theta_BS= BsGain_Theta_BS.'; % size()= [NumLinks S]
else
BsGain_Theta_BS=repmat(BsGainPattern,[NumLinks S]);
end
if numel(MsGainPattern)>1
MsGain_Theta_MS= feval(InterpFunction,squeeze(MsGainPattern(:,1,1,:)),MsGainAnglesAz,ThetaMs(:), InterpMethod); % V only
MsGain_Theta_MS= MsGain_Theta_MS.'; % size()= [NumLinks U]
else
MsGain_Theta_MS= repmat(MsGainPattern,[NumLinks U]);
end
else
% Set dummy values in case LOS option is not used
BsGain_Theta_BS=NaN;
MsGain_Theta_MS=NaN;
end
% CHANNEL MATRIX GENERATION
[H delta_t FinalPhases FinalPhases_LOS] = scm_core( scmpar,...
linkpar,...
antpar,...
bulkpar,...
BsGainPatternInterpolated,...
BsGain_Theta_BS,... % gain of LOS path
MsGainPatternInterpolated,...
MsGain_Theta_MS,... % gain of LOS path
0,... % offset time (not used typically)
BsGainIsScalar,...
MsGainIsScalar);
% final phases
bulkpar.subpath_phases=FinalPhases;
% time sampling grid
bulkpar.delta_t=delta_t;
% If path loss and shadowing are to be multiplied into the output
if ( (strcmpi(PathLossModelUsed,'yes')==1) || strcmpi(ShadowingModelUsed,'yes')==1 )
if (size(H,5)==1) % only one link
if (strcmpi(PathLossModelUsed,'yes')==1)
H=sqrt(bulkpar.path_losses).*H; % path loss in linear scale
end
if (strcmpi(ShadowingModelUsed,'yes')==1)
H=H*sqrt(bulkpar.shadow_fading); % shadow fading in linear scale
end
else % if more than one link
siz_H=size(H);
Hmat=reshape(H,prod(siz_H(1:end-1)),siz_H(end)); % a matrix with NumLinks cols
if (strcmpi(PathLossModelUsed,'yes')==1)
pl_mat=diag(sparse(sqrt(bulkpar.path_losses)));
Hmat=Hmat*pl_mat; % multiply path loss into each link
end
if (strcmpi(ShadowingModelUsed,'yes')==1)
sf_mat=diag(sparse(sqrt(bulkpar.shadow_fading))); % shadow fading is in linear scale
Hmat=Hmat*sf_mat; % multiply shadow fading into each link
end
H=reshape(Hmat,siz_H); % put back to original size
end
end
% GENERATE OUTPUT
no=nargout;
if (no>1)
delays=bulkpar.delays;
end
if (no>2)
switch lower(ScmOptions)
case {'none','urban_canyon','polarized'}
full_output=bulkpar;
case ('los')
bulkpar.Phi_LOS=FinalPhases_LOS;
full_output=bulkpar;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A function that maps inputs from (-inf,inf) to (-180,180)
function y=prin_value(x)
y=mod(x,360);
y=y-360*floor(y/180);
% %%%%%%%%%%%%%%%%
% %%%%%%%%%%%
% %%%%%%%%
% %%%%% That's all folks !!!
% %%
% %
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -