GithubHelp home page GithubHelp logo

sonic-the-hedgehog-lnk1123 / reedsolomon Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 1.0 55 KB

A .NET implementation of the Reed-Solomon algorithm, supporting error, erasure and errata correction

License: Apache License 2.0

C# 100.00%
csharp dotnet error-correcting-codes forward-error-correction library reed-solomon reedsolomon

reedsolomon's People

Contributors

sonic-the-hedgehog-lnk1123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

myalitsin

reedsolomon's Issues

Size check not accurate

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?!

CCSDS image decoding

Hi. Is this project able to decode CCSDS images?

If yes, i appreciate if you provide an example.

Valid primitive polynomials

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.

Bugs and errors in recovering with erasures

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();
        }


    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.