Testing Simpler P25 1/2 Decoder and Heuristics;

This commit is contained in:
lwvmobile
2023-09-15 10:30:49 -04:00
parent cbaed9337b
commit f229f0d648
6 changed files with 323 additions and 162 deletions

View File

@@ -981,6 +981,8 @@ void soft_tonef (float samp[160], int n, int ID, int AD);
//new p25lcw //new p25lcw
void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t irrecoverable_errors); void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t irrecoverable_errors);
//new p25 1/2 rate decoder
int p25_12(uint8_t * input, uint8_t treturn[12]);
void processP25lcw (dsd_opts * opts, dsd_state * state, char *lcformat, char *mfid, char *lcinfo); void processP25lcw (dsd_opts * opts, dsd_state * state, char *lcformat, char *mfid, char *lcinfo);
void processHDU (dsd_opts * opts, dsd_state * state); void processHDU (dsd_opts * opts, dsd_state * state);

View File

@@ -287,8 +287,11 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol)
valid = 0; valid = 0;
UNUSED(opts);
//testing again, either on Voice channels only (when tuned) or with trunk disabled //testing again, either on Voice channels only (when tuned) or with trunk disabled
if (state->synctype == 1 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1) // if (state->synctype == 1 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1)
if (state->synctype == 1 && opts->use_heuristics == 1)
{ {
// Use the P25p1 heuristics if available // Use the P25p1 heuristics if available
valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit); valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit);
@@ -354,7 +357,8 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol)
valid = 0; valid = 0;
//testing again, either on Voice channels only (when tuned) or with trunk disabled //testing again, either on Voice channels only (when tuned) or with trunk disabled
if (state->synctype == 0 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1) // if (state->synctype == 0 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1)
if (state->synctype == 0 && opts->use_heuristics == 1)
{ {
// Use the P25p1 heuristics if available // Use the P25p1 heuristics if available
valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit); valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit);

View File

@@ -2219,6 +2219,7 @@ main (int argc, char **argv)
// opts.setmod_bw = 12000; //safe default on both DMR and P25 // opts.setmod_bw = 12000; //safe default on both DMR and P25
opts.pulse_digi_rate_out = 8000; opts.pulse_digi_rate_out = 8000;
opts.pulse_digi_out_channels = 2; opts.pulse_digi_out_channels = 2;
opts.use_heuristics = 1; //enable for Phase 1 on -ft switch (testing)
sprintf (opts.output_name, "TDMA"); sprintf (opts.output_name, "TDMA");
fprintf (stderr,"Decoding P25 and DMR\n"); fprintf (stderr,"Decoding P25 and DMR\n");
} }

165
src/p25_12.c Normal file
View File

@@ -0,0 +1,165 @@
/*-------------------------------------------------------------------------------
* p25_12.c
* P25p1 1/2 Rate Simple Trellis Decoder
*
* LWVMOBILE
* 2023-09 DSD-FME Florida Man Edition
*-----------------------------------------------------------------------------*/
#include "dsd.h"
uint8_t p25_interleave[98] = {
0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, 49, 56, 57, 64, 65, 72, 73, 80, 81, 88, 89, 96, 97,
2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, 51, 58, 59, 66, 67, 74, 75, 82, 83, 90, 91,
4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 52, 53, 60, 61, 68, 69, 76, 77, 84, 85, 92, 93,
6, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, 47, 54, 55, 62, 63, 70, 71, 78, 79, 86, 87, 94, 95};
//this is a convertion table for converting the dibit pairs into constellation points
uint8_t p25_constellation_map[16] = {
11, 12, 0, 7, 14, 9, 5, 2, 10, 13, 1, 6, 15, 8, 4, 3
};
//digitized dibit to OTA symbol conversion for reference
//0 = +1; 1 = +3;
//2 = -1; 3 = -3;
//finite state machine values
uint8_t p25_fsm[16] = {
0,15,12,3,
4,11,8,7,
13,2,1,14,
9,6,5,10 };
int p25_12(uint8_t * input, uint8_t treturn[12])
{
int i, j;
int irr_err = 0;
uint8_t deinterleaved_dibits[98];
memset (deinterleaved_dibits, 0, sizeof(deinterleaved_dibits));
//deinterleave our input dibits
for (i = 0; i < 98; i++)
deinterleaved_dibits[p25_interleave[i]] = input[i];
//pack the input into nibbles (dibit pairs)
uint8_t nibs[49];
memset (nibs, 0, sizeof(nibs));
for (i = 0; i < 49; i++)
nibs[i] = (deinterleaved_dibits[i*2+0] << 2) | (deinterleaved_dibits[i*2+1] << 0);
//convert our dibit pairs into constellation point values
uint8_t point[49];
memset (point, 0xFF, sizeof(point));
for (i = 0; i < 49; i++)
point[i] = p25_constellation_map[nibs[i]];
//debug view points -- point[0] should be zero
// fprintf (stderr, "\n P =");
// for (i = 0; i < 49; i++)
// fprintf (stderr, " %02d", point[i]);
//free-bee on err correction, point[0] should always be zero (flush bits)
// point[0] = 0;
//convert constellation points into tdibit values using the FSM
uint8_t state = 0;
uint8_t temp_s = 0;
uint8_t tdibits[49]; //trellis dibits 1/2 rate
memset (tdibits, 0xF, sizeof(tdibits));
uint8_t hd[4]; //array of the four fsm words hamming distance
memset (hd, 0, sizeof(hd));
for (i = 0; i < 49; i++)
{
//just quickly peek for the correct state of the current point in the fsm
for (j = 0; j < 16; j++)
{
if (p25_fsm[j] == point[i])
temp_s = j&3; //set position to correct state output value
}
for (j = 0; j < 4; j++)
{
if ( p25_fsm[(state*4)+j] == point[i] )
{
//return our tdibit value and state for the next point
tdibits[i] = state = (uint8_t)j;
break;
}
}
//if tdibit value is greater than 3, then we have a decoding error
if (tdibits[i] == 0xF)
{
irr_err++; //increment number of errors
//debug position of error and state value
// fprintf (stderr, " %d:%d;", i, state);
//use the predicted correct state/value at output instead -- last resort
tdibits[i] = state = temp_s; //this still performs better than the min hamming distance method
}
}
//debug view tdibits/states
// fprintf (stderr, "\n T =");
// for (i = 0; i < 49; i++)
// fprintf (stderr, " %02d", tdibits[i]);
//pack tdibits into return payload bytes
for (i = 0; i < 12; i++)
treturn[i] = (tdibits[(i*4)+0] << 6) | (tdibits[(i*4)+1] << 4) | (tdibits[(i*4)+2] << 2) | tdibits[(i*4)+3];
//trellis point/state err tally
// if (irr_err != 0)
// fprintf (stderr, " ERR = %d", irr_err);
return (irr_err);
}
int count_bits(uint8_t b, int slen)
{
int i = 0; int j = 0;
for (j = 0; j < slen; j++)
{
if ( (b & 1) == 1) i++;
b = b >> 1;
}
return i;
}
uint8_t find_min(uint8_t list[4], int len)
{
int min = list[0];
uint8_t index = 0;
int unique = 1;
int i;
for (i = 1; i < len; i++)
{
if (list[i] < min)
{
min = list[i];
index = (uint8_t)i;
unique = 1;
}
else if (list[i] == min)
{
unique = 0;
}
}
if (unique == 0)
return 0xF;
return index;
}

View File

@@ -36,7 +36,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state)
} }
int tsbkbit[196]; //tsbk bit array, 196 trellis encoded bits int tsbkbit[196]; //tsbk bit array, 196 trellis encoded bits
int tsbk_dibit[98]; uint8_t tsbk_dibit[98];
memset (tsbkbit, 0, sizeof(tsbkbit)); memset (tsbkbit, 0, sizeof(tsbkbit));
memset (tsbk_dibit, 0, sizeof(tsbk_dibit)); memset (tsbk_dibit, 0, sizeof(tsbk_dibit));
@@ -110,16 +110,11 @@ void processMPDU(dsd_opts * opts, dsd_state * state)
} }
//flushing the trellis state machine //send tsbkbit to block_deinterleave and return tsbk_byte
if (j == 0) // ec[j] = bd_bridge(tsbkbit, tsbk_byte);
{
bd_bridge(flushing_bits, tsbk_byte);
//reset tsbk_byte afterwards
memset (tsbk_byte, 0, sizeof(tsbk_byte));
}
//send tsbkbit to block_deinterleave and return tsbk_byte //send tsbkbit to block_deinterleave and return tsbk_byte
ec[j] = bd_bridge(tsbkbit, tsbk_byte); ec[j] = p25_12 (tsbk_dibit, tsbk_byte);
//too many bit manipulations! //too many bit manipulations!
k = 0; k = 0;

View File

@@ -22,7 +22,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
} }
int tsbkbit[196]; //tsbk bit array, 196 trellis encoded bits int tsbkbit[196]; //tsbk bit array, 196 trellis encoded bits
int tsbk_dibit[98]; uint8_t tsbk_dibit[98];
memset (tsbkbit, 0, sizeof(tsbkbit)); memset (tsbkbit, 0, sizeof(tsbkbit));
memset (tsbk_dibit, 0, sizeof(tsbk_dibit)); memset (tsbk_dibit, 0, sizeof(tsbk_dibit));
@@ -38,15 +38,13 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
int tsbk_decoded_bits[190]; //decoded bits from tsbk_bytes for sending to crc16_lb_bridge int tsbk_decoded_bits[190]; //decoded bits from tsbk_bytes for sending to crc16_lb_bridge
memset (tsbk_decoded_bits, 0, sizeof(tsbk_decoded_bits)); memset (tsbk_decoded_bits, 0, sizeof(tsbk_decoded_bits));
int flushing_bits[196]; //for flushing the trellis state machine
memset (flushing_bits, 0, sizeof(flushing_bits));
int i, j, k, x; int i, j, k, x;
int ec = -2; //error value returned from (block_deinterleave) int ec = -2; //error value returned from (block_deinterleave)
int err = -2; //error value returned from crc16_lb_bridge int err = -2; //error value returned from crc16_lb_bridge
int skipdibit = 14; //initial status dibit will occur at 14, then add 36 each time it occurs int skipdibit = 14; //initial status dibit will occur at 14, then add 36 each time it occurs
int protectbit = 0; int protectbit = 0;
int MFID = 0xFF; //Manufacturer ID - Might be beneficial to NOT send anything but standard 0x00 or 0x01 messages int MFID = 0xFF; //Manufacturer ID - Might be beneficial to NOT send anything but standard 0x00 or 0x01 messages
int lb = 0; //last block
//TODO: Don't Print TSBKs/vPDUs unless verbosity levels set higher //TODO: Don't Print TSBKs/vPDUs unless verbosity levels set higher
@@ -74,16 +72,14 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
} }
//flushing the trellis state machine //send to p25_12
if (j == 0) ec = p25_12 (tsbk_dibit, tsbk_byte);
{
bd_bridge(flushing_bits, tsbk_byte); //debug err tally from 1/2 decoder
//reset tsbk_byte afterwards // if (ec) fprintf (stderr, " #%d ERR = %d;", j+1, ec);
memset (tsbk_byte, 0, sizeof(tsbk_byte));
}
//send tsbkbit to block_deinterleave and return tsbk_byte //send tsbkbit to block_deinterleave and return tsbk_byte
ec = bd_bridge(tsbkbit, tsbk_byte); // ec = bd_bridge(tsbkbit, tsbk_byte);
//too many bit manipulations! //too many bit manipulations!
k = 0; k = 0;
@@ -132,13 +128,14 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
//check the protect bit, don't run if protected //check the protect bit, don't run if protected
protectbit = (tsbk_byte[0] >> 6) & 0x1; protectbit = (tsbk_byte[0] >> 6) & 0x1;
lb = (tsbk_byte[0] >> 7) & 0x1;
//Don't run NET_STS out of this, or will set wrong NAC/CC //&& PDU[1] != 0x49 && PDU[1] != 0x45 //Don't run NET_STS out of this, or will set wrong NAC/CC //&& PDU[1] != 0x49 && PDU[1] != 0x45
//0x49 is telephone grant, 0x46 Unit to Unit Channel Answer Request (seems bogus) (mfid 90) //0x49 is telephone grant, 0x46 Unit to Unit Channel Answer Request (seems bogus) (mfid 90)
// if (MFID < 0x2 && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B ) // if (MFID < 0x2 && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B )
//running with A4 and 90 causing some false positives when sending to vPDU, issuing bad call grants to nowhere! //running with A4 and 90 causing some false positives when sending to vPDU, issuing bad call grants to nowhere!
// if ( (MFID < 0x2 || MFID == 0xA4 || MFID == 0x90) && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B ) // if ( (MFID < 0x2 || MFID == 0xA4 || MFID == 0x90) && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B )
if (MFID < 0x2 && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B ) if (MFID < 0x2 && protectbit == 0 && err == 0 && PDU[1] != 0x7B )
{ {
fprintf (stderr, "%s",KYEL); fprintf (stderr, "%s",KYEL);
process_MAC_VPDU(opts, state, 0, PDU); process_MAC_VPDU(opts, state, 0, PDU);
@@ -195,14 +192,14 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
{ {
fprintf (stderr, "[%02X]", tsbk_byte[i]); fprintf (stderr, "[%02X]", tsbk_byte[i]);
} }
fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, (tsbk_byte[0] >> 7) ); fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, lb);
if (ec != 0) if (ec != 0)
{ {
fprintf (stderr, "%s",KRED); fprintf (stderr, "%s",KRED);
fprintf (stderr, " (FEC ERR)"); fprintf (stderr, " ERR = %d", ec);
} }
else if (err != 0) if (err != 0)
{ {
fprintf (stderr, "%s",KRED); fprintf (stderr, "%s",KRED);
fprintf (stderr, " (CRC ERR)"); fprintf (stderr, " (CRC ERR)");
@@ -218,10 +215,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
MFID = 0xFF; MFID = 0xFF;
//check for last block bit //check for last block bit
if ( (tsbk_byte[0] >> 7) == 1 ) if (lb) break;
{
j = 4; //set j to break the loop early
}
} }
fprintf (stderr, "%s ", KNRM); fprintf (stderr, "%s ", KNRM);