rng('default'); % Initialize the random number generator stream
NeNodeB = 5; % Number of eNodeB
% Create eNodeB configurations
enb = cell(1,NeNodeB);
for i=1:NeNodeB
enb{i}=lteRMCDL('R.5'); % Get configuration based on RMC,选R7正好合适。
enb{i}.NCellID = mod((i-1)*2,504); % Set arbitrary cell identity
enb{i}.TotSubframes = 1; % Number of subframes to generate
enb{i}.NPRSRB = 2; % Bandwidth of PRS in resource blocks
enb{i}.IPRS = 0; % PRS configuration index
enb{i}.PRSPeriod = 'On'; % PRS present in all subframes
enb{i}.Position = hPositioningPosition(i-1, NeNodeB); % eNodeB position
end
% Use the first eNodeB configuration for general settings
info = lteOFDMInfo(enb{1});
% Plot Location of eNodeBs and UE
% The positions of the eNodeBs and the UE are plotted for reference. The UE lies at
% (0,0) and the eNodeBs are distributed around the UE.
hPositioningPlotPositions(enb);
% Generate Transmissions
% For each eNodeB, a transmission is made consisting of the PRS, Primary Synchronisation Signal (PSS),
% Secondary Synchronisation Signal (SSS) and Cell-specific Reference Signal (Cell RS).
% An empty resource grid is created and a PRS is generated and mapped onto the grid using ltePRS
% and ltePRSIndices. The PSS, SSS and Cell RS are added in a similar fashion. The resultant grid is
% OFDM modulated to produce a transmit waveform.
tx = cell(1,NeNodeB);
for i = 1:NeNodeB
grid = [];
for nsf = 0:19
enb{i}.NSubframe = mod(nsf,10);
sfgrid = lteDLResourceGrid(enb{i}); % Empty subframe
sfgrid(ltePRSIndices(enb{i})) = ltePRS(enb{i}); % PRS REs
sfgrid(ltePSSIndices(enb{i})) = ltePSS(enb{i}); % PSS REs
sfgrid(lteSSSIndices(enb{i})) = lteSSS(enb{i}); % SSS REs
sfgrid(lteCellRSIndices(enb{i})) = lteCellRS(enb{i}); % Cell RS REs
grid = [grid sfgrid]; %#ok
end
enb{i}.NSubframe = 0;
tx{i} = lteOFDMModulate(enb{i}, grid); % OFDM modulate
end
% Compute delays from eNodeBs to UEs
% Using the known eNodeB positions, the time delay from each eNodeB to the UE is calculated
% using the distance between the UE and eNodeB, radius, and the speed of propagation (speed of light).
% Using knowledge of the sampling rate, info.SamplingRate, the sample delay is calculated and stored in sampleDelay.
% These variables will be used to model the environment between the eNodeBs and the UE but the information will NOT be
% provided to the UE.
speedOfLight = 299792458.0; % Speed of light in m/s
sampleDelay = zeros(1, NeNodeB);
radius = cell(1, NeNodeB);
for i = 1:NeNodeB
[~, radius{i}] = cart2pol(enb{i}.Position(1), enb{i}.Position(2));
delay = radius{i}/speedOfLight; % Delay in seconds
sampleDelay(i) = round(delay*info.SamplingRate); % Delay in samples
end