mirror of
https://github.com/aicodix/modem.git
synced 2026-04-27 14:30:34 +00:00
renamed to make room for new preamble
This commit is contained in:
parent
92a4213b5f
commit
675ee7b024
3 changed files with 62 additions and 62 deletions
18
common.hh
18
common.hh
|
|
@ -22,20 +22,20 @@ struct Common
|
|||
static const int mls1_poly = 0x43;
|
||||
static const int mls2_poly = 0x163;
|
||||
static const int data_tones = 256;
|
||||
static const int meta_tones = 32;
|
||||
static const int seed_tones = 32;
|
||||
static const int tone_count = data_tones + meta_tones + seed_tones;
|
||||
static const int head_tones = 32;
|
||||
static const int tail_tones = 32;
|
||||
static const int tone_count = data_tones + head_tones + tail_tones;
|
||||
static const int block_length = 10;
|
||||
static const int block_skew = 3;
|
||||
static const int first_meta = 4;
|
||||
static const int first_seed = 9;
|
||||
static const int first_head = 4;
|
||||
static const int first_tail = 9;
|
||||
static constexpr int slm_poly[16] = {
|
||||
0x11d, 0x12b, 0x12d, 0x14d, 0x15f, 0x163, 0x165, 0x169,
|
||||
0x171, 0x187, 0x18d, 0x1a9, 0x1c3, 0x1cf, 0x1e7, 0x1f5 };
|
||||
CODE::CRC<uint32_t> crc0;
|
||||
CODE::HadamardEncoder<6> hadamard_encoder;
|
||||
int8_t meta[32];
|
||||
int8_t seed[32];
|
||||
int8_t head[32];
|
||||
int8_t tail[32];
|
||||
uint8_t data[data_max];
|
||||
const uint32_t *frozen_bits;
|
||||
int mod_bits;
|
||||
|
|
@ -44,8 +44,8 @@ struct Common
|
|||
int code_order;
|
||||
int oper_mode;
|
||||
int tone_off;
|
||||
int meta_off;
|
||||
int seed_off;
|
||||
int head_off;
|
||||
int tail_off;
|
||||
int symbol_count;
|
||||
bool differential;
|
||||
|
||||
|
|
|
|||
84
decode.cc
84
decode.cc
|
|
@ -230,16 +230,16 @@ struct Decoder : Common
|
|||
fwd(fdom, tdom);
|
||||
CODE::MLS seq1(mls1_poly);
|
||||
auto clamp = [](int v){ return v < -127 ? -127 : v > 127 ? 127 : v; };
|
||||
for (int i = 0; i < meta_tones; ++i) {
|
||||
meta[i] = clamp(std::nearbyint(127 * demod_or_erase(fdom[bin(i*block_length+first_meta+tone_off)], chan[i*block_length+first_meta]).real() * nrz(seq1())));
|
||||
for (int i = 0; i < head_tones; ++i) {
|
||||
head[i] = clamp(std::nearbyint(127 * demod_or_erase(fdom[bin(i*block_length+first_head+tone_off)], chan[i*block_length+first_head]).real() * nrz(seq1())));
|
||||
seq1();
|
||||
}
|
||||
int meta_data = hadamard_decoder(meta);
|
||||
if (meta_data < 0) {
|
||||
std::cerr << "meta data damaged" << std::endl;
|
||||
int head_data = hadamard_decoder(head);
|
||||
if (head_data < 0) {
|
||||
std::cerr << "head data damaged" << std::endl;
|
||||
continue;
|
||||
}
|
||||
setup(meta_data >> 3);
|
||||
setup(head_data >> 3);
|
||||
std::cerr << "oper mode: " << oper_mode << std::endl;
|
||||
if (oper_mode >= 3) {
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
|
|
@ -248,8 +248,8 @@ struct Decoder : Common
|
|||
chan[i] = DSP::lerp(chan[i], tone[i], value(0.5));
|
||||
}
|
||||
for (int j = 0, k = 0; j < symbol_count; ++j) {
|
||||
meta_off = (block_skew * j + first_meta) % block_length;
|
||||
seed_off = (block_skew * j + first_seed) % block_length;
|
||||
head_off = (block_skew * j + first_head) % block_length;
|
||||
tail_off = (block_skew * j + first_tail) % block_length;
|
||||
if (j) {
|
||||
for (int i = 0; i < extended_len; ++i)
|
||||
correlator(buf = next_sample());
|
||||
|
|
@ -268,43 +268,43 @@ struct Decoder : Common
|
|||
for (int i = 0; i < tone_count; ++i)
|
||||
tone[i] = fdom[bin(i+tone_off)];
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
if (i % block_length == meta_off || i % block_length == seed_off)
|
||||
if (i % block_length == head_off || i % block_length == tail_off)
|
||||
tone[i] *= nrz(seq1());
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
demod[i] = demod_or_erase(tone[i], chan[i]);
|
||||
for (int i = 0; i < meta_tones; ++i)
|
||||
meta[i] = clamp(std::nearbyint(127 * demod[i*block_length+meta_off].real()));
|
||||
int meta_data = hadamard_decoder(meta);
|
||||
if (meta_data < 0) {
|
||||
std::cerr << "meta data damaged" << std::endl;
|
||||
meta_data = 0;
|
||||
for (int i = 0; i < head_tones; ++i)
|
||||
head[i] = clamp(std::nearbyint(127 * demod[i*block_length+head_off].real()));
|
||||
int head_data = hadamard_decoder(head);
|
||||
if (head_data < 0) {
|
||||
std::cerr << "head data damaged" << std::endl;
|
||||
head_data = 0;
|
||||
}
|
||||
hadamard_encoder(meta, meta_data);
|
||||
for (int i = 0; i < meta_tones; ++i) {
|
||||
tone[block_length*i+meta_off] *= meta[i];
|
||||
demod[block_length*i+meta_off] *= meta[i];
|
||||
hadamard_encoder(head, head_data);
|
||||
for (int i = 0; i < head_tones; ++i) {
|
||||
tone[block_length*i+head_off] *= head[i];
|
||||
demod[block_length*i+head_off] *= head[i];
|
||||
}
|
||||
for (int i = 0; i < meta_tones; ++i) {
|
||||
index[i] = tone_off + block_length * i + meta_off;
|
||||
phase[i] = arg(demod[block_length*i+meta_off]);
|
||||
for (int i = 0; i < head_tones; ++i) {
|
||||
index[i] = tone_off + block_length * i + head_off;
|
||||
phase[i] = arg(demod[block_length*i+head_off]);
|
||||
}
|
||||
for (int i = 0; i < seed_tones; ++i)
|
||||
seed[i] = clamp(std::nearbyint(127 * demod[i*block_length+seed_off].real()));
|
||||
int seed_data = hadamard_decoder(seed);
|
||||
if (seed_data < 0) {
|
||||
std::cerr << "seed data damaged" << std::endl;
|
||||
seed_data = 0;
|
||||
for (int i = 0; i < tail_tones; ++i)
|
||||
tail[i] = clamp(std::nearbyint(127 * demod[i*block_length+tail_off].real()));
|
||||
int tail_data = hadamard_decoder(tail);
|
||||
if (tail_data < 0) {
|
||||
std::cerr << "tail data damaged" << std::endl;
|
||||
tail_data = 0;
|
||||
}
|
||||
hadamard_encoder(seed, seed_data);
|
||||
for (int i = 0; i < seed_tones; ++i) {
|
||||
tone[block_length*i+seed_off] *= seed[i];
|
||||
demod[block_length*i+seed_off] *= seed[i];
|
||||
hadamard_encoder(tail, tail_data);
|
||||
for (int i = 0; i < tail_tones; ++i) {
|
||||
tone[block_length*i+tail_off] *= tail[i];
|
||||
demod[block_length*i+tail_off] *= tail[i];
|
||||
}
|
||||
for (int i = 0; i < seed_tones; ++i) {
|
||||
index[i+meta_tones] = tone_off + block_length * i + seed_off;
|
||||
phase[i+meta_tones] = arg(demod[block_length*i+seed_off]);
|
||||
for (int i = 0; i < tail_tones; ++i) {
|
||||
index[i+head_tones] = tone_off + block_length * i + tail_off;
|
||||
phase[i+head_tones] = arg(demod[block_length*i+tail_off]);
|
||||
}
|
||||
tse.compute(index, phase, meta_tones + seed_tones);
|
||||
tse.compute(index, phase, head_tones + tail_tones);
|
||||
//std::cerr << "Theil-Sen slope = " << tse.slope() << std::endl;
|
||||
//std::cerr << "Theil-Sen yint = " << tse.yint() << std::endl;
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
|
|
@ -315,13 +315,13 @@ struct Decoder : Common
|
|||
for (int i = 0; i < tone_count; ++i)
|
||||
chan[i] = fdom[bin(i+tone_off)];
|
||||
} else {
|
||||
for (int i = meta_off; i < tone_count; i += block_length)
|
||||
for (int i = head_off; i < tone_count; i += block_length)
|
||||
chan[i] = DSP::lerp(chan[i], tone[i], value(0.5));
|
||||
for (int i = seed_off; i < tone_count; i += block_length)
|
||||
for (int i = tail_off; i < tone_count; i += block_length)
|
||||
chan[i] = DSP::lerp(chan[i], tone[i], value(0.5));
|
||||
}
|
||||
CODE::XorShiftMask<int, 14, 1, 5, 10, 1> combination;
|
||||
int trial = j ? (meta_data << 6) | seed_data : (meta_data & 7) << 6 | seed_data;
|
||||
int trial = j ? (head_data << 6) | tail_data : (head_data & 7) << 6 | tail_data;
|
||||
int comb = 0;
|
||||
for (int i = 0; i <= trial; ++i)
|
||||
comb = combination();
|
||||
|
|
@ -331,12 +331,12 @@ struct Decoder : Common
|
|||
std::cerr << "reserved seed value detected" << std::endl;
|
||||
CODE::MLS seq(slm_poly[poly_index], seed_value);
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
if (i % block_length != meta_off && i % block_length != seed_off)
|
||||
if (i % block_length != head_off && i % block_length != tail_off)
|
||||
demod[i] *= nrz(seq());
|
||||
value sp = 0, np = 0;
|
||||
for (int i = 0, l = k; i < tone_count; ++i) {
|
||||
cmplx hard(1, 0);
|
||||
if (i % block_length != meta_off && i % block_length != seed_off) {
|
||||
if (i % block_length != head_off && i % block_length != tail_off) {
|
||||
int bits = mod_bits;
|
||||
if (oper_mode == 2 && l % 32 == 30)
|
||||
bits = 2;
|
||||
|
|
@ -354,7 +354,7 @@ struct Decoder : Common
|
|||
snr[j] = precision;
|
||||
precision = std::min(precision, value(127));
|
||||
for (int i = 0; i < tone_count; ++i) {
|
||||
if (i % block_length != meta_off && i % block_length != seed_off) {
|
||||
if (i % block_length != head_off && i % block_length != tail_off) {
|
||||
int bits = mod_bits;
|
||||
if (oper_mode == 2 && k % 32 == 30)
|
||||
bits = 2;
|
||||
|
|
|
|||
22
encode.cc
22
encode.cc
|
|
@ -89,20 +89,20 @@ struct Encoder : public Common
|
|||
temp[i] = tone[i];
|
||||
if (symbol_number >= 0) {
|
||||
int comb = combination();
|
||||
int meta_data = symbol_number ? trial >> 6 : (oper_mode << 3) | (trial >> 6);
|
||||
hadamard_encoder(meta, meta_data);
|
||||
int seed_data = trial & 63;
|
||||
hadamard_encoder(seed, seed_data);
|
||||
int head_data = symbol_number ? trial >> 6 : (oper_mode << 3) | (trial >> 6);
|
||||
hadamard_encoder(head, head_data);
|
||||
int tail_data = trial & 63;
|
||||
hadamard_encoder(tail, tail_data);
|
||||
int poly_index = comb & 15;
|
||||
int seed_value = comb >> 4;
|
||||
if (seed_value == 0)
|
||||
continue;
|
||||
CODE::MLS seq(slm_poly[poly_index], seed_value);
|
||||
for (int i = 0, m = 0, s = 0; i < tone_count; ++i)
|
||||
if (i % block_length == meta_off)
|
||||
temp[i] *= meta[m++];
|
||||
else if (i % block_length == seed_off)
|
||||
temp[i] *= seed[s++];
|
||||
if (i % block_length == head_off)
|
||||
temp[i] *= head[m++];
|
||||
else if (i % block_length == tail_off)
|
||||
temp[i] *= tail[s++];
|
||||
else
|
||||
temp[i] *= nrz(seq());
|
||||
}
|
||||
|
|
@ -282,10 +282,10 @@ struct Encoder : public Common
|
|||
shuffle(perm, code, code_order);
|
||||
CODE::MLS seq1(mls1_poly);
|
||||
for (int j = 0, k = 0; j < symbol_count; ++j) {
|
||||
meta_off = (block_skew * j + first_meta) % block_length;
|
||||
seed_off = (block_skew * j + first_seed) % block_length;
|
||||
head_off = (block_skew * j + first_head) % block_length;
|
||||
tail_off = (block_skew * j + first_tail) % block_length;
|
||||
for (int i = 0; i < tone_count; ++i) {
|
||||
if (i % block_length == meta_off || i % block_length == seed_off) {
|
||||
if (i % block_length == head_off || i % block_length == tail_off) {
|
||||
tone[i] = nrz(seq1());
|
||||
} else {
|
||||
int bits = mod_bits;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue