Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
432 views

Matlab Code For RS Coding and Decoding

This document demonstrates the design of a block interleaver for a Reed Solomon code. It shows how interleaving can help when the expected burst error length from the channel exceeds the error correction capability of the RS code. It defines the interleaver and deinterleaver, writes input data into the interleaver row-by-row, reads it out column-by-column, introduces a burst error, then writes the interleaved output into the deinterleaver column-by-column and reads it out row-by-row to disperse the errors for correction.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
432 views

Matlab Code For RS Coding and Decoding

This document demonstrates the design of a block interleaver for a Reed Solomon code. It shows how interleaving can help when the expected burst error length from the channel exceeds the error correction capability of the RS code. It defines the interleaver and deinterleaver, writes input data into the interleaver row-by-row, reads it out column-by-column, introduces a burst error, then writes the interleaved output into the deinterleaver column-by-column and reads it out row-by-row to disperse the errors for correction.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

%Matlab Code for RS coding and decoding

n=7; k=3; % Codeword and message word lengths


m=3; % Number of bits per symbol
msg = gf([5 2 3; 0 1 7;3 6 1],m) % Two k-symbol message words
% message vector is defined over a Galois field where the number
must
%range from 0 to 2^m-1
codedMessage = rsenc(msg,n,k) % Two n-symbol codewords
dmin=n-k+1 % display dmin
t=(dmin-1)/2 % diplay error correcting capability of the code
% Generate noise Add 2 contiguous symbol errors with first word;
% 2 discontiguous symbol errors with second word and 3
distributed symbol
% errors to last word
noise=gf([0 0 0 2 3 0 0 ;6 0 1 0 0 0 0 ;5 0 6 0 0 4 0],m)
received = noise+codedMessage
%dec contains the decoded message and cnumerr contains the
number of
%symbols errors corrected for each row. Also if cnumerr(i) = -1 it
indicates
%that the ith row contains unrecoverable error

[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

% Original message printed for comparison


msg = GF(2^3) array. Primitive polynomial = D^3+D+1 (11
decimal)
Array elements =
523
017
361

%Demonstration of design of Block Interleaver for Reed Solomon Code


%Author : Mathuranathan for http://www.gaussianwaves.com
%License - Creative Commons - cc-by-nc-sa 3.0
clc;

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
%____________________________________________

p=n-k; %Number of parity symbols


t=p/2; %Error correction capability of RS code

fprintf('Given (%d,%d) Reed Solomon code can correct : %d symbols \n',n,k,fix(t));


fprintf('Given - expected burst error length from the channel : %d symbols \n',b);
disp('____________________________________________________________________________');
if(b>t)
fprintf('Interleaving MAY help in this scenario\n');
else
fprintf('Interleaving will NOT help in this scenario\n');
end
disp('____________________________________________________________________________');
D=ceil(b/t)+1; %Intelever Depth

memory = zeros(D,n); %constructing block interleaver memory

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)))]);

%We sending D blocks of similar data


intlvrInput=repmat(data(1:n),[1 D]);

fprintf('Input Data to the Interleaver -> \n');


disp(char(intlvrInput));
disp('____________________________________________________________________________');

%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

%Reading from the deinterleaver row-by-row


for index=1:D
deintlvrOnput((index-1)*n+1:index*n)=memory(index,1:end);
end
fprintf('Deinterleaver Output->\n');
disp(char(deintlvrOnput));
disp('____________________________________________________________________________');

You might also like