Ejemplo n.º 1
0
        public static int[] LocateErrors(ILinearCode linearCode, MatrixInt syndrome)
        {
            #region Error locator polynomial
            var rowCount    = linearCode.T;
            var columnCount = linearCode.T + 1;

            var system = new int[rowCount, columnCount];

            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < columnCount; col++)
                {
                    system[row, col] = syndrome[0, row + col];
                }
            }
            var coefficients = MatrixAlgorithms.Solve(new MatrixInt(system), linearCode.GaloisField).Transpose();
            #endregion

            #region Calculate Error Positions
            var errorLocators = new int[linearCode.N];
            for (int position = 0, word = 1; position < linearCode.N; position++, word++)
            {
                var sum = coefficients[0, 0];
                for (int i = 1; i < coefficients.ColumnCount; i++)
                {
                    var wordPower = linearCode.GaloisField.Power(word, i);
                    var wordToAdd = linearCode.GaloisField.MultiplyWords(coefficients[0, i], wordPower);
                    sum = linearCode.GaloisField.AddWords(sum, wordToAdd);
                }

                var lastWord = linearCode.GaloisField.Power(word, linearCode.T);
                sum = linearCode.GaloisField.AddWords(sum, lastWord);

                errorLocators[position] = sum;
            }
            #endregion
            return(errorLocators);
        }
Ejemplo n.º 2
0
        public static int[] LocateErrors(ILinearCode linearCode, MatrixInt syndrome, ParityCheckMatrixGeneratorEllyptic generator)
        {
            #region Error locator polynomial
            var rowCount    = linearCode.T;
            var columnCount = linearCode.T + 1;

            var system = new int[rowCount, columnCount];

            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < columnCount - 1; col++)
                {
                    system[row, col] = syndrome[0, generator.Terms[(row + col), linearCode.T - 2]];
                }
                system[row, columnCount - 1] = syndrome[0, generator.Terms[row, linearCode.T - 1]];
            }
            var coefficients = MatrixAlgorithms.Solve(new MatrixInt(system), linearCode.GaloisField).Transpose();
            #endregion

            #region Calculate Error Positions
            var errorLocators = new int[linearCode.N];
            for (int position = 0; position < linearCode.N; position++)
            {
                var sum = 0;
                for (int i = 0; i < linearCode.T; i++)
                {
                    var wordToAdd = linearCode.GaloisField.MultiplyWords(coefficients[0, i], linearCode.GaloisField.Power(generator.Points[position].x, i));
                    sum = linearCode.GaloisField.AddWords(sum, wordToAdd);
                }

                sum = linearCode.GaloisField.AddWords(sum, generator.Points[position].y);

                errorLocators[position] = sum;
            }
            #endregion
            return(errorLocators);
        }
Ejemplo n.º 3
0
        public static MatrixInt DecodeAndCorrect(ILinearCode linearCode, MatrixInt message, ParityCheckMatrixGeneratorEllyptic generator)
        {
            if (message.ColumnCount != linearCode.ParityCheckMatrix.ColumnCount)
            {
                throw new DimensionMismatchException("Incorrect length of message. Meesage length should be equal number of columns in parity check matrix.");
            }

            #region Calculate syndrome
            var syndrome = MatrixAlgorithms.DotMultiplication(message, linearCode.ParityCheckMatrix.Transpose(), linearCode.GaloisField);
            #endregion

            #region Locate errors
            var errorLocators = ErrorLocatorEllyptic.LocateErrors(linearCode, syndrome, generator);

            var errorCount = errorLocators.Where(v => v == 0).Count();
            #endregion

            Debug.WriteLine(linearCode.ParityCheckMatrix);
            #region Caclulate Error vector
            var system = new MatrixInt(linearCode.D, errorCount);
            for (int row = 0; row < linearCode.D; row++)
            {
                for (int col = 0, i = 0; col < linearCode.N; col++)
                {
                    if (errorLocators[col] == 0)
                    {
                        system[row, i] = linearCode.ParityCheckMatrix[row, col];
                        i++;
                    }
                }
            }
            Debug.WriteLine(system);
            system |= syndrome.Transpose();
            Debug.WriteLine(system);
            var errorVectorValues = MatrixAlgorithms.Solve(system, linearCode.GaloisField);

            var errorVector = new int[errorLocators.Length];
            for (int i = 0, j = 0; i < errorVector.Length; i++)
            {
                if (errorLocators[i] == 0)
                {
                    errorVector[i] = errorVectorValues[j, 0];
                    j++;
                }
                else
                {
                    errorVector[i] = 0;
                }
            }
            #endregion


            var rawOriginalMessage = new int[linearCode.K];

            for (int i = 0; i < linearCode.K; i++)
            {
                rawOriginalMessage[i] = linearCode.GaloisField.AddWords(message.Data[0, i + linearCode.D], errorVector[i + linearCode.D]);
            }

            var originalMessage = new MatrixInt(rawOriginalMessage);
            return(originalMessage);
        }
Ejemplo n.º 4
0
        public static MatrixInt DecodeAndCorrect(ILinearCode linearCode, MatrixInt message)
        {
            if (message.ColumnCount != linearCode.ParityCheckMatrix.ColumnCount)
            {
                throw new DimensionMismatchException("Incorrect length of message. Meesage length should be equal number of columns in parity check matrix.");
            }

            #region Calculate syndrome
            var syndrome = MatrixAlgorithms.DotMultiplication(message, linearCode.ParityCheckMatrix.Transpose(), linearCode.GaloisField);
            #endregion

            var errorLocations = ErrorLocatorDefault.LocateErrors(linearCode, syndrome);

            #region Caclulate Error vector
            var rowCount    = linearCode.T;
            var columnCount = linearCode.T + 1;

            var system = new int[rowCount, columnCount];
            #region Find error positions
            var errorNumber = 0;
            for (int errorPosition = 0; errorPosition < linearCode.N; errorPosition++)
            {
                if (errorLocations[errorPosition] == 0)
                {
                    for (int row = 0; row < rowCount; row++)
                    {
                        system[row, errorNumber] = linearCode.ParityCheckMatrix[row, errorPosition];
                    }
                    errorNumber++;
                }
            }

            for (int i = 0; i < rowCount; i++)
            {
                system[i, columnCount - 1] = syndrome[0, i];
            }
            #endregion

            #region Find error values
            var weights = MatrixAlgorithms.Solve(new MatrixInt(system), linearCode.GaloisField);
            #endregion

            #region Recreate complete error vector
            var rawErrorVector = new int[linearCode.N];

            errorNumber = 0;
            for (int i = 0; i < linearCode.N; i++)
            {
                if (errorLocations[i] == 0)
                {
                    rawErrorVector[i] = weights.Data[errorNumber, 0];
                    errorNumber++;
                    continue;
                }
                rawErrorVector[i] = 0;
            }
            #endregion

            #endregion

            var rawOriginalMessage = new int[linearCode.K];

            for (int i = 0; i < linearCode.K; i++)
            {
                rawOriginalMessage[i] = linearCode.GaloisField.AddWords(message.Data[0, i], rawErrorVector[i]);
            }

            var originalMessage = new MatrixInt(rawOriginalMessage);
            return(originalMessage);
        }