%% Turbo Decode Input Data
% Perform turbo decoding of soft bits obtained from a noisy constellation.
% Create a bit stream, turbo encode the bit stream, and modulate it. Create noise, add it to the modulated symbols. Display the transmitted and received symbols on a scatter plot.

txBits = randi([0 1],6144,1);
codedData = lteTurboEncode(txBits);
txSymbols = lteSymbolModulate(codedData,'QPSK');
noise = 0.5*complex(randn(size(txSymbols)),randn(size(txSymbols)));
rxSymbols = txSymbols + noise;

scatter(real(rxSymbols),imag(rxSymbols),'co'); 
hold on;

scatter(real(txSymbols),imag(txSymbols),'rx')
legend('Rx constellation','Tx constellation')

%
% Demodulate the symbols and turbo decode soft bits. Compare the transmitted and recovered bits.

softBits = lteSymbolDemodulate(rxSymbols,'QPSK','Soft');
rxBits = lteTurboDecode(softBits);
numberErrors = sum(rxBits ~= int8(txBits))

% Copyright 2012 The MathWorks, Inc.