tomerfiliba-org / reedsolomon

ā³šŸ›” Pythonic universal errors-and-erasures Reed-Solomon codec to protect your data from errors and bitrot. Includes a future-proof zero-dependencies pure-python implementation šŸ”® and an optional speed-optimized Cython/C extension šŸš€
http://pypi.python.org/pypi/reedsolo
Other
351 stars 86 forks source link

Generated correction symbols do not match those ones of MATLAB #66

Closed DmitryYenkov closed 11 months ago

DmitryYenkov commented 1 year ago

image image

prim=285 is the same, as the length and number of correction symbols. Why is the difference? How can I get same result?

lrq3000 commented 1 year ago

Try with fcr=1, it's often an implicitly hardcoded value in most implementations of Reed-Solomon that most developers aren't aware of. In our implementation, fcr is set to 0 by default, but often it is set to 1 by mistake in other implementations (it's essentially at which iteration you start encoding/decoding, and since MATLAB is 1 indexed, they may have mistakenly started at 1). But fcr can also be another value especially if they followed US military standards.

I would suggest you try this function here to autodetect the parameters by providing the message without the ecc, and then the message with ecc symbols (ie, the input and output of what you fed/received from matlab rs codec), and the algo should tell you what are the adequate parameters.

DmitryYenkov commented 1 year ago

Thanks! It works. I tried 5 or 6 different implementations of RS encoder from github and none of them give the same result as MATLAB.

lrq3000 commented 1 year ago

Awesome, thank you very much for your feedback!

Out of curiosity, what parameters worked? Is it fcr=1 or another set of parameters?

10 juil. 2023 08:19:40 DmitryYenkov @.***>:

Thanks! It works. I tried 5 or 6 different implementations of RS encoder from github and none of them give the same result as MATLAB.

ā€” Reply to this email directly, view it on GitHub[https://github.com/tomerfiliba-org/reedsolomon/issues/66#issuecomment-1628310611], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAIRFXXDZOEEWRHZC6AUFP3XPONHZANCNFSM6AAAAAAZ63BFFI]. You are receiving this because you commented.[Image de pistage][https://github.com/notifications/beacon/AAIRFXXB2AXGPUJWRQHDLHLXPONHZA5CNFSM6AAAAAAZ63BFFKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTBBYGFG.gif]

DmitryYenkov commented 12 months ago

With fcr=1.

In MATLAB there is a function for creation of generator polynomial for RS-code - rsgenpoly. By default it gives thefollowing output:

rsgenpoly(255, 239, prim_poly) ans = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal) Array elements = 1 118 52 103 31 104 126 187 232 17 56 183 49 100 81 44 79

But I guess with fcr=0 this polynom is different. I extracted one from this github project: https://github.com/raeudigerRaeffi/generalizedReedSolomon/tree/master

And it looks like this: 1, 59, 13, 104, 189, 68, 209, 30, 8, 163, 65, 41, 229, 98, 50, 36, 59

So, here is a comparation. 1st output is default to MATLAB, 2nd is with poly (1,59,13,...) and 3rd is with (1,118,52,...) poly image Correction symbols only.

lrq3000 commented 12 months ago

Thank you very much for your feedback!

Iā€™m reopening this issue to remind myself to add the autodetection script in reedsolo directly so that it will be easier for others to find the adequate parameters for messages encoded by arbitrary RS codecs, and also to document better the interoperability with MATLAB (a common RS codec).