From 885562539e1ede623f4695b667b31347a0b50f59 Mon Sep 17 00:00:00 2001 From: juribeparada Date: Thu, 1 Feb 2018 11:56:18 -0300 Subject: [PATCH] Changing metric calculation for Viterbi decoder NXDN --- NXDNConvolution.cpp | 17 ++++------------- NXDNFACCH1.cpp | 4 ++-- NXDNSACCH.cpp | 4 ++-- NXDNUDCH.cpp | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/NXDNConvolution.cpp b/NXDNConvolution.cpp index 049bdb6..8db6a05 100755 --- a/NXDNConvolution.cpp +++ b/NXDNConvolution.cpp @@ -27,12 +27,12 @@ const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) -const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 1U, 1U, 1U, 1U}; -const uint8_t BRANCH_TABLE2[] = {0U, 1U, 1U, 0U, 0U, 1U, 1U, 0U}; +const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 2U, 2U, 2U, 2U}; +const uint8_t BRANCH_TABLE2[] = {0U, 2U, 2U, 0U, 0U, 2U, 2U, 0U}; const unsigned int NUM_OF_STATES_D2 = 8U; const unsigned int NUM_OF_STATES = 16U; -const uint32_t M = 2U; +const uint32_t M = 4U; const unsigned int K = 5U; CNXDNConvolution::CNXDNConvolution() : @@ -72,16 +72,7 @@ void CNXDNConvolution::decode(uint8_t s0, uint8_t s1) for (uint8_t i = 0U; i < NUM_OF_STATES_D2; i++) { uint8_t j = i * 2U; - uint16_t metric0 = 0; - uint16_t metric1 = 0; - - if (s0 != 99U) - metric0 = (BRANCH_TABLE1[i] ^ s0); - - if (s1 != 99U) - metric1 = (BRANCH_TABLE2[i] ^ s1); - - uint16_t metric = metric0 + metric1; + uint16_t metric = abs(BRANCH_TABLE1[i] - s0) + abs(BRANCH_TABLE2[i] - s1); uint16_t m0 = m_oldMetrics[i] + metric; uint16_t m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + (M - metric); diff --git a/NXDNFACCH1.cpp b/NXDNFACCH1.cpp index 48f4639..63a3377 100644 --- a/NXDNFACCH1.cpp +++ b/NXDNFACCH1.cpp @@ -89,12 +89,12 @@ bool CNXDNFACCH1::decode(const unsigned char* data, unsigned int offset) unsigned int index = 0U; for (unsigned int i = 0U; i < NXDN_FACCH1_LENGTH_BITS; i++) { if (n == PUNCTURE_LIST[index]) { - temp2[n++] = 99U; + temp2[n++] = 1U; index++; } bool b = READ_BIT1(temp1, i); - temp2[n++] = b ? 1U : 0U; + temp2[n++] = b ? 2U : 0U; } CNXDNConvolution conv; diff --git a/NXDNSACCH.cpp b/NXDNSACCH.cpp index 304b20d..e4ec9e5 100755 --- a/NXDNSACCH.cpp +++ b/NXDNSACCH.cpp @@ -83,12 +83,12 @@ bool CNXDNSACCH::decode(const unsigned char* data) unsigned int index = 0U; for (unsigned int i = 0U; i < NXDN_SACCH_LENGTH_BITS; i++) { if (n == PUNCTURE_LIST[index]) { - temp2[n++] = 99U; + temp2[n++] = 1U; index++; } bool b = READ_BIT1(temp1, i); - temp2[n++] = b ? 1U : 0U; + temp2[n++] = b ? 2U : 0U; } CNXDNConvolution conv; diff --git a/NXDNUDCH.cpp b/NXDNUDCH.cpp index e58460e..eabcca7 100644 --- a/NXDNUDCH.cpp +++ b/NXDNUDCH.cpp @@ -110,12 +110,12 @@ bool CNXDNUDCH::decode(const unsigned char* data) unsigned int index = 0U; for (unsigned int i = 0U; i < NXDN_FACCH2_LENGTH_BITS; i++) { if (n == PUNCTURE_LIST[index]) { - temp2[n++] = 99U; + temp2[n++] = 1U; index++; } bool b = READ_BIT1(temp1, i); - temp2[n++] = b ? 1U : 0U; + temp2[n++] = b ? 2U : 0U; } CNXDNConvolution conv;