%% Configure and Generate Multiuser 5G Downlink Waveform
% Create two SCS carrier configuration objects with mixed numerologies and custom numbers of resource blocks.

carriers = {
    nrSCSCarrierConfig('SubcarrierSpacing',15,'NStartGrid',10,'NSizeGrid',100), ...
    nrSCSCarrierConfig('SubcarrierSpacing',30,'NStartGrid',0,'NSizeGrid',70)};
    

% Create two custom BWP configuration objects, one for each of the carriers.

bwp = {
    nrWavegenBWPConfig('BandwidthPartID',1,'SubcarrierSpacing',15,'NStartBWP',10,'NSizeBWP',80), ...
    nrWavegenBWPConfig('BandwidthPartID',2,'SubcarrierSpacing',30,'NStartBWP',0,'NSizeBWP',60)};

% Create an SS burst configuration object with block pattern Case A, corresponding to an SCS of 15 kHz.

ssb = nrWavegenSSBurstConfig('BlockPattern','Case A');

% Create two PDCCH configuration objects.

pdcch = {
    nrWavegenPDCCHConfig('SearchSpaceID',1,'BandwidthPartID',1,'RNTI',1,'DMRSScramblingID',1), ...
    nrWavegenPDCCHConfig('SearchSpaceID',2,'BandwidthPartID',2,'RNTI',2,'DMRSScramblingID',2, ...
        'AggregationLevel',4)};
    

% Create two CORESET configuration objects and two search space set configuration objects for the two PDCCH.

coreset = {
    nrCORESETConfig('CORESETID',1,'FrequencyResources',[1 1 1 1 1 0 0 0 0 0 1],'Duration',3), ...
    nrCORESETConfig('CORESETID',2,'FrequencyResources',[0 0 0 0 0 0 0 0 1 1])};

ss = {
    nrSearchSpaceConfig('SearchSpaceID',1,'CORESETID',1,'StartSymbolWithinSlot',4), ...
    nrSearchSpaceConfig('SearchSpaceID',2,'CORESETID',2,'NumCandidates',[8 8 4 0 0])};

% Create two PDSCH configuration objects with mixed modulation schemes.

pdsch = {
    nrWavegenPDSCHConfig('BandwidthPartID',1,'Modulation','16QAM','RNTI',1,'NID',1), ...
    nrWavegenPDSCHConfig('BandwidthPartID',2,'Modulation','QPSK','RNTI',2,'NID',2, ...
            'PRBSet', 50:59)};

% Create two CSI-RS configuration objects.

 csirs = {
     nrWavegenCSIRSConfig('BandwidthPartID',1,'RowNumber',2,'RBOffset',10), ... 
     nrWavegenCSIRSConfig('BandwidthPartID',2,'Density','three','RowNumber',4)};

% Create a multiuser 5G downlink waveform configuration object, specifying the previously defined configurations.

cfgDL = nrDLCarrierConfig( ...
    'FrequencyRange','FR1', ...
    'ChannelBandwidth',40, ...
    'NumSubframes',20, ...
    'SCSCarriers',carriers, ...
    'BandwidthParts',bwp, ...
    'SSBurst',ssb, ...
    'CORESET',coreset, ...
    'SearchSpaces',ss, ...
    'PDCCH',pdcch, ...
    'PDSCH',pdsch, ...
    'CSIRS',csirs);

% Generate a 5G downlink waveform using the specified configuration.

waveform = nrWaveformGenerator(cfgDL);

% Copyright 2020 The MathWorks, Inc.