%% Generate PDCCH DM-RS Symbols for All Candidates and Aggregation Levels
% Configure the carrier with default configuration parameters.

carrier = nrCarrierConfig;

% Configure the CORESET with 6 frequency resources, a duration of 3 OFDM symbols, and a REG bundle size of 3.

crst = nrCORESETConfig;
crst.FrequencyResources = ones(1,6);
crst.Duration = 3;
crst.REGBundleSize = 3;

% 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 = 6;
pdcch.NSizeBWP = 36;
pdcch.CORESET = crst;
pdcch.SearchSpace = cfgSS;

% Generate PDCCH DM-RS symbols for all candidates and aggregation levels.

[~,allDMRS] = nrPDCCHSpace(carrier,pdcch)

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

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

% Copyright 2019 The MathWorks, Inc.