MATLAB Examples

Downlink Carrier Waveform Generation

This example implements a 5G NR downlink carrier waveform generator using 5G Toolbox™.



This example shows how to parameterize and generate a 5G New Radio (NR) downlink waveform. The following channels and signals are generated;

  • PDSCH and its associated DM-RS
  • PDCCH and its associated DM-RS
  • PBCH and its associated DM-RS
  • PSS and SSS

This example supports the parameterization and generation of multiple bandwidth parts (BWP). Multiple instances of the PDSCH and PDCCH channels can be generated over the different BWPs. Multiple CORESETs and search space configurations can be set for mapping the PDCCHs. Note that no precoding is applied to the physical channels and signals in this example.

Carrier Configuration

This section sets the overall carrier bandwidth in resource blocks, the cell ID, and the length of the generated waveform in subframes. You can visualize the generated resource grids by setting the DisplayGrids field to 1.

carrier = [];
carrier.NDLRB = 200;        % Carrier width in 15kHz numerology
carrier.NCellID = 0;        % Cell identity
carrier.NumSubframes = 10;  % Number of 1ms subframes in generated waveform (1,2,4,8 slots per 1ms subframe, depending on SCS)
carrier.DisplayGrids = 1;   % Display the resource grids after signal generation

SS Burst

In this section you can set the parameters for the SS burst. The numerology of the SS burst can be different from other parts of the waveform. This is specified via the block pattern parameter as specified in TS38.213 Section 4.1. A bitmap is used to specify which blocks are transmitted in a 5ms half-frame burst. The periodicity in milliseconds and the power of the burst can also be set here. Other SS burst parameters not shown here can also be set. For the full list see the help for hSSBurst.

% SS burst configuration
ssburst = [];
ssburst.BlockPattern = 'Case B';        % Case B (30kHz) subcarrier spacing
ssburst.SSBTransmitted = [1 1 1 1];     % Bitmap indicating blocks transmitted in a 5ms half-frame burst
ssburst.SSBPeriodicity = 20;            % SS burst set periodicity in ms (5, 10, 20, 40, 80, 160)
ssburst.Power = 0;                      % Power scaling in dB

Bandwidth Parts

A BWP is formed by a set of contiguous resources sharing a numerology on a given carrier. This example supports the use of multiple BWPs using a struct array. Each entry in the array represents a BWP. Each BWP can have different subcarrier spacings (SCS), use different cyclic prefix (CP) lengths and span different bandwidths. The RBOffset parameter controls the location of the BWP in the carrier. This is expressed in terms of the BWP numerology. Different BWPs can overlap with each other.

% Bandwidth parts configurations
bwp = [];

bwp(1).SubcarrierSpacing = 15;          % BWP Subcarrier Spacing
bwp(1).CyclicPrefix = 'Normal';         % BWP Cyclic prefix for 15 kHz
bwp(1).NRB = 25;                        % Size of BWP
bwp(1).RBOffset = 10;                   % Position of BWP in carrier

bwp(2).SubcarrierSpacing = 30;          % BWP Subcarrier Spacing
bwp(2).CyclicPrefix = 'Normal';         % BWP Cyclic prefix for 30 kHz
bwp(2).NRB = 50;                        % Size of BWP
bwp(2).RBOffset = 50;                   % Position of BWP in carrier

CORESET and Search Space Configuration

The parameters in this section specify the control resource set (CORESET) and the PDCCH search space configuration. The CORESET specifies the possible locations (in time and frequency) of the control channel for a given numerology. This example supports multiple CORESETs. The following parameters can be specified:

  • Allocated OFDM symbols: specifies the first symbol of each CORESET monitoring opportunity in a slot
  • The allocated slots within a period
  • Periodicity of the allocation. If this is set to empty it indicates no repetition
  • CORESET duration in symbols, either 1, 2 or 3.
  • The first PRB of the allocation. Note that the allocation is in blocks of 6 PRBs.

Note that this example only supports non-interleaved CCE-to-REG mapped CORESETs.

The figure below shows the meaning of the CORESET parameters.

% CORESET/search configurations
coreset = [];
coreset(1).AllocatedSymbols = [0,7];    % First symbol of each CORESET monitoring opportunity in a slot
coreset(1).AllocatedSlots = [0,1];      % Allocated slots within a period
coreset(1).AllocatedPeriod = 5;         % Allocated slot period (empty implies no repetition)
coreset(1).Duration = 3;                % CORESET symbol duration (1,2,3)
coreset(1).AllocatedPRB = 6*[0,1,3];    % 6 REG sized indices, (RRC - frequencyAllocation)

PDCCH Instances Configuration

This section specifies the parameters for the different PDCCH instances. Each entry in the struct array defines an instance of the PDCCH. The following parameters can be set:

  • Enable/disable the PDCCH instance
  • Specify the BWP the PDCCH instance refers to
  • PDCCH instance power in dB
  • Allocated search spaces: indices within the corresponding CORESET where to map the PDCCH
  • CORESET which carries the PDCCH instance
  • Periodicity of the allocation. If this is set to empty it indicates no repetition
  • Number of control channel elements (CCEs) in this PDCCH
  • NumCCE and StartCCE specify the elements used for the transmission of this PDCCH
  • RNTI
  • Scrambling NID for this PDCCH and its associated DM-RS
  • DM-RS power boosting
  • DCI message payload size
  • DCI message data source. You can use one of the following standard PN sequences: 'PN9-ITU', 'PN9', 'PN11', 'PN15', 'PN23'. The seed for the generator can be specified using a cell array in the form {'PN9',seed}. If no seed is specified, the generator is initialised with all ones
pdcch = [];
pdcch(1).Enable = 1;                    % Enable PDCCH config
pdcch(1).BWP = 1;                       % Bandwidth part
pdcch(1).Power = 1.1;                   % Power scaling in dB
pdcch(1).AllocatedSearchSpaces = [0,1]; % Index within the CORESET
pdcch(1).CORESET = 1;                   % Control resource set ID which carries this PDCCH
pdcch(1).AllocatedPeriod = [4];         % Allocation slot period (empty implies no repetition)
pdcch(1).NumCCE = 30;                   % Number of CCE (in PRBs) in PDCCH
pdcch(1).StartCCE = 10;                 % Starting CCE of PDCCH
pdcch(1).RNTI = 0;                      % RNTI
pdcch(1).NID = 1;                       % PDCCH and DM-RS scrambling NID
pdcch(1).PowerDMRS = 0;                 % Additional power boosting in dB
pdcch(1).DataBlkSize = 20;              % DCI payload size
pdcch(1).DataSource = 'PN9';            % DCI data source

PDSCH Instances Configuration

This section specifies PDSCH instances using a struct array. This example sets two PDSCH instances.

General Parameters

The following parameters are set for each instance:

  • Enable/disable this PDSCH instance
  • Specify the BWP this PDSCH maps to. The PDSCH will use the SCS specified for this BWP
  • Power scaling in dB
  • Transport block data source. You can use one of the following standard PN sequences: 'PN9-ITU', 'PN9', 'PN11', 'PN15', 'PN23'. The seed for the generator can be specified using a cell array in the form {'PN9', seed}. If no seed is specified, the generator is initialised with all ones
  • Target code rate used to calculate the transport block sizes
  • Overhead parameter
  • Symbol modulation
  • Number of layers
  • Redundancy version (RV) sequence
pdsch = [];
pdsch(1).Enable = 1;                    % Enable PDSCH config
pdsch(1).BWP = 1;                       % Bandwidth part
pdsch(1).Power = 0;                     % Power scaling in dB
pdsch(1).DataSource = 'PN9';            % Transport block data source
pdsch(1).TargetCodeRate = 0.4785;       % Code rate used to calculate transport block sizes
pdsch(1).Xoh_PDSCH = 0;                 % Overhead
pdsch(1).Modulation = 'QPSK';           % 'QPSK', '16QAM', '64QAM', '256QAM'
pdsch(1).NLayers = 2;                   % Number of PDSCH layers
pdsch(1).RVSequence = [0,1,2,3];        % RV sequence to be applied cyclically across the PDSCH allocation sequence


The following diagram represents some of the parameters used in the PDSCH allocation.

You can set the following parameters to control the PDSCH allocation. Note that these parameters are relative to the BWP. The specified PDSCH allocation will avoid the locations used for the SS burst.

  • Symbols in a slot where the PDSCH is mapped to. It does not need to be a contiguous allocation
  • Slots in a frame used for the PDSCH
  • Period of the allocation in slots. If this is empty it indicates no repetition
  • The allocated PRBs are relative to the BWP
  • RNTI. This value is used to links the PDSCH to an instance of the PDCCH
  • NID for scrambling the PDSCH bits
pdsch(1).AllocatedSymbols = [2:10];     % Range of symbols in a slot
pdsch(1).AllocatedSlots = [0:9];        % Allocated slots indices
pdsch(1).AllocatedPeriod = 15;          % Allocation period in slots (empty implies no repetition)
pdsch(1).AllocatedPRB = [0:5, 10:20];   % PRB allocation
pdsch(1).RNTI = 0;                      % RNTI
pdsch(1).NID = 1;                       % Scrambling for data part

The generator in this example does not check for inter-channel conflict. However, additional parameters can be specified for rate matching around other allocations

  • The PDSCH can be rate matched around several CORESETs
  • The PDSCH can be rate matched around other PDSCH allocations
pdsch(1).RateMatch(1).CORESET = [1];                  % Rate matching pattern, defined by one CORESET
pdsch(1).RateMatch(1).Pattern.AllocatedPRB = [];      % Rate matching pattern, defined by set of 'bitmaps'
pdsch(1).RateMatch(1).Pattern.AllocatedSymbols = [];
pdsch(1).RateMatch(1).Pattern.AllocatedSlots = [];
pdsch(1).RateMatch(1).Pattern.AllocatedPeriod = [];

DM-RS Configuration

The following DM-RS parameters can be set

% DM-RS configuration (TS 38.211 section
pdsch(1).PortSet = 0:pdsch(1).NLayers-1; % DM-RS ports to use for the layers
pdsch(1).PDSCHMappingType = 'A';       % PDSCH mapping type ('A'(slot-wise),'B'(non slot-wise))
pdsch(1).DL_DMRS_typeA_pos = 2;        % Mapping type A only. First DM-RS symbol position (2,3)
pdsch(1).DL_DMRS_max_len = 1;          % Number of front-loaded DM-RS symbols (1(single symbol),2(double symbol))
pdsch(1).DL_DMRS_add_pos = 0;          % Additional DM-RS symbol positions (max range 0...3)
pdsch(1).DL_DMRS_config_type = 2;      % DM-RS configuration type (1,2)
pdsch(1).NIDNSCID = 1;                 % Scrambling identity (0...65535)
pdsch(1).NSCID = 0;                    % Scrambling initialisation (0,1)
pdsch(1).PowerDMRS = 0;                % Additional power boosting in dB

Specifying Multiple PDSCH Instances

A second PDSCH instance is specified next using the second BWP.

pdsch(2) = pdsch(1);
pdsch(2).Enable = 1;
pdsch(2).BWP = 2;                           % PDSCH mapped to 2nd BWP
pdsch(2).AllocatedSymbols = [0:11];
pdsch(2).AllocatedSlots = [2:4,6:20];
pdsch(2).AllocatedPRB = [25:30, 35:38];     % PRB allocation

Waveform Generation

This section collects all the parameters into the carrier configuration and generates the waveform.

% Collect together channel oriented parameter sets into a single
% configuration
carrier.SSBurst = ssburst;
carrier.BWP = bwp;
carrier.CORESET = coreset;
carrier.PDCCH = pdcch;
carrier.PDSCH = pdsch;

% Generate complex baseband waveform
[waveform,bwpset] = hNRDownlinkWaveformGenerator(carrier);

The waveform generator also plots the resource grids for the bandwidth parts (this is controlled by the field DisplayGrids in the carrier configuration). The following plots are generated:

  • Resource grid showing the location of the components (PDCCH, PDSCH, and CORESET) in each BWP. This does not plot the power of the signals, just their location in the grid.
  • Generated waveform in the frequency domain for each BWP. This includes the PDCCH and PDSCH instances.

Note that none of these resource grids include the SS burst, this is independent of the BWPs.

The waveform generator function returns the time domain waveform and a struct array bwpset, which contains the following fields:

  • The resource grid corresponding to this BWP
  • The resource grid of the overall bandwidth containing the channels and signals in this BWP
  • An info structure with information corresponding to the BWP. The contents of this info structure for the first BWP are shown below.
disp('Information associated to BWP 1:')
Information associated to BWP 1:
           SamplingRate: 61440000
                   Nfft: 4096
              Windowing: 10
    CyclicPrefixLengths: [1x14 double]
          SymbolLengths: [1x14 double]
           NSubcarriers: 2400
      SubcarrierSpacing: 15
         SymbolsPerSlot: 14
       SlotsPerSubframe: 1
     SymbolsPerSubframe: 14
     SamplesPerSubframe: 61440
         SubframePeriod: 1.0000e-03
              Midpoints: [1x141 double]
          WindowOverlap: [10 10 10 10 10 10 10 10 10 10 10 10 10 10]

Note that the generated resource grid is a 3D matrix where the different planes represent the antenna ports. For the different physical channels and signals the lowest port is mapped to the first plane of the grid.