mirror of
https://github.com/aicodix/modem.git
synced 2026-04-27 14:30:34 +00:00
use only one polynomial for scrambling
This commit is contained in:
parent
16b5f7e5c9
commit
f816ebbc43
3 changed files with 41 additions and 51 deletions
13
common.hh
13
common.hh
|
|
@ -22,18 +22,15 @@ struct Common
|
|||
static const int mls1_poly = 0x43;
|
||||
static const int mls2_poly = 0x163;
|
||||
static const int data_tones = 256;
|
||||
static const int side_tones = 64;
|
||||
static const int tone_count = data_tones + side_tones;
|
||||
static const int seed_tones = 64;
|
||||
static const int tone_count = data_tones + seed_tones;
|
||||
static const int block_length = 5;
|
||||
static const int block_skew = 3;
|
||||
static const int first_side = 4;
|
||||
static constexpr int slm_poly[16] = {
|
||||
0x11d, 0x12b, 0x12d, 0x14d, 0x15f, 0x163, 0x165, 0x169,
|
||||
0x171, 0x187, 0x18d, 0x1a9, 0x1c3, 0x1cf, 0x1e7, 0x1f5 };
|
||||
static const int first_seed = 4;
|
||||
CODE::CRC<uint16_t> crc0;
|
||||
CODE::CRC<uint32_t> crc1;
|
||||
CODE::HadamardEncoder<7> hadamard_encoder;
|
||||
int8_t side[side_tones];
|
||||
int8_t seed[seed_tones];
|
||||
uint8_t data[data_max];
|
||||
const uint32_t *frozen_bits;
|
||||
int mod_bits;
|
||||
|
|
@ -42,7 +39,7 @@ struct Common
|
|||
int code_order;
|
||||
int oper_mode;
|
||||
int tone_off;
|
||||
int side_off;
|
||||
int seed_off;
|
||||
int symbol_count;
|
||||
|
||||
Common() : crc0(0xA8F4), crc1(0x8F6E37A0) {}
|
||||
|
|
|
|||
49
decode.cc
49
decode.cc
|
|
@ -283,7 +283,7 @@ struct Decoder : Common
|
|||
oper_mode = -1;
|
||||
symbol_count = 0;
|
||||
for (int j = 0, k = 0; j < symbol_count + 1; ++j) {
|
||||
side_off = (block_skew * j + first_side) % block_length;
|
||||
seed_off = (block_skew * j + first_seed) % block_length;
|
||||
if (j) {
|
||||
for (int i = 0; i < extended_len; ++i)
|
||||
correlator(buf = next_sample());
|
||||
|
|
@ -295,49 +295,44 @@ struct Decoder : Common
|
|||
}
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
tone[i] = fdom[bin(i+tone_off)];
|
||||
for (int i = side_off; i < tone_count; i += block_length)
|
||||
for (int i = seed_off; i < tone_count; i += block_length)
|
||||
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 < side_tones; ++i)
|
||||
side[i] = clamp(std::nearbyint(127 * demod[i*block_length+side_off].real()));
|
||||
int side_info = hadamard_decoder(side);
|
||||
if (side_info < 0) {
|
||||
std::cerr << "side info damaged" << std::endl;
|
||||
for (int i = 0; i < seed_tones; ++i)
|
||||
seed[i] = clamp(std::nearbyint(127 * demod[i*block_length+seed_off].real()));
|
||||
int seed_value = hadamard_decoder(seed);
|
||||
if (seed_value < 0) {
|
||||
std::cerr << "seed value damaged" << std::endl;
|
||||
oper_mode = -1;
|
||||
break;
|
||||
}
|
||||
hadamard_encoder(side, side_info);
|
||||
for (int i = 0; i < side_tones; ++i) {
|
||||
tone[block_length*i+side_off] *= side[i];
|
||||
demod[block_length*i+side_off] *= side[i];
|
||||
hadamard_encoder(seed, seed_value);
|
||||
for (int i = 0; i < seed_tones; ++i) {
|
||||
tone[block_length*i+seed_off] *= seed[i];
|
||||
demod[block_length*i+seed_off] *= seed[i];
|
||||
}
|
||||
for (int i = 0; i < side_tones; ++i) {
|
||||
index[i] = tone_off + block_length * i + side_off;
|
||||
phase[i] = arg(demod[block_length*i+side_off]);
|
||||
for (int i = 0; i < seed_tones; ++i) {
|
||||
index[i] = tone_off + block_length * i + seed_off;
|
||||
phase[i] = arg(demod[block_length*i+seed_off]);
|
||||
}
|
||||
tse.compute(index, phase, side_tones);
|
||||
tse.compute(index, phase, seed_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)
|
||||
demod[i] *= DSP::polar<value>(1, -tse(i+tone_off));
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
chan[i] *= DSP::polar<value>(1, tse(i+tone_off));
|
||||
CODE::XorShiftMask<int, 14, 1, 5, 10, 50> combination;
|
||||
int trial = side_info;
|
||||
int comb = 0;
|
||||
for (int i = 0; i <= trial; ++i)
|
||||
comb = combination();
|
||||
int poly_index = comb & 15;
|
||||
int seed_value = comb >> 4;
|
||||
CODE::MLS seq(slm_poly[poly_index], seed_value);
|
||||
if (seed_value) {
|
||||
CODE::MLS seq(mls2_poly, seed_value);
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
if (i % block_length != side_off)
|
||||
if (i % block_length != seed_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 != side_off) {
|
||||
if (i % block_length != seed_off) {
|
||||
int bits = mod_bits;
|
||||
if (mod_bits == 3 && l % 32 == 30)
|
||||
bits = 2;
|
||||
|
|
@ -359,7 +354,7 @@ struct Decoder : Common
|
|||
snr[j] = precision;
|
||||
precision = std::min(precision, value(1023));
|
||||
for (int i = 0; i < tone_count; ++i) {
|
||||
if (i % block_length != side_off) {
|
||||
if (i % block_length != seed_off) {
|
||||
int bits = mod_bits;
|
||||
if (mod_bits == 3 && k % 32 == 30)
|
||||
bits = 2;
|
||||
|
|
@ -396,7 +391,7 @@ struct Decoder : Common
|
|||
correlator(buf = next_sample());
|
||||
std::cerr << "oper mode: " << oper_mode << std::endl;
|
||||
}
|
||||
for (int i = side_off; i < tone_count; i += block_length)
|
||||
for (int i = seed_off; i < tone_count; i += block_length)
|
||||
chan[i] = DSP::lerp(chan[i], tone[i], value(0.5));
|
||||
}
|
||||
if (oper_mode < 0)
|
||||
|
|
|
|||
24
encode.cc
24
encode.cc
|
|
@ -80,22 +80,20 @@ struct Encoder : public Common
|
|||
{
|
||||
value scale = value(0.5) / std::sqrt(value(tone_count));
|
||||
value best_papr = 1000;
|
||||
CODE::XorShiftMask<int, 14, 1, 5, 10, 50> combination;
|
||||
for (int trial = 0; trial < 128; ++trial) {
|
||||
for (int seed_value = 0; seed_value < 128; ++seed_value) {
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
temp[i] = tone[i];
|
||||
if (symbol_number >= 0) {
|
||||
hadamard_encoder(side, trial);
|
||||
int comb = combination();
|
||||
int poly_index = comb & 15;
|
||||
int seed_value = comb >> 4;
|
||||
CODE::MLS seq(slm_poly[poly_index], seed_value);
|
||||
for (int i = 0, s = 0; i < tone_count; ++i)
|
||||
if (i % block_length == side_off)
|
||||
temp[i] *= side[s++];
|
||||
else
|
||||
hadamard_encoder(seed, seed_value);
|
||||
for (int i = 0; i < seed_tones; ++i)
|
||||
temp[i*block_length+seed_off] *= seed[i];
|
||||
if (seed_value) {
|
||||
CODE::MLS seq(mls2_poly, seed_value);
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
if (i % block_length != seed_off)
|
||||
temp[i] *= nrz(seq());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < symbol_len; ++i)
|
||||
fdom[i] = 0;
|
||||
for (int i = 0; i < tone_count; ++i)
|
||||
|
|
@ -301,9 +299,9 @@ struct Encoder : public Common
|
|||
shuffle(perm, code, code_order);
|
||||
CODE::MLS seq1(mls1_poly);
|
||||
for (int j = 0, k = 0, m = 0; j < symbol_count + 1; ++j) {
|
||||
side_off = (block_skew * j + first_side) % block_length;
|
||||
seed_off = (block_skew * j + first_seed) % block_length;
|
||||
for (int i = 0; i < tone_count; ++i) {
|
||||
if (i % block_length == side_off) {
|
||||
if (i % block_length == seed_off) {
|
||||
tone[i] = nrz(seq1());
|
||||
} else if (j) {
|
||||
int bits = mod_bits;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue