Implementation of M17 polynomial deinterleaver

replace/f20c326f1b4a02e47512196829e04c803fe58a3f
Silvano Seva 2021-09-20 21:34:59 +02:00
rodzic f2f013f5a5
commit d018dbb4a0
1 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -53,4 +53,29 @@ void interleave(std::array< uint8_t, N >& data)
std::copy(interleaved.begin(), interleaved.end(), data.begin());
}
/**
* Perform the deinterleaving operation on a block of data previously interleaved
* 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 deinterleave(std::array< uint8_t, N >& data)
{
std::array< uint8_t, N > deinterleaved;
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(deinterleaved, i, getBit(data, index));
}
std::copy(deinterleaved.begin(), deinterleaved.end(), data.begin());
}
#endif /* M17_INTERLEAVER_H */