tomerfiliba-org/reedsolomon

How to use for Bit Correction

fspider opened this issue · 2 comments

Data length = 64 bit (data) + 32 bit (RS padding) = 96 bit.

Current code is trying to correct in Byte Unit.
But I want to correct in bit unit so that it can correct as many bit as possible.

Thank you!

NOTE: I'm not associated with this library in particular, but perhaps this may be informative for your problem:

This library corrects burst-type errors, not raw binary — which is fairly typical in terms of how RS codes are commonly used (there are of course cases where binary stream RS is more common).

With that being said, the straightforward way to attempt to maximize correctability would be to maximize the number of code words (ie: select the smallest bit sized code that will work). Let's try different bit sizes iteratively:

  • 4 bits: 2^4-1 = 15 codewords; 96 bits / (4 bits / codeword) = at least 24 codewords, so this will not work (24 > 15).
  • 5 bits: 2^5-1 = 31 codewords; 96 bits / (5 bits / codeword) = at least 19.2 codewords, so this will work, but it will be wasteful as only 32/5 = 6.4 => 6 codewords can be used for coding, leaving 0.4*5 = 2 bits of "RS padding" to be wasted.
  • 6 bits: 2^6-1 = 63 codewords; 96 bits / (6 bits / codeword) = at least 16 codewords, so this will work, but it will be wasteful as only 32/6 = 5.333... => 5 codewords can be used for coding, leaving 0.333...*6 = 2 bits of "RS padding" to be wasted.
  • 7 bits: 2^7-1 = 127 codewords; 96 bits / (7 bits / codeword) = at least 13.7 codewords, so this will work, but it will be even more wasteful as only 32/7 = 4.57 => 4 codewords can be used for coding, leaving 0.57*7 = 4 bits of "RS padding" to be wasted.
  • 8 bits: 2^8-1 = 255 codewords; 96 bits / (8 bits / codeword) = at least 12 codewords, so this will work efficiently as 32/8 = 4 codewords can be used for coding, meaning that zero bits of "RS padding" will be wasted.

Given 4 codewords of the 8 bit sized code as codable correction words, you should be able to correct up to n/2 = 4/2 = 2 unknown symbol errors or detect up to n = 4 symbol errors.

However, if you are willing to slightly relax your requirements, you could improve this slightly while maintaining the same coding rate (albeit at minor loss of encode/decode speed). For instance, if you encoded and decoded two messages together, you could effectively double the number of correctable messages: 16 data codewords (128 bits) + 8 correction codewords (64 bits) = 24 total codewords (192 bits), which would allow you to correct up to n/2 = 8/2 = 4 unknown symbol errors or detect up to n = 8 symbol errors.

You can take this to it's logical limit by encoding and decoding floor(255/12) = 21 messages together (again, with some increasing in encoding/decoding complexity resulting in decreased speed): 218 = 168 data codewords (1,344 bits) and 214 = 84 correction codewords (672 bits) yields 252 total codewords (2,016 bits), which would allow you to correct up to n/2 = 84/2 = 42 unknown symbol errors or detect up to n = 42 symbol errors.

I hope this is helpful, lmk :)

To complement @haneefmubarak 's excellent answer: in a nutshell, convert your bits into bytes, and then for RSCodec just divide by 8 your design: 64 bit (data) + 32 bit (RS padding) = (n-k: 8) + (k: 4) = 12 Bytes. Where n-k is the original message length (without error correction code), and k the error correction code length (also called nsym in this module).