From a9e221adf1d63144fc04e82d704acc92436bee02 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 12 May 2023 09:42:19 +0200 Subject: [PATCH] added bpsk and qpsk types to reduce code --- decode.cc | 27 ++++++++------------------- encode.cc | 8 ++------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/decode.cc b/decode.cc index b839692..4b19b9a 100644 --- a/decode.cc +++ b/decode.cc @@ -167,9 +167,10 @@ struct Decoder typedef SIMD mesg_type; #endif typedef DSP::Const Const; + typedef PhaseShiftKeying<2, cmplx, code_type> bpsk; + typedef PhaseShiftKeying<4, cmplx, code_type> qpsk; static const int sample_rate = 8000; static const int code_order = 12; - static const int mod_bits = 2; static const int code_len = 1 << code_order; static const int meta_len = 63; static const int symbol_len = 256; @@ -236,18 +237,6 @@ struct Decoder if (!((frozen_bits[i/32] >> (i%32)) & 1)) mesg[j++] = mess[i]; } - cmplx mod_map(code_type *b) - { - return PhaseShiftKeying<4, cmplx, code_type>::map(b); - } - void mod_hard(code_type *b, cmplx c) - { - PhaseShiftKeying<4, cmplx, code_type>::hard(b, c); - } - void mod_soft(code_type *b, cmplx c, value precision) - { - PhaseShiftKeying<4, cmplx, code_type>::soft(b, c, precision); - } const cmplx *next_sample() { value real; @@ -290,7 +279,7 @@ struct Decoder for (int i = 0; i < subcarrier_count; ++i) prev[i] = fdom[bin(i)]; for (int i = 0; i < meta_len; ++i) - code[i] = DSP::clamp(16 * cons[i].real(), -127, 127); + bpsk::soft(code+i, cons[i], 8); CODE::MLS seq(0b1000011); for (int i = 0; i < meta_len; ++i) code[i] *= nrz(seq()); @@ -327,9 +316,9 @@ struct Decoder value sp = 0, np = 0; for (int j = 0; j < payload_symbols; ++j) { for (int i = 0; i < subcarrier_count; ++i) { - code_type tmp[mod_bits]; - mod_hard(tmp, cons[subcarrier_count*j+i]); - cmplx hard = mod_map(tmp); + code_type tmp[2]; + qpsk::hard(tmp, cons[subcarrier_count*j+i]); + cmplx hard = qpsk::map(tmp); cmplx error = cons[subcarrier_count*j+i] - hard; sp += norm(hard); np += norm(error); @@ -338,13 +327,13 @@ struct Decoder value snr = DSP::decibel(precision); std::cerr << " " << snr; for (int i = 0; i < subcarrier_count; ++i) - mod_soft(code+mod_bits*(subcarrier_count*j+i), cons[subcarrier_count*j+i], precision); + qpsk::soft(code+2*(subcarrier_count*j+i), cons[subcarrier_count*j+i], precision); } std::cerr << std::endl; } else { value precision = 8; for (int i = 0; i < cons_total; ++i) - mod_soft(code+mod_bits*i, cons[i], precision); + qpsk::soft(code+2*i, cons[i], precision); } CODE::PolarHelper::PATH metric[mesg_type::SIZE]; shuffle(code); diff --git a/encode.cc b/encode.cc index 6a9e9c3..fed1426 100644 --- a/encode.cc +++ b/encode.cc @@ -29,7 +29,7 @@ struct Encoder typedef float value; typedef DSP::Complex cmplx; typedef int8_t code_type; - static const int mod_bits = 2; + typedef PhaseShiftKeying<4, cmplx, code_type> qpsk; static const int code_order = 12; static const int code_len = 1 << code_order; static const int meta_len = 63; @@ -102,10 +102,6 @@ struct Encoder fdom[first_subcarrier+1+i] = fdom[first_subcarrier+i] * cmplx(code[i] * nrz(seq())); symbol(); } - cmplx mod_map(code_type *b) - { - return PhaseShiftKeying<4, cmplx, code_type>::map(b); - } Encoder(DSP::WritePCM *pcm, const uint8_t *inp) : pcm(pcm), crc(0x8F6E37A0) { leading_noise(); @@ -123,7 +119,7 @@ struct Encoder for (int j = 0; j < payload_symbols; ++j) { for (int i = 0; i < subcarrier_count; ++i) fdom[first_subcarrier+i] *= - mod_map(code+mod_bits*(subcarrier_count*j+i)); + qpsk::map(code+2*(subcarrier_count*j+i)); symbol(); } for (int i = 0; i < symbol_len; ++i)