%% Descramble PSSCH Codeword
% Descramble a received PSSCH codeword.
%% Scramble PSSCH Codeword
% Create a UE settings structure with required fields.
% Generate the required length of the PRBS.
% Scramble the PSSCH codeword with the PRBS sequence using xor.
% Modulate the logical scrambled data.

ue = struct('NSAID',255,'NSubframePSSCH',0);

codeword = ones(1152,1);
psschPrbs = ltePSSCHPRBS(ue,length(codeword));

scrambled = xor(psschPrbs,codeword);

txsym = lteSymbolModulate(scrambled,'16QAM');

%
%% Descramble Recovered Codeword
% Add noise to transmitted symbols and demodulate received soft data.
% Generate the PSSCH PRBS in signed form.
% Descramble the vector representing a sequence of soft bits by generating the PSSCH PRBS in signed form and performing a pointwise multiplication between the PRBS sequence and the recovered soft data.
% Compare the transmitted codeword to the recovered codeword.

sym = awgn(txsym,30,'measured');
softdata = lteSymbolDemodulate(sym,'16QAM');

scramblingSeq = ltePSSCHPRBS(ue,length(softdata),'signed');
descrambled = softdata.*scramblingSeq;

isequal(codeword,descrambled > 0)

% The transmitted codeword matches the hard decision on the descrambled data.
% Copyright 2012 The MathWorks, Inc.