org.cesta.util
Class LinearEncoder

java.lang.Object
  extended by org.cesta.util.LinearEncoder

public class LinearEncoder
extends java.lang.Object

Linear encoder encodes numbers according to chosen simplified BCH polynomial code.

CODE_15_7 matrix was constructed from polynomial G(x) = x^8+x^7+x^6+x^4+1 and generates (15,7) linear code, where each two codewords have Hamming distance at least 5. It has only 7 data bits, therefore it can encode only 128 different values.

CODE_15_10 matrix was constructed from polynomial G(x) = x^5+x^3+x+1 and generates (15,10) linear code, where each two codewords have Hamming distance at least 4. It has 10 data bits.

CODE_15_11 is (15,11) code and was constructed from G(x) = x^4+x+1. Hamming distance between codewords is at least 3. 11 data bits.

CODE_15_14 is (15,14) code and was constructed from G(x) = x+1. Hamming distance between codewords is at least 2. 14 data bits.

You can use Richard Tervo's online tool to see how the codes actualy look. http://www.ee.unb.ca/cgi-bin/tervo/polygen.pl

Author:
Tobias Smolka

Field Summary
protected  int[][] code
           
static int[][] CODE_15_10
           
static int[][] CODE_15_11
           
static int[][] CODE_15_14
           
static int[][] CODE_15_7
           
 
Constructor Summary
LinearEncoder(int wordCount)
          Creates linear encoder, that can encode specified number of words and guarantee some hamming distance between each of them.
 
Method Summary
 int decode(int number)
          Decodes provided number.
 int encode(int number)
          Encodes provided number
 int[][] getCode()
          Returns currently used code (generator matrix)
static int hammingDistance(int a, int b)
          Returns Hamming distance between two numbers
static int[][] int2matrix(int number, int bitLength)
          Converts number to binary matrix with one row and bitLength columns
static int matrix2int(int[][] matrix)
          Converts binary row matrix to number
static int[][] multiplyMatrices(int[][] m1, int[][] m2)
          Multiply general matrices
 void setCode(int[][] code)
          Sets code for the encoder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CODE_15_7

public static final int[][] CODE_15_7

CODE_15_10

public static final int[][] CODE_15_10

CODE_15_11

public static final int[][] CODE_15_11

CODE_15_14

public static final int[][] CODE_15_14

code

protected int[][] code
Constructor Detail

LinearEncoder

public LinearEncoder(int wordCount)
Creates linear encoder, that can encode specified number of words and guarantee some hamming distance between each of them. Encoded number is always 15 bites long.

Parameters:
wordCount - number of possible words
Method Detail

setCode

public void setCode(int[][] code)
Sets code for the encoder. The code is 2 dimensional array, which contains generator matrix.

Parameters:
code -

getCode

public int[][] getCode()
Returns currently used code (generator matrix)

Returns:
code

encode

public int encode(int number)
Encodes provided number

Parameters:
number -
Returns:
encoded number

decode

public int decode(int number)
Decodes provided number. The algorithm doesn't currently support error correction.

Parameters:
number -
Returns:
decoded number

int2matrix

public static int[][] int2matrix(int number,
                                 int bitLength)
Converts number to binary matrix with one row and bitLength columns

Parameters:
number - number to convert
bitLength - how big the matrix should be
Returns:
matrix

matrix2int

public static int matrix2int(int[][] matrix)
Converts binary row matrix to number

Parameters:
matrix - matrix to convert
Returns:
number

multiplyMatrices

public static int[][] multiplyMatrices(int[][] m1,
                                       int[][] m2)
Multiply general matrices

Parameters:
m1 - matrix A
m2 - matrix B
Returns:
matrix A*B

hammingDistance

public static int hammingDistance(int a,
                                  int b)
Returns Hamming distance between two numbers

Parameters:
a - non negative number
b - non negative number
Returns:
Hamming distance between a and b