Add fuzzy syncword validation

Now syncword match is not exact but can tolerate up to two erroneous
bits.

TG-81
pull/68/head
Niccolò Izzo 2022-02-08 14:44:05 +01:00 zatwierdzone przez Silvano Seva
rodzic ca49b306b9
commit 5ef145cd39
2 zmienionych plików z 16 dodań i 5 usunięć

Wyświetl plik

@ -252,6 +252,11 @@ private:
*/
int8_t quantize(int32_t offset);
/**
* Compute Hamming Distance between two bytes
*/
uint8_t hammingDistance(uint8_t x, uint8_t y);
};
} /* M17 */

Wyświetl plik

@ -272,6 +272,11 @@ bool M17Demodulator::isFrameLSF()
return isLSF;
}
uint8_t M17Demodulator::hammingDistance(uint8_t x, uint8_t y)
{
return __builtin_popcount(x ^ y);
}
void M17Demodulator::update()
{
M17::sync_t syncword = { 0, false };
@ -283,6 +288,7 @@ void M17Demodulator::update()
FILE *csv_log = fopen("demod_log_2.csv", "a");
#endif
if(baseband.data != NULL)
{
// Apply RRC on the baseband buffer
@ -342,12 +348,12 @@ void M17Demodulator::update()
// printf(" %02X%02X", (*idleFrame)[i], (*idleFrame)[i+1]);
//}
}
// Check if the decoded syncword matches with frame or lsf sync
// If syncword is not valid, lock is lost, accept 2 bit errors
if (frameIndex == M17_SYNCWORD_SYMBOLS &&
((*activeFrame)[0] != stream_syncword_bytes[0] ||
(*activeFrame)[1] != stream_syncword_bytes[1]) &&
((*activeFrame)[0] != lsf_syncword_bytes[0] ||
(*activeFrame)[1] != lsf_syncword_bytes[1]))
(hammingDistance((*activeFrame)[0], stream_syncword_bytes[0]) +
hammingDistance((*activeFrame)[1], stream_syncword_bytes[1]) > 2) &&
(hammingDistance((*activeFrame)[0], lsf_syncword_bytes[0]) +
hammingDistance((*activeFrame)[1], lsf_syncword_bytes[1]) > 2))
{
locked = false;
std::swap(activeFrame, idleFrame);