echo off;clear;clc
Message = [1 1 0 1 0 1 1 0 0];
% Define trellis based on the convolutional encode given in Fig. 9.25 of Proakis 2002 where rate is 1 / 2
% The constraint length is 3, generator polynomials for the two adders are [1 0 1] and [1 1 1], their octal
% equivalence is [5 7]. Note that the way that shift registers are shown in
% MATLAB is different from the notation of Proakis and Sklar with first
% shift register in MATLAB missing.
t = poly2trellis(3,[5 7]);
Code = convenc(Message,t); % Encode the data according to t
tblen = 5;% Traceback depth
Decode = vitdec(Code,t,tblen,'trunc','hard');% Perform decoding
Message
Code
Decode
% Part B : Decoding any given code word
Codeword = [0 1 1 0 1 1 1 1 0 1 0 0 0 1];
Message = vitdec(Codeword,t,tblen,'term','hard');% Perform decoding
disp('Code word and Message')
Codeword
Message