Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about two different results with the same coding target. #56

Open
han5onwi11y opened this issue Feb 17, 2023 · 1 comment
Open

Comments

@han5onwi11y
Copy link

han5onwi11y commented Feb 17, 2023

Thank you for reading this message and thanks to the authors of this reed-solomon Python repository.

If we take (255, 223) coding as an example and assume GF(2^8), the information before coding has 223 bytes, and the reed-solomon ecc has 32 bytes. Hence, the total encoded length is 255 bytes.

First, the information before coding has a file named "input.bin", which has 233 bytes.

input.bin column 1 column 2 column 3 column 4 column 5 column 6 column 7 column 8 column 9 column 10 column 11 column 12 column 13 column 14 column 15 column 16
row 1 0x12 0x34 0x56 0x78 0x90 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0x00 0xff
row 2 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
row 3 0x32 0x3a 0x63 0x75 0x3c 0x77 0xb3 0x83 0x86 0x86 0x5c 0x00 0x00 0x20 0x00 0x00
row 4 0x00 0x00 0x20 0x02 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0xb0 0xf1 0x01 0x00
row 5 0x00 0x00 0x60 0x08 0x00 0x00 0x18 0x30 0x97 0xe5 0x00 0x00 0x53 0xe3 0x0c 0x00
row 6 0x00 0x1a 0xd8 0x28 0xcd 0xe1 0x78 0x10 0x96 0xe5 0x06 0x00 0xa0 0xe1 0x31 0xff
row 7 0x2f 0xe1 0x00 0x20 0x50 0xe2 0xe5 0xff 0xff 0xca 0x05 0x00 0x00 0x0a 0xcc 0x01
row 8 0x9f 0xe5 0x0a 0x10 0xa0 0xe1 0x00 0x00 0x8f 0xe0 0xdc 0xa0 0x90 0xe5 0x01 0x10
row 9 0x41 0xe2 0x94 0x90 0x90 0xe5 0x01 0x20 0x02 0xe0 0x00 0x30 0xa0 0xe3 0xc8 0xd0
row10 0x4d 0xe2 0x03 0x00 0x92 0xe1 0x03 0x00 0x00 0x0a 0x50 0x03 0x9f 0xe5 0x00 0x00
row11 0x8f 0xe0 0xa0 0x90 0xe5 0x01 0x10 0x41 0xe2 0x94 0x90 0x90 0xe5 0x01 0x20 0x02
row12 0xe0 0x00 0x30 0xa0 0xe3 0xc8 0xd0 0x4d 0xe2 0x03 0x00 0x92 0xe1 0x03 0x08 0x10
row13 0x9d 0xe5 0x00 0x00 0x51 0xe3 0x04 0x00 0x00 0x0a 0x08 0x20 0x9d 0xe5 0x04 0x00
row14 0xa0 0x08 0x10 0x9d 0xe5 0x00 0x00 0x51 0xe3 0x04 0x00 0x00 0x0a 0x08 0x20 -

Second, I use the MATLAB to generate the RS code, and the result of 32-byte RS code is below. Please note that this 32-byte RS code generated by MATLAB is my desired result. However, the Python script provided by his Github repository has different results (see the third part).

m = 8;
n = 255;
k = 223;
prim_poly = 285;
genpoly = rsgenpoly(n,k,prim_poly,1);
fp = fopen('input.bin','r','b') ;
data = fread(fp, 'ubit8')';
info_bytes = gf(data ,m);
encode_bytes = rsenc(info_bytes,n,k,genpoly) ;
encode_bytes.x %print this, then see the 255 bytes with rs code

rs code column 1 column 2 column 3 column 4 column 5 column 6 column 7 column 8 column 9 column 10 column 11 column 12 column 13 column 14 column 15 column 16
row 1 0x28 0x49 0x62 0x92 0x1d 0x89 0x5c 0x81 0x02 0xde 0x7b 0x1f 0xb3 0xc1 0xa8 0x48
row 2 0xd4 0xe9 0xad 0x47 0xf4 0x70 0x58 0x8b 0x97 0x1d 0x8a 0x83 0x42 0x32 0x29 0x7d

Third, I use the Python script provided by his Github repository.

from reedsolo import RSCodec
import reedsolo as rs
inputfile = open('input.bin', "rb")
n = 255
rsc = RSCodec(32)
rs.init_tables(0x11d)
ecc_encode = rsc.encode(inputfile.read())

If you print ecc_encode out, you can see the 32-byte RS code below.

rs code column 1 column 2 column 3 column 4 column 5 column 6 column 7 column 8 column 9 column 10 column 11 column 12 column 13 column 14 column 15 column 16
row 1 0xfd 0xe2 0xaa 0x47 0x93 0xad 0x57 0x5b 0xca 0xd8 0x17 0x19 0xe2 0x38 0x52 0x7d
row 2 0x74 0xa3 0x98 0xf9 0x23 0xc3 0xa3 0xba 0x3d 0x80 0x80 0x02 0x61 0xf5 0x91 0x29

The result generated by Python script is not corrected (at least, it is not my desired).

Could you help me correct the Python script? Thank you.

@han5onwi11y han5onwi11y changed the title two coding cases cause different results. Questions about two coding different resultes with the same coding target. Feb 17, 2023
@han5onwi11y han5onwi11y changed the title Questions about two coding different resultes with the same coding target. Questions about two different results with the same coding target. Feb 17, 2023
@lrq3000
Copy link
Collaborator

lrq3000 commented Mar 30, 2023

Hello,

Normally our library is mathematically standardized, I developed two different codebases (see also unireedsolomon) from two different approaches to ensure that it is universal. So either MATLAB's codec is doing some assumptions that you did not input into our codec (such as a non-zero fcr value), or there is something different with the data loading, so that the data you feed into RSCodec is actually different from the one you feed into the MATLAB's RS codec.

In particular, I am referring to this MATLAB line:

data = fread(fp, 'ubit8')';

There is no equivalent in your Python code.

However, since you do not provide here the original input data, I cannot test further. It is not sufficient you provide the output of both codecs encodings, we would need to see the original file, so that we can try to reproduce on our own. You provide a dump above but it would help if you could provide a code to generate it either in MATLAB or Python, or just attach it here or via a 3rd party website, so that we are exactly on the same page, as otherwise reproducing the dump is I think hazardous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants