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
%%%% It is important to note that for the example of 9.7.5 of Proakis 2002
%%%% on page 633, in order to obtain correct result, settings must be tblen = 5, and 'term' 
Decode = vitdec(Code,t,tblen,'term','hard');% Perform decoding
Message
Code
Decode