sonic-the-hedgehog-lnk1123 / reedsolomon Goto Github PK
View Code? Open in Web Editor NEWA .NET implementation of the Reed-Solomon algorithm, supporting error, erasure and errata correction
License: Apache License 2.0
A .NET implementation of the Reed-Solomon algorithm, supporting error, erasure and errata correction
License: Apache License 2.0
Hi,
First of all thanks for your efforts creating this library.
A small remark however: IMHO the check: if (toEncode.Length >= this.field.Size)
on line 64 of the ReedSolomonEncoder
should have a >
instead of a >=
.
The following reasoning leads me to this: The data size representing 128 message bytes + 32 ecBytes =160 data bytes and can be encoded with the GenericGF AZTEC_DATA_8
, same holds for 223 message bytes + 32 error correction bytes = 255 bytes of data. However, a message of 224 bytes is now not supported, although I think it can be represented in 256 bytes of data.
What is your opinion on this? Is it possible to store 224 bytes and 32 ecBytes using GenericGF AZTEC_DATA_8
?!
Hi. Is this project able to decode CCSDS images?
If yes, i appreciate if you provide an example.
The byte to be encoded is greater than 31 and cannot be found in the array logTable[a].
How do I deal with this situation
In issue #3 there is provided primitive polynomial for every number of bits between 2 and 30. The polynomial I found using https://www.wolframalpha.com/input/?i=finite+field+of+order+65536 using the first primitive polynomial for each power of 2. I found, that providing invalid polynomial (described as integer positive number) causes infinity loop between lines 317 and 325 of https://github.com/Sonic-The-Hedgehog-LNK1123/ReedSolomon/blob/master/ReedSolomon/GenericGFPoly.cs when Encoding
is ran.
I am not familiar with Galois field theory and it is difficult for me. It is possible to reliably test if provided polynomial is valid using your and ZXing code? The performance is not important for me, I will accept the brute-force way. For example, I know that, for 8-bit values all polynomials are between 256 and 511, so it is not problem to generate every value between this and test each value. For 16-bit values there are above 2000 valid primitive polynomials of about 65000 possible polynomials, so the best way is generate the list once and store it.
I have tested the library by creating random data, corrupting the data and trying to recovery. I use the v2.1.0 release.
If I try to recovery using known error locations (erasures) thousand times, sometimes recovery fails. Below there is simple console application code, which indicates the problem:
using System;
using System.Collections.Generic;
namespace ReedSolomonTest
{
class MainClass
{
/// <summary>
/// Creating Galois field
/// </summary>
/// <returns>The GenericGF object</returns>
static STH1123.ReedSolomon.GenericGF GenGF(int NumOfBits)
{
int PrimPoly = 0;
switch (NumOfBits)
{
case 4: PrimPoly = 16 + 2 + 1; break;
case 8: PrimPoly = 256 + 16 + 8 + 4 + 1; break;
case 12: PrimPoly = 4096 + 64 + 16 + 2 + 1; break;
case 16: PrimPoly = 65536 + 32 + 8 + 4 + 1; break;
case 20: PrimPoly = 1048576 + 8 + 1; break;
case 24: PrimPoly = 16777216 + 16 + 8 + 2 + 1; break;
default: throw new Exception("Unsupported number of bits");
}
return new STH1123.ReedSolomon.GenericGF((int)PrimPoly, (int)Math.Pow(2, NumOfBits), 1);
}
public static void Main(string[] args)
{
// Number of bits per symbol
int NumOfBits = 8;
// Raw data block size
int DataSize = 223;
// Reed-Solomon code block size
int CodeSize = 32;
// Maximum value of element (2^n)-1, where n=1,2,3...
int ValMax = ((int)Math.Pow(2, NumOfBits) - 1);
// Number of randomly generated errors
int TestErrCount = 30;
// Determine if error locations is known
bool KnownErrors = true;
// Data structure with correction code
int[] TestData1 = new int[DataSize + CodeSize];
int[] TestData2 = new int[DataSize + CodeSize];
int[] TestData3 = new int[DataSize + CodeSize];
// Creating pseudo-random number generator
Random R = new Random();
// Maximum used value
int MaxCodeVal = 0;
// Good and bad result counter
int ResultGood = 0;
int ResultBad = 0;
int ResultFailure = 0;
// Number of test iterations
int TestIterations = 1000000;
// Iterative repeat test
for (int TestI = 0; TestI < TestIterations; TestI++)
{
// Clearing data
for (int i = 0; i < (DataSize + CodeSize); i++)
{
TestData1[i] = 0;
TestData2[i] = 0;
TestData3[i] = 0;
}
// Creating three instances of the same raw data
for (int i = 0; i < DataSize; i++)
{
TestData1[i] = R.Next(0, ValMax);
TestData2[i] = TestData1[i];
TestData3[i] = TestData1[i];
}
// Encoding
STH1123.ReedSolomon.ReedSolomonEncoder RSE = new STH1123.ReedSolomon.ReedSolomonEncoder(GenGF(NumOfBits));
RSE.Encode(TestData2, CodeSize);
// Making random errors with storing locations
int TestErr = TestErrCount;
List<int> TestErrPos = new List<int>();
while (TestErr > 0)
{
int P = R.Next(DataSize - 1);
if (!TestErrPos.Contains(P))
{
TestErrPos.Add(P);
int D = R.Next(ValMax);
if (TestData2[P] != D)
{
TestData2[P] = D;
TestData3[P] = D;
TestErr--;
}
}
}
// Trying to recovery original data
STH1123.ReedSolomon.ReedSolomonDecoder RSD = new STH1123.ReedSolomon.ReedSolomonDecoder(GenGF(NumOfBits));
bool DecodeResult = RSD.Decode(TestData2, CodeSize, KnownErrors ? TestErrPos.ToArray() : null);
// Encounting differences in raw data instances
int Diff12 = 0;
int Diff13 = 0;
for (int i = 0; i < DataSize; i++)
{
if (TestData1[i] != TestData2[i])
{
Diff12++;
}
if (TestData1[i] != TestData3[i])
{
Diff13++;
}
}
// Reading the maximum value
for (int i = 0; i < (DataSize + CodeSize); i++)
{
if (MaxCodeVal < TestData2[i])
{
MaxCodeVal = TestData2[i];
}
}
// If there is not difference, this test result is good,
// otherwise the test result is bad
if (Diff13 == TestErrCount)
{
if (Diff12 == 0)
{
ResultGood++;
}
else
{
ResultBad++;
}
}
else
{
ResultFailure++;
}
// Printing the test progress
if ((TestI % (TestIterations / 100)) == 0)
{
Console.WriteLine("Progress: " + (TestI / (TestIterations / 100)) + "%");
}
}
// Printing the test results
Console.WriteLine("Maximum existing value: " + MaxCodeVal.ToString());
Console.WriteLine("Good: " + ResultGood);
Console.WriteLine("Bad: " + ResultBad);
Console.WriteLine("Failed: " + ResultFailure);
Console.WriteLine("Total: " + (ResultGood + ResultBad + ResultFailure));
Console.ReadLine();
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.