Plug Custom Channel into Wireless Network Simulator
This example shows you how to plug a custom channel into the wireless network simulator by using 5G Toolbox™ and the Communications Toolbox™ Wireless Network Simulation Library.
Using this example, you can:
Create and configure a 5G network with new radio (NR) base station (gNB) and user equipment (UE) nodes.
Establish a connection between the gNB and UE nodes.
Create a custom channel, and plug it into the wireless network simulator.
Simulate a 5G network, and retrieve the statistics of the gNB and UE nodes.
Check if the Communications Toolbox Wireless Network Simulation Library support package is installed. If the support package is not installed, MATLAB® returns an error with a link to download and install the support package.
wirelessnetworkSupportPackageCheck
Create a wireless network simulator.
networkSimulator = wirelessNetworkSimulator.init;
Create a gNB node with these specifications.
Position —
Channel bandwidth — 20 MHz
Subcarrier spacing — 30 KHz
Duplex mode — Time division duplex
gnb = nrGNB(Position=[-100 100 0],ChannelBandwidth=20e6,DuplexMode="TDD",SubcarrierSpacing=30e3);
Create two UE nodes, specifying their positions in Cartesian coordinates.
ue = nrUE(Position=[100 100 0; 5000 100 0]); % In Cartesian x, y, and z coordinates.
Configure a scheduler at the gNB with a maximum number of two users per transmission time interval (TTI).
configureScheduler(gnb,MaxNumUsersPerTTI=2)
Connect the UE nodes to the gNB node and enable full-buffer traffic.
connectUE(gnb,ue,FullBufferTraffic="on")
Add the nodes to the network simulator.
addNodes(networkSimulator,gnb) addNodes(networkSimulator,ue)
Add the custom channel to the wireless network simulator.
addChannelModel(networkSimulator,@addImpairment);
Specify the simulation time in seconds.
simulationTime = 0.05;
Run the simulation for the specified simulation time.
run(networkSimulator,simulationTime)
Obtain the statistics for the gNB and UE nodes.
gnbStats = statistics(gnb); ueStats = statistics(ue);
Follow these steps to create a custom channel that models NR path loss for an urban macrocell scenario.
Create a custom function with this syntax:
rxData = customFcnName(rxInfo,txData)
. TherxInfo
input (a structure) is the receiver node information, and thetxData
input (a structure) specifies the transmitted packets. The simulator automatically passes information about the receiver node and the packets transmitted by a transmitter node as inputs to the custom function. For more information about this, see theaddChannelModel
object function.Use the
nrPathLossConfig
(5G Toolbox) object to set path loss configuration parameters for an urban macrocell scenario.Calculate path loss between the base station and UE nodes using the
nrPathLoss
(5G Toolbox) function. Specify carrier frequency, line of sight (LOS) between the gNB and UE nodes, and the transmitter and receiver positions.Apply path loss to the transmitted packets.
function outputData = addImpairment(rxInfo,txData) % Set path loss configuration parameters pathLossConfig = nrPathLossConfig; pathLossConfig.Scenario = "UMa"; % Urban macrocell pathLossConfig.EnvironmentHeight = 1; % Average height of the environment in UMa/UMi los = 1; % Assume LOS between the gNB and UE nodes outputData = txData; % Calculate path loss pathLoss = nrPathLoss(pathLossConfig,txData.CenterFrequency,los, ... txData.TransmitterPosition',rxInfo.Position'); outputData.Power = outputData.Power - pathLoss; % Set default values for channel parameters outputData.Metadata.Channel.PathGains = ... permute(ones(outputData.NumTransmitAntennas,rxInfo.NumReceiveAntennas),[3 4 1 2])/ ... sqrt(rxInfo.NumReceiveAntennas); outputData.Metadata.Channel.PathFilters = 1; outputData.Metadata.Channel.SampleTimes = 0; if outputData.Abstraction == 0 % Full physical layer processing outputData.Data = outputData.Data.*db2mag(-pathLoss); numTxAnts = outputData.NumTransmitAntennas; numRxAnts = rxInfo.NumReceiveAntennas; H = fft(eye(max([numTxAnts numRxAnts]))); H = H(1:numTxAnts,1:numRxAnts); H = H/norm(H); outputData.Data = txData.Data*H; % Apply channel to the waveform end end