This example shows how to process a binary data stream by using a communications link that consists of a baseband modulator, channel, demodulator, pulse shaping, raised cosine filtering, and error correction.
Establish Simulation Framework
In this example, to achieve a more accurate BER estimate, the number of bits to process is increased from the value used in the
Use Pulse Shaping on 16-QAM Signal
example. Other simulation variables match the settings in that example.
Define simulation parameters for a 16-QAM modulation scheme with raised cosine filtering and an AWGN channel.
Generate Random Data
Set the
rng
function to its default state, or any static seed value, so that the example produces repeatable results. Then, use the
randi
function to generate random binary data.
Apply Convolutional Encoding
To correct errors arising from the noisy channel, apply convolutional coding to the data before transmission and Viterbi decoding to the received data. The decoder uses a hard decision algorithm, which means each received data bit is interpreted as either
0
or
1
.
Define a convolutional coding trellis for a rate 2/3 code by using the
poly2trellis
function. The defined trellis represents the convolutional code that the
convenc
function uses for encoding the binary vector,
dataIn
.
genpoly = 2×3
23 35 0
0 5 13
Encode the input data by using the
tPoly
trellis.
Modulate Data
Use the
bit2int
function to convert the
k
-tuple encoded binary data to an integer values.
Use the
qammod
function to apply 16-QAM modulation.
Apply Raised Cosine Filtering
Use the
rcosdesign
function to create an RRC filter.
Use the
upfirdn
function to upsample the signal by the oversampling factor and apply the RRC filter. The
upfirdn
function pads the upsampled signal with zeros at the end to flush the filter. Then, the function applies the filter.
Apply AWGN Channel
Use the bits per symbol, samples per symbol, code rate, and the
convertSNR
function to convert the ratio of energy per bit to noise power spectral density (
EbNo
) to an SNR value for use by the
awgn
function. When converting the
to SNR, you must account for the number of information bits per symbol. With no FEC applied, each symbol corresponded to
k
bits. With FEC applied, each symbol corresponds to (
k
codeRate
) information bits. For the 2/3 code rate and 16-QAM transmissions used in this example, three symbols correspond to 12 coded bits and 8 uncoded (information) bits.
Pass the filtered signal through an AWGN channel.
Receive and Demodulate Signal
Filter the received signal by using the RRC filter. Remove a portion of the signal to account for the filter delay.
Use the
qamdemod
function to demodulate the received filtered signal.
Apply Viterbi Decoding
Use the
int2bit
function to convert the recovered integer symbols into binary data.
Use the
vitdec
function, configured for hard decisions and continuous operation mode, to decode the convolutionally encoded data. The continuous operation mode maintains the internal state when the decoder is repeatedly invoked, such as when receiving frames of data operating in a loop. The continuous operation mode also adds delay to the system. Although this example does not use a loop, the '
cont
' mode is used for the purpose of illustrating how to compensate for the delay in this decoding operation.
Compute System BER
The delay introduced by the transmit and receive RRC filters is already accounted for in the recovered data, but the decoder delay is not accounted for yet. The continuous operation mode of the Viterbi decoder incurs a delay with a duration in bits equal to the traceback length,
traceBack
, times the number of input streams at the encoder. For the 2/3 code rate used in this example, the encoder has two input streams, so the delay is 2×
traceBack
bits. As a result, the first 2×
traceBack
bits in the decoded vector,
dataOut
, are zeros. When computing the BER, discard the first 2×
traceBack
bits in
dataOut
and the last 2×
traceBack
bits in the original vector,
dataIn
.
Use the
biterr
function to compute the number of errors and the BER by comparing
dataIn
and
dataOut
. For the same
of 10 dB, less errors occur when FEC is included in the processing chain.
The bit error rate is 4.30e-05, based on 43 errors.
More About Delays
The decoding operation in this example incurs a delay that causes the output of the decoder to lag the input. Timing information does not appear explicitly in the example, and the length of the delay depends on the specific operations being performed. Delays occur in various communications system operations, including convolutional decoding, convolutional interleaving and deinterleaving, equalization, and filtering. To find out the duration of the delay caused by specific functions or operations, see the specific documentation for those functions or operations. For more information on delays, see
Delays of Convolutional Interleavers
and
Fading Channels
.