Search in sources :

Example 6 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestReedSolomonCodes_U16 method computeSyndromes.

@Test
void computeSyndromes() {
    DogArray_I16 message = randomMessage(0xFF, 50);
    var ecc = new DogArray_I16();
    for (int base = 0; base < 2; base++) {
        var alg = new ReedSolomonCodes_U16(12, primitive12, base);
        alg.generator(6);
        alg.computeECC(message, ecc);
        DogArray_I16 syndromes = DogArray_I16.zeros(6);
        alg.computeSyndromes(message, ecc, syndromes);
        // no error. All syndromes values should be zero
        for (int i = 0; i < syndromes.size; i++) {
            assertEquals(0, syndromes.data[i]);
        }
        // introduce an error
        message.data[6] += (short) 7;
        alg.computeSyndromes(message, ecc, syndromes);
        int notZero = 0;
        for (int i = 0; i < syndromes.size; i++) {
            if (syndromes.data[i] != 0)
                notZero++;
        }
        assertTrue(notZero > 1);
    }
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 7 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class ReedSolomonCodes_U16 method findErrorLocatorPolynomialBM.

/**
 * Computes the error locator polynomial using  Berlekamp-Massey algorithm [1]
 *
 * <p>[1] Massey, J. L. (1969), "Shift-register synthesis and BCH decoding" (PDF), IEEE Trans.
 * Information Theory, IT-15 (1): 122–127</p>
 *
 * @param syndromes (Input) The syndromes
 * @param errorLocator (Output) Error locator polynomial. Coefficients are large to small.
 */
void findErrorLocatorPolynomialBM(DogArray_I16 syndromes, DogArray_I16 errorLocator) {
    // error polynomial
    DogArray_I16 C = errorLocator;
    // previous error polynomial
    DogArray_I16 B = err_eval;
    initToOne(C, syndromes.size + 1);
    initToOne(B, syndromes.size + 1);
    DogArray_I16 tmp = errorX;
    tmp.resize(syndromes.size);
    // int L = 0;
    // int m = 1; // stores how much B is 'shifted' by
    int b = 1;
    for (int n = 0; n < syndromes.size; n++) {
        // Compute discrepancy delta
        int delta = syndromes.data[n] & 0xFFFF;
        for (int j = 1; j < C.size; j++) {
            delta ^= math.multiply(C.data[C.size - j - 1] & 0xFFFF, syndromes.data[n - j] & 0xFFFF);
        }
        // B = D^m * B
        B.data[B.size++] = 0;
        if (delta != 0) {
            int scale = math.multiply(delta, math.inverse(b));
            math.polyAddScaleB(C, B, scale, tmp);
            if (B.size <= C.size) {
            // if 2*L > N ---- Step 4
            // m += 1;
            } else {
                // if 2*L <= N --- Step 5
                B.setTo(C);
                // L = n+1-L;
                b = delta;
            // m = 1;
            }
            C.setTo(tmp);
        }
    }
    removeLeadingZeros(C);
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16)

Example 8 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyAddScaleB.

@Test
void polyAddScaleB() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    DogArray_I16 inputA = createArbitraryPolynomial(alg.max_value);
    // Create an arbitrary polynomial: 0xA0*x^3 + 0x45
    var inputB = new DogArray_I16(4);
    inputB.resize(4);
    inputB.set(0, 0xA0);
    inputB.set(3, 0x45);
    int scale = 0x62;
    DogArray_I16 scaleB = new DogArray_I16();
    alg.polyScale(inputB, scale, scaleB);
    DogArray_I16 expected = new DogArray_I16();
    alg.polyAdd(inputA, scaleB, expected);
    var found = new DogArray_I16();
    alg.polyAddScaleB(inputA, inputB, scale, found);
    assertEqualsG(expected, found);
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 9 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyMult_S.

@Test
void polyMult_S() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    // Create an arbitrary polynomial: 0x121*x^2 + 0x54*x + 0xFFF
    var inputA = new DogArray_I16();
    inputA.resize(3);
    inputA.set(2, 0x121);
    inputA.set(1, 0x54);
    inputA.set(0, 0xFFF);
    var inputB = new DogArray_I16();
    inputB.resize(2);
    inputB.set(0, 0x03);
    // make sure the order doesn't matter
    var output0 = new DogArray_I16();
    alg.polyMult_S(inputA, inputB, output0);
    var output1 = new DogArray_I16();
    alg.polyMult_S(inputB, inputA, output1);
    assertEquals(4, output0.size);
    assertEqualsG_S(output0, output1);
    // check the value against a manual solution
    DogArray_I16 expected = new DogArray_I16();
    expected.resize(4);
    expected.set(2, alg.multiply(0x121, 0x03));
    expected.set(1, alg.multiply(0x54, 0x03));
    expected.set(0, alg.multiply(0xFFF, 0x03));
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 10 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyMult_flipA.

@Test
void polyMult_flipA() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    // Create an arbitrary polynomial: 0x121*x^2 + 0x54*x + 0xFFF
    var inputA = new DogArray_I16();
    inputA.resize(3);
    inputA.set(2, 0x121);
    inputA.set(1, 0x54);
    inputA.set(0, 0xFFF);
    var inputB = new DogArray_I16();
    inputB.resize(2);
    inputB.set(1, 0x03);
    var output0 = new DogArray_I16();
    alg.polyMult_flipA(inputA, inputB, output0);
    assertEquals(4, output0.size);
    // check the value against a manual solution
    DogArray_I16 expected = new DogArray_I16();
    expected.resize(4);
    expected.set(1, alg.multiply(0x121, 0x03));
    expected.set(2, alg.multiply(0x54, 0x03));
    expected.set(3, alg.multiply(0xFFF, 0x03));
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_I16 (org.ddogleg.struct.DogArray_I16)17 Test (org.junit.jupiter.api.Test)13 DogArray_I32 (org.ddogleg.struct.DogArray_I32)3