#2162 APCO25 NID BCH decoder implementation. (#2163)

Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
Denny Sheirer
2025-02-27 08:09:46 -06:00
committed by GitHub
parent 4e367bb5fe
commit 8718d04ef5
6 changed files with 1513 additions and 13 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2025 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.edac.bch;
/**
* BCH(63) decoder base implementation that uses GF(2^6) and standard primitive polynomial.
*/
public abstract class BCH_63 extends BCH
{
public static final int M = 6;
/**
* Constructs an instance
* @param k data bits size
* @param t error detection and correction capacity of the generator polynomial used to create the codewords.
*/
public BCH_63(int k, int t)
{
super(M, k, t, PRIMITIVE_POLYNOMIAL_GF_63);
}
}

View File

@@ -0,0 +1,69 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2025 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.edac.bch;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import io.github.dsheirer.bits.IntField;
/**
* APCO 25 BCH(63,16,23) code with T=11 error bit correction capacity.
*/
public class BCH_63_16_23_P25 extends BCH_63
{
public static final int K = 16;
private static final int T = 11; // Error-correcting capability
public static final IntField NAC_FIELD = IntField.length12(0);
public static final IntField DUID_FIELD = IntField.length4(12);
/**
* Constructs a BCH decoder instance for processing APCO25 BCH(63,16,23) protected NID codewords
*/
public BCH_63_16_23_P25()
{
super(K, T);
}
@Override
public void decode(CorrectedBinaryMessage message)
{
super.decode(message);
}
/**
* Attempts to error correct the NID message. If the message is uncorrectable, overwrite the message NAC field with
* the most frequently/recently observed NAC value and attempt to correct the message a second time.
* @param message to correct
* @param observedNAC that can be used to attempt a second correction on an uncorrectable message.
*/
public void decode(CorrectedBinaryMessage message, int observedNAC)
{
decode(message);
if(message.getCorrectedBitCount() == BCH.MESSAGE_NOT_CORRECTED && observedNAC > 0)
{
//Check to see if the message NAC is different than the observed NAC ... overwrite and try again.
if(message.getInt(NAC_FIELD) != observedNAC)
{
message.setInt(observedNAC, NAC_FIELD);
decode(message);
}
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2025 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.edac.bch;
/**
* Finds primitive polynomials for a Galois Fields (GF) of size M.
*/
public class GaloisFieldPrimitiveFinder
{
private int M;
private int N;
/**
* Constructs an instance of primitive finder for m for GF(2 ^ m)
* @param m size of galois field
*/
public GaloisFieldPrimitiveFinder(int m)
{
M = m;
N = ((1 << M) - 1);
}
public boolean isPrimitive(int polynomial)
{
int x = 1;
int k = 1 << M;
for(int i = 0; i < N; i++)
{
if(i > 0 && (x == 1))
{
return false;
}
x <<= 1;
if((x & k) > 0)
{
x ^= polynomial;
}
}
return (x == 1);
}
public static void main(String[] args)
{
GaloisFieldPrimitiveFinder finder;
//Search: M=2 to M=9
for(int m = 2; m < 10; m++)
{
finder = new GaloisFieldPrimitiveFinder(m);
System.out.println("Searching for M: " + m);
for(int i = 0; i < (1 << m); i++)
{
//Skip polynomials divisible by X or X+1
int candidate = i | (1 << m);
if(finder.isPrimitive(candidate))
{
System.out.println("M:" + m + " Primitive: " + String.format("0x%X", candidate));
}
}
}
}
}