diff --git a/common.hh b/common.hh index cbba5ab..f7cc1f7 100644 --- a/common.hh +++ b/common.hh @@ -12,7 +12,7 @@ Copyright 2025 Ahmet Inan struct Common { - static const int mod_max = 8; + static const int mod_max = 12; static const int code_max = 16; static const int bits_max = 1 << code_max; static const int data_max = 4096; diff --git a/decode.cc b/decode.cc index a59156e..b47c2a9 100644 --- a/decode.cc +++ b/decode.cc @@ -105,6 +105,8 @@ struct Decoder : Common return QuadratureAmplitudeModulation<256, cmplx, code_type>::map(b); case 10: return QuadratureAmplitudeModulation<1024, cmplx, code_type>::map(b); + case 12: + return QuadratureAmplitudeModulation<4096, cmplx, code_type>::map(b); } return 0; } @@ -125,6 +127,8 @@ struct Decoder : Common return QuadratureAmplitudeModulation<256, cmplx, code_type>::soft(b, c, precision); case 10: return QuadratureAmplitudeModulation<1024, cmplx, code_type>::soft(b, c, precision); + case 12: + return QuadratureAmplitudeModulation<4096, cmplx, code_type>::soft(b, c, precision); } } void demap_hard(code_type *b, cmplx c, int bits) @@ -144,6 +148,8 @@ struct Decoder : Common return QuadratureAmplitudeModulation<256, cmplx, code_type>::hard(b, c); case 10: return QuadratureAmplitudeModulation<1024, cmplx, code_type>::hard(b, c); + case 12: + return QuadratureAmplitudeModulation<4096, cmplx, code_type>::hard(b, c); } } void shuffle(code_type *dest, const code_type *src, int order) diff --git a/encode.cc b/encode.cc index 499a4f3..9c7c0e5 100644 --- a/encode.cc +++ b/encode.cc @@ -200,6 +200,8 @@ struct Encoder : public Common return QuadratureAmplitudeModulation<256, cmplx, code_type>::map(b); case 10: return QuadratureAmplitudeModulation<1024, cmplx, code_type>::map(b); + case 12: + return QuadratureAmplitudeModulation<4096, cmplx, code_type>::map(b); } return 0; } @@ -220,6 +222,8 @@ struct Encoder : public Common return QuadratureAmplitudeModulation<256, cmplx, code_type>::DIST; case 10: return QuadratureAmplitudeModulation<1024, cmplx, code_type>::DIST; + case 12: + return QuadratureAmplitudeModulation<4096, cmplx, code_type>::DIST; } return 2; } diff --git a/qam.hh b/qam.hh index 4efbf9c..956f35b 100644 --- a/qam.hh +++ b/qam.hh @@ -258,5 +258,77 @@ struct QuadratureAmplitudeModulation<1024, TYPE, CODE> } }; +template +struct QuadratureAmplitudeModulation<4096, TYPE, CODE> +{ + static const int NUM = 4096; + static const int BITS = 12; + typedef TYPE complex_type; + typedef typename TYPE::value_type value_type; + typedef CODE code_type; + + static constexpr value_type FAC = 0.8293555858802010; + static constexpr value_type RCP = 63 * FAC; + static constexpr value_type AMP = 1 / RCP; + static constexpr value_type DIST = 2 * AMP; + + static constexpr value_type amp(int i) + { + return AMP * i; + } + + static code_type quantize(value_type precision, value_type value) + { + value *= DIST * precision; + if (std::is_integral::value) + value = std::nearbyint(value); + if (std::is_same::value) + value = std::min(std::max(value, -127), 127); + if (std::is_same::value) + value = std::min(std::max(value, -32767), 32767); + return value; + } + + static void hard(code_type *b, complex_type c) + { + b[ 0] = c.real() < amp(0) ? code_type(-1) : code_type(1); + b[ 1] = c.imag() < amp(0) ? code_type(-1) : code_type(1); + b[ 2] = std::abs(c.real()) < amp(32) ? code_type(-1) : code_type(1); + b[ 3] = std::abs(c.imag()) < amp(32) ? code_type(-1) : code_type(1); + b[ 4] = std::abs(std::abs(c.real())-amp(32)) < amp(16) ? code_type(-1) : code_type(1); + b[ 5] = std::abs(std::abs(c.imag())-amp(32)) < amp(16) ? code_type(-1) : code_type(1); + b[ 6] = std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16)) < amp(8) ? code_type(-1) : code_type(1); + b[ 7] = std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16)) < amp(8) ? code_type(-1) : code_type(1); + b[ 8] = std::abs(std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16))-amp(8)) < amp(4) ? code_type(-1) : code_type(1); + b[ 9] = std::abs(std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16))-amp(8)) < amp(4) ? code_type(-1) : code_type(1); + b[10] = std::abs(std::abs(std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16))-amp(8))-amp(4)) < amp(2) ? code_type(-1) : code_type(1); + b[11] = std::abs(std::abs(std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16))-amp(8))-amp(4)) < amp(2) ? code_type(-1) : code_type(1); + } + + static void soft(code_type *b, complex_type c, value_type precision) + { + b[ 0] = quantize(precision, c.real()); + b[ 1] = quantize(precision, c.imag()); + b[ 2] = quantize(precision, std::abs(c.real())-amp(32)); + b[ 3] = quantize(precision, std::abs(c.imag())-amp(32)); + b[ 4] = quantize(precision, std::abs(std::abs(c.real())-amp(32))-amp(16)); + b[ 5] = quantize(precision, std::abs(std::abs(c.imag())-amp(32))-amp(16)); + b[ 6] = quantize(precision, std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16))-amp(8)); + b[ 7] = quantize(precision, std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16))-amp(8)); + b[ 8] = quantize(precision, std::abs(std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16))-amp(8))-amp(4)); + b[ 9] = quantize(precision, std::abs(std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16))-amp(8))-amp(4)); + b[10] = quantize(precision, std::abs(std::abs(std::abs(std::abs(std::abs(c.real())-amp(32))-amp(16))-amp(8))-amp(4))-amp(2)); + b[11] = quantize(precision, std::abs(std::abs(std::abs(std::abs(std::abs(c.imag())-amp(32))-amp(16))-amp(8))-amp(4))-amp(2)); + } + + static complex_type map(code_type *b) + { + return AMP * complex_type( + b[0]*(b[2]*(b[4]*(b[6]*(b[8]*(b[10]+value_type(2))+value_type(4))+value_type(8))+value_type(16))+value_type(32)), + b[1]*(b[3]*(b[5]*(b[7]*(b[9]*(b[11]+value_type(2))+value_type(4))+value_type(8))+value_type(16))+value_type(32)) + ); + } +}; + #endif