%% Generate PDCCH DM-RS Indices for All Candidates and Aggregation Levels
% Configure a carrier grid of 60 resource blocks (RBs), where the starting RB index relative to the common resource block 0 (CRB 0) is 3.

carrier = nrCarrierConfig;
carrier.NStartGrid = 3;
carrier.NSizeGrid = 60;

% Configure noninterleaved CORESET with 6 frequency resources and a duration of 3 OFDM symbols.

crst = nrCORESETConfig;
crst.FrequencyResources = ones(1,6);
crst.Duration = 3;
crst.CCEREGMapping = 'noninterleaved';

% Configure the search space set for the PDCCH with the specified number of candidates at each aggregation level.

cfgSS = nrSearchSpaceConfig;
cfgSS.NumCandidates = [5 5 3 2 1];

% Configure the PDCCH with the specified bandwidth part, CORESET, and search space set.

pdcch = nrPDCCHConfig;
pdcch.NStartBWP = 5;
pdcch.NSizeBWP = 48;
pdcch.CORESET = crst;
pdcch.SearchSpace = cfgSS;

% Generate PDCCH DM-RS resource element indices for all candidates and aggregation levels using 1-based, subscript indexing form relative to the BWP grid.

[~,~,allDMRSInd] = nrPDCCHSpace(carrier,pdcch, ...
    'IndexOrientation','bwp','IndexStyle','subscript')

% Verify that the number of generated candidates for PDCCH DM-RS indices at each aggregation level matches the number of candidates specified by the search space set.

numCandidates = [...
    size(allDMRSInd{1},3) ... 
    size(allDMRSInd{2},3) ... 
    size(allDMRSInd{3},3) ... 
    size(allDMRSInd{4},3) ... 
    size(allDMRSInd{5},3)];
isequaln(cfgSS.NumCandidates,numCandidates)

% Copyright 2019 The MathWorks, Inc.