Implementation of M17 decorrelator, polynomial interleaver and Golay(24,12) encoder

This commit is contained in:
Silvano Seva 2021-08-22 10:29:31 +02:00
parent ee1b111fb7
commit 93af26ef13
3 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* Adapted from original code written by Rob Riggs, Mobilinkd LLC *
* *
* 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/> *
***************************************************************************/
#ifndef M17_DECORRELATOR_H
#define M17_DECORRELATOR_H
#ifndef __cplusplus
#error This header is C++ only!
#endif
#include <experimental/array>
#include <string>
#include <array>
/**
* Decorrelator sequence for data randomisation.
*/
static constexpr std::array< uint8_t, 46 > sequence =
{
0xd6, 0xb5, 0xe2, 0x30, 0x82, 0xFF, 0x84, 0x62,
0xba, 0x4e, 0x96, 0x90, 0xd8, 0x98, 0xdd, 0x5d,
0x0c, 0xc8, 0x52, 0x43, 0x91, 0x1d, 0xf8, 0x6e,
0x68, 0x2F, 0x35, 0xda, 0x14, 0xea, 0xcd, 0x76,
0x19, 0x8d, 0xd5, 0x80, 0xd1, 0x33, 0x87, 0x13,
0x57, 0x18, 0x2d, 0x29, 0x78, 0xc3
};
/**
* Apply M17 decorrelation scheme to a byte array.
*
* \param data: byte array to be decorrelated..
*/
template <size_t N >
inline void decorrelate(std::array< uint8_t, N >& data)
{
for (size_t i = 0; i < N; i++)
{
data[i] ^= sequence[i];
}
}
#endif /* M17_DECORRELATOR_H */

View File

@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* Adapted from original code written by Rob Riggs, Mobilinkd LLC *
* *
* 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/> *
***************************************************************************/
#ifndef M17_GOLAY_H
#define M17_GOLAY_H
#ifndef __cplusplus
#error This header is C++ only!
#endif
#include <cstdint>
/**
* Compute the Golay(24,12) codeword of a given block of data using the M17
* Golay polynomial.
* Result is composed as follows:
*
* +--------+----------+--------+
* | parity | checksum | data |
* +--------+----------+--------+
* | 1 bit | 11 bit | 12 bit |
* +--------+----------+--------+
*
* \param data: input data, upper four bits are discarded.
* \return resulting 24 bit codeword.
*/
static uint32_t golay_encode24(const uint16_t& data)
{
// Compute [23,12] Golay codeword
uint32_t codeword = data & 0x0FFFF;
for(size_t i = 0; i < 12; i++)
{
if(codeword & 0x01) codeword ^= 0x0C75;
codeword >>= 1;
}
// Append data to codeword, result is checkbits(11) | data(12)
codeword |= (data << 11);
// Compute parity and append it to codeword
return (codeword << 1) | (__builtin_popcount(codeword) & 0x01);
}
#endif /* M17_GOLAY_H */

View File

@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* Adapted from original code written by Rob Riggs, Mobilinkd LLC *
* *
* 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/> *
***************************************************************************/
#ifndef M17_INTERLEAVER_H
#define M17_INTERLEAVER_H
#ifndef __cplusplus
#error This header is C++ only!
#endif
#include "M17Utils.h"
/**
* Interleave a block of data using the quadratic permutation polynomial from
* M17 protocol specification. Polynomial used is P(x) = 45*x + 92*x^2.
*
* \param data: input byte array.
*/
template < size_t N >
void interleave(std::array< uint8_t, N >& data)
{
std::array< uint8_t, N > interleaved;
static constexpr size_t F1 = 45;
static constexpr size_t F2 = 92;
static constexpr size_t NB = N*8;
for(size_t i = 0; i < NB; i++)
{
size_t index = ((F1 * i) + (F2 * i * i)) % NB;
setBit(interleaved, index, getBit(data, i));
}
std::copy(interleaved.begin(), interleaved.end(), data.begin());
}
#endif /* M17_INTERLEAVER_H */