Reed Solomon encoding/decoding for binary data
29 views (last 30 days)
Show older comments
Das Siddharth
on 13 Jun 2021
Commented: Das Siddharth
on 16 Jun 2021
I want to encode a binary data with the rsenc. It does the work but it generates random integer parities appenended in the end of the data vector. And when I try to manipulate it with adding random binary values and then pass it through the decoder all the results are messed up. I do get the final result correctly but the rest of the properties are all messed up. Here's one small example of what I did.
message_in_bin_enc = rsenc(message_in_bin_gf,n,k); % example message is [0 0 1] as a galois field.
bin_Rs_enc = message_in_bin_enc;
binRandom = randi([0 1],1,4);
bin_Rs_enc (1,4)= binRandom(1,1);
bin_Rs_enc (1,5)= binRandom(1,2);
bin_Rs_enc (1,6)= binRandom(1,3);
bin_Rs_enc (1,7)= binRandom(1,4);
%So here I tried to manipulate the parity bits with my very own random
%binary bits cause I need the entire data as a binary stream.
% Let's say now the message looks something like [0 0 1 0 0 0 1] assuming
% its a (7,3) RS code.
%Then once it passes through my circuit which (can)randomly flips the
%message bits. e.g : [0 1 0 0 0 0 0] (error)
error = gf(bin_Rs_enc_1,m); % bin_Rs_enc_1 is when it passes through the ciruit and error in introduced.
[corrected_message,sheesh] = rsdec(error,n,k);
%Now if I decode all the results are butchered up for some odd reason tho I
%get the correct final ans.
Please guide me through this. Thank you in advance.
0 Comments
Accepted Answer
Akira Agata
on 14 Jun 2021
Since RS system object has 'BitInput' option, I would recommend using comm.RSEncoder rather than rsenc if you want to evaluate FEC performance for binary sequence. The following is a simple example:
% RS(N,K)
N = 7;
K = 3;
% Create RS(7,3) encoder/decoder object
rsEnc = comm.RSEncoder(...
'BitInput', true,...
'CodewordLength', N,...
'MessageLength', K);
rsDec = comm.RSDecoder(...
'BitInput', true,...
'CodewordLength', N,...
'MessageLength', K);
% Since each symbol of RS(7,3) is element of GF(2^3), RS(7,3) encodes every
% 9 bits (= 3 x 3) and generates RS code word of 21 bits (= 3 x 7) length
% Encode 9 binary data bits and create 21 bits code word
rng('default'); % for reproducability
tx_bin = randi([0 1],9,1);
tx_enc_bin = rsEnc(tx_bin);
% For example, add 1 error at the 3rd bit
rx_bin = tx_enc_bin;
rx_bin(3) = 1;
% Decode the received bits
rx_dec_bin = rsDec(rx_bin);
Just in case, let's confirm that the error was corrected:
>> isequal(tx_bin, rx_dec_bin)
ans =
logical
1
3 Comments
Akira Agata
on 16 Jun 2021
Please note that Reed-Solomon code uses m-bit 'symbols' (instead of 'bits'). And each symbol is element of Galois field GF(2^m).
For example, regarding the RS(7,3) code, each code word (7 symbols) consists of 3-symbol data and 4-symbol parity, and each symbol is element of GF(2^3). So the total length of RS(7,3) code word is 21 bits (= 7 [symbols] x 3 [bit/symbol]).
+1
If you want to encode every 3bits, I believe BCH(7,3) code would be one promissing solution.
More Answers (0)
See Also
Categories
Find more on Error Detection and Correction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!