%% Demodulate PSSCH Symbols
% Demodulate PSSCH symbols plus noise for an SL-SCH codeword created by encoding a vector of information bits. Plot the noisy RE symbols, the symbols prior to QPSK demodulation, and the resulting LLR soft bits.
%% Create a UE settings structure
% Specify normal cyclic prefix and 16-QAM modulation.

ue = struct('CyclicPrefixSL','Normal');
ue.RV = 0;
ue.Modulation = '16QAM';
ue.NSAID = 255;
ue.NSubframePSSCH = 0;

%
%% Generate symbols to recover
% Specify the codeword length to use for the SL-SCH. Choose a length that is a multiple of 12 symbols for normal cyclic prefix and has 4 bits per symbol for 16-QAM modulation. Pick a standard number of resource blocks, such as 10.
% Create the SL-SCH codeword.
% Create the PSSCH symbols and add noise.

codewordlength = 5760; % (12 symbols)(4 bps)(12 REperRB)(10 PRB)
cw = lteSLSCH(ue,codewordlength,ones(100,1));

sym = ltePSSCH(ue,cw);
rxsym = sym + 0.1*randn(size(sym));

%
%% Decode received PSSCH symbols
% Recover the soft bits representing the transmitted SL-SCH codeword. Compare the soft bits to the transmitted codeword.

[rxcw,rxmodsym] = ltePSSCHDecode(ue,rxsym);
isequal(cw,rxcw>0)

% Using a random noise seed and the level of noise added sometimes results in decoding errors. If the comparison returns '1' there were no decoding errors. If the comparison returns '0' there were decoding errors.
%
% Plot the received and recovered signals.

subplot(2,2,1)
plot(rxsym,'o')
title('PSSCH Encoded Symbols + Noise')

subplot(2,2,2)
plot(rxmodsym,'o')
title('Decoded Symbols')

subplot(2,2,[3,4])
plot(rxcw)
title('Decoded Soft Bits')

% Copyright 2012 The MathWorks, Inc.