%% Perform PUSCH Descrambling
% Create a random sequence of binary values corresponding to a codeword containing 3000 bits. Perform PUSCH scrambling initialized with the specified physical layer cell identity number and RNTI.

cw = randi([0 1],3000,1);
ncellid = 42;
rnti = 101;
scrambled = nrPUSCHScramble(cw,ncellid,rnti);

% Modulate the scrambled data using 16-QAM modulation. Demodulate the result.

modulation = '16QAM';
sym = nrSymbolModulate(scrambled,modulation);
demod = nrSymbolDemodulate(sym,modulation);

% Perform PUSCH descrambling of the demodulated symbols.

descrambled = nrPUSCHDescramble(demod,ncellid,rnti)

% Perform hard decision on the soft metric.

rxcw = double(descrambled<0)

% Compare the result with the original codeword.

isequal(cw,rxcw)

% Copyright 2018 The MathWorks, Inc.