%% Scramble Two Codewords Using PDSCH PRBS
% Scramble the contents of two codewords using the PDSCH scrambling sequence. When transmitting multiple codewords via spatial multiplexing, each codeword uses a different scrambling sequence.
% Create cell-wide configuration structure for reference channel R.14, get PDSCH indices.

rmc.RC = 'R.14';
rmc = lteRMCDL(rmc,2);
pdsch = rmc.PDSCH;
[~,pdschInfo] = ltePDSCHIndices(rmc,pdsch,pdsch.PRBSet);
codedTrBlkSize1 = pdschInfo.G(1);
codedTrBlkSize2 = pdschInfo.G(2);
cws{1} = randi([0 1],codedTrBlkSize1,1);
cws{2} = randi([0 1],codedTrBlkSize2,1);

%
% Generate PDSCH scrambling sequences for two codewords, and scramble the codewords using the PDSCH scrambling sequences.

RNTI = 11;
ncw = 0;
pdschPrbsSeq1 = ltePDSCHPRBS(rmc,RNTI,ncw,length(cws{1}));
ncw = 1;
pdschPrbsSeq2 = ltePDSCHPRBS(rmc,RNTI,ncw,length(cws{2}));
scrambled1 = xor(pdschPrbsSeq1, cws{1});
scrambled2 = xor(pdschPrbsSeq2, cws{2});

% Copyright 2012 The MathWorks, Inc.