Matlab Code For RS Coding and Decoding
Matlab Code For RS Coding and Decoding
[dec,cnumerr] = rsdec(received,n,k)
% print the original message for comparison
msg
% Given below is the output of the program. Only decoded message,
cnumerr and original
% message are given here (with comments inline)
% The default primitive polynomial over which the GF is defined is
D^3+D+1 ( which is 1011 -> 11 in decimal).
dec = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
523
017
667
cnumerr =
2
2
-1 ->>> Error in last row -> this error is due to the fact that we have
added 3 distributed errors with the last row where as the RS code
can correct only 2 errors. Compare the decoded message with
original message given below for confirmation
clear;
%____________________________________________
%Input Parameters
%____________________________________________
%Interleaver Design for Reed-Solomon Codes
%RS code parameters
n=255; %RS codeword length
k=235; %Number of data symbols
b=20; %Number of symbols that is expected to be corrupted by the channel
%____________________________________________
data='THE_QUICK_BROWN_FOX_JUMPS_OVER_THE_LAZY_DOG_'; % A constant
pattern used as a data
%If n>length(data) then repeat the pattern to construct a data of length 'n'
data=char([repmat(data,[1,fix(n/length(data))]),data(1:mod(n,length(data)))]);
%INTERLEAVER
%Writing into the interleaver row-by-row
for index=1:D
memory(index,1:end)=intlvrInput((index-1)*n+1:index*n);
end
intlvrOutput=zeros(1,D*n);
%Reading from the interleaver column-by-column
for index=1:n
intlvrOutput((index-1)*D+1:index*D)=memory(:,index);
end
%Create b symbols error at 25th Symbol location for test in the interleaved output
%'*' means error in this case
intlvrOutput(1,25:24+b)=zeros(1,b)+42;
fprintf('\nInterleaver Output after being corrupted by %d symbol burst error marked by ''*''->\n',b);
disp(char(intlvrOutput));
disp('____________________________________________________________________________');
%Deinteleaver
deintlvrOutput=zeros(1,D*n);
%Writing into the deinterleaver column-by-column
for index=1:n
memory(:,index)=intlvrOutput((index-1)*D+1:index*D)';
end