%% WINNER II Channel with Two Mobile Stations
% Simulate a system that has two MS connected to one BS. One MS is 8 meters away from the BS; the other is 20 meters away from the BS. Impulse signals are sent through the two links. The spectrum of the received signals at MS shows frequency selectivity. It also shows the MS that is closer the BS has a larger average received power than the other MS.
% Specify random number generator seed for repeatability.

rng(100);

%
% Initial frame length and sample rate.

frmLen   = 1024;

%
% Configure layout parameters.

BSAA  = winner2.AntennaArray('UCA', 8, 0.02);  % UCA-8 antenna array for BS
MSAA1 = winner2.AntennaArray('ULA', 2, 0.01);  % ULA-2 antenna array for MS
MSAA2 = winner2.AntennaArray('ULA', 4, 0.005); % ULA-4 antenna array for MS
MSIdx = [2 3]; BSIdx = {1}; NL = 2; maxRange = 100; rndSeed = 101;
cfgLayout = winner2.layoutparset(MSIdx,BSIdx,NL, ...
   [BSAA,MSAA1,MSAA2],maxRange,rndSeed);

%
% Adjust BS and MS positions.

cfgLayout.Stations(1).Pos(1:2) = [10, 10];
cfgLayout.Stations(2).Pos(1:2) = [18, 10];  % 8 meters away from BS
cfgLayout.Stations(3).Pos(1:2) = [22, 26];  % 20 meters away from BS

%
% NLOS for both links

cfgLayout.Pairing = [1 1; 2 3];
cfgLayout.PropagConditionVector = [0 0];

%
% Configure model parameters

cfgModel = winner2.wimparset;
cfgModel.NumTimeSamples     = frmLen; % Frame length
cfgModel.IntraClusterDsUsed = 'no';   % No cluster splitting
cfgModel.SampleDensity      = 2e5;    % For lower sample rate
cfgModel.PathLossModelUsed  = 'yes';  % Turn on path loss
cfgModel.ShadowingModelUsed = 'yes';  % Turn on shadowing

%
% Create a WINNER II channel System object.

wimChan = comm.WINNER2Channel(cfgModel, cfgLayout);

%
% Call the info method of the object to get some system information

chanInfo = info(wimChan)
numTx    = chanInfo.NumBSElements(1);
Rs       = chanInfo.SampleRate(1);

%
% Create a Spectrum Analyzer System object.

SA = dsp.SpectrumAnalyzer('SampleRate', Rs, ...
    'YLimits', [-170, -100], 'ShowLegend', true, ...
    'ChannelNames', {'MS 1 (8 meters away)','MS 2 (20 meters away)'});

%
% Pass impulse signals through the two links and show spectra of the received signals at the two MS.

for i = 1:10
    x = [ones(1,numTx); zeros(frmLen-1, numTx)];
    y = wimChan(x);
    SA([y{1}(:,1), y{2}(:,1)]);
end

%
% Copyright 2019 The MathWorks, Inc.