From 69ebf0ea296c82dd995d35d0c3e184a3ce9a7e7d Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Wed, 2 Jul 2025 07:05:20 +0200 Subject: [PATCH] made offsets accessible to other methods --- decode.cc | 28 +++++++++++++++------------- encode.cc | 22 ++++++++++++---------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/decode.cc b/decode.cc index 376a872..d8ba084 100644 --- a/decode.cc +++ b/decode.cc @@ -56,8 +56,8 @@ struct Decoder static const int data_tones = 256; static const int block_length = 10; static const int block_skew = 3; - static const int pilot_offset = 4; - static const int reserved_offset = 9; + static const int first_pilot = 4; + static const int first_reserved = 9; static const int tone_count = data_tones + pilot_tones + reserved_tones; static const int tone_off = - tone_count / 2; static const int tones_max = tone_count * symbols_max; @@ -87,6 +87,8 @@ struct Decoder int crc_bits; int data_bits; int data_bytes; + int pilot_off; + int reserved_off; int symbol_count; static int bin(int carrier) @@ -321,7 +323,7 @@ struct Decoder CODE::MLS seq1(mls1_poly); auto clamp = [](int v){ return v < -127 ? -127 : v > 127 ? 127 : v; }; for (int i = 0; i < pilot_tones; ++i) - mode[i] = clamp(std::nearbyint(127 * demod_or_erase(tone[i*block_length+pilot_offset], chan[i*block_length+pilot_offset]).real() * nrz(seq1()))); + mode[i] = clamp(std::nearbyint(127 * demod_or_erase(tone[i*block_length+first_pilot], chan[i*block_length+first_pilot]).real() * nrz(seq1()))); int oper_mode = hadamarddec(mode); if (oper_mode < 0 || oper_mode > 15) { std::cerr << "operation mode " << oper_mode << " unsupported." << std::endl; @@ -349,14 +351,14 @@ struct Decoder seq1.reset(); hadamardenc(mode, oper_mode); } - int poff = (block_skew * j + pilot_offset) % block_length; + pilot_off = (block_skew * j + first_pilot) % block_length; for (int i = 0; i < pilot_tones; ++i) - tone[block_length*i+poff] *= nrz(seq1()) * mode[i]; + tone[block_length*i+pilot_off] *= nrz(seq1()) * mode[i]; for (int i = 0; i < tone_count; ++i) demod[tone_count*j+i] = demod_or_erase(tone[i], chan[i]); for (int i = 0; i < pilot_tones; ++i) { - index[i] = tone_off + block_length * i + poff; - phase[i] = arg(demod[tone_count*j+block_length*i+poff]); + index[i] = tone_off + block_length * i + pilot_off; + phase[i] = arg(demod[tone_count*j+block_length*i+pilot_off]); } tse.compute(index, phase, pilot_tones); //std::cerr << "Theil-Sen slope = " << tse.slope() << std::endl; @@ -364,7 +366,7 @@ struct Decoder for (int i = 0; i < tone_count; ++i) demod[tone_count*j+i] *= DSP::polar(1, -tse(i+tone_off)); for (int i = 0; i < tone_count; ++i) - if (i % block_length == poff) + if (i % block_length == pilot_off) chan[i] = tone[i]; else chan[i] *= DSP::polar(1, tse(i+tone_off)); @@ -374,11 +376,11 @@ struct Decoder std::cerr << "Es/N0 (dB):"; value sp = 0, np = 0; for (int j = 0, k = 0; j < symbol_count; ++j) { - int poff = (block_skew * j + pilot_offset) % block_length; - int roff = (block_skew * j + reserved_offset) % block_length; + pilot_off = (block_skew * j + first_pilot) % block_length; + reserved_off = (block_skew * j + first_reserved) % block_length; for (int i = 0; i < pilot_tones; ++i) { cmplx hard(1, 0); - cmplx error = demod[tone_count*j+block_length*i+poff] - hard; + cmplx error = demod[tone_count*j+block_length*i+pilot_off] - hard; sp += norm(hard); np += norm(error); } @@ -386,9 +388,9 @@ struct Decoder value snr = DSP::decibel(precision); std::cerr << " " << snr; for (int i = 0; i < tone_count; ++i) { - if (i % block_length == poff) + if (i % block_length == pilot_off) continue; - if (i % block_length == roff) + if (i % block_length == reserved_off) continue; int bits = mod_bits; if (oper_mode >= 9 && oper_mode <= 11 && k % 64 == 60) diff --git a/encode.cc b/encode.cc index 48af458..110c713 100644 --- a/encode.cc +++ b/encode.cc @@ -40,8 +40,8 @@ struct Encoder static const int tone_count = data_tones + pilot_tones + reserved_tones; static const int block_length = 10; static const int block_skew = 3; - static const int pilot_offset = 4; - static const int reserved_offset = 9; + static const int first_pilot = 4; + static const int first_reserved = 9; DSP::WritePCM *pcm; DSP::FastFourierTransform fwd; DSP::FastFourierTransform bwd; @@ -65,6 +65,8 @@ struct Encoder int data_bytes; int code_order; int tone_off; + int pilot_off; + int reserved_off; int symbol_count; static int bin(int carrier) @@ -344,13 +346,13 @@ struct Encoder int offset = (freq_off * symbol_len) / rate; tone_off = offset - tone_count / 2; } - void tone_reservation_kernel(int roff) + void tone_reservation_kernel() { value mag = 1 / value(10 * reserved_tones); for (int i = 0; i < symbol_len; ++i) temp[i] = 0; for (int i = 0; i < reserved_tones; ++i) - temp[bin(i*block_length+tone_off+roff)] = mag; + temp[bin(i*block_length+tone_off+reserved_off)] = mag; bwd(kern, temp); } void guard_interval_weights() @@ -376,7 +378,7 @@ struct Encoder schmidl_cox(); CODE::MLS seq1(mls1_poly); for (int i = 0, m = 0; i < tone_count; ++i) { - if (i % block_length == pilot_offset) { + if (i % block_length == first_pilot) { tone[i] = nrz(seq1()) * mode[m++]; } else { tone[i] = 0; @@ -410,12 +412,12 @@ struct Encoder shuffle(perm, code); CODE::MLS seq1(mls1_poly); for (int j = 0, k = 0; j < symbol_count; ++j) { - int poff = (block_skew * j + pilot_offset) % block_length; - int roff = (block_skew * j + reserved_offset) % block_length; + pilot_off = (block_skew * j + first_pilot) % block_length; + reserved_off = (block_skew * j + first_reserved) % block_length; for (int i = 0, m = 0; i < tone_count; ++i) { - if (i % block_length == poff) { + if (i % block_length == pilot_off) { tone[i] = nrz(seq1()) * mode[m++]; - } else if (i % block_length == roff) { + } else if (i % block_length == reserved_off) { tone[i] = 0; } else { int bits = mod_bits; @@ -425,7 +427,7 @@ struct Encoder k += bits; } } - tone_reservation_kernel(roff); + tone_reservation_kernel(); symbol(); } }