mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
handle data and parity seperate in both BCH and RS
This commit is contained in:
parent
6b3bc5e534
commit
f545b5d6ab
8 changed files with 145 additions and 105 deletions
|
|
@ -19,18 +19,25 @@ int main()
|
|||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::GaloisField<4, 0b10011, uint8_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemDecoder<6, 1, 5, GF> BCH;
|
||||
const int L = (BCH::N + 7) / 8;
|
||||
const int D = (BCH::K + 7) / 8;
|
||||
const int P = (BCH::NP + 7) / 8;
|
||||
const int L = D + P;
|
||||
GF instance;
|
||||
BCH decode;
|
||||
uint8_t target[L] = { 0b11001000, 0b11110100 };
|
||||
uint8_t target[L] = { 0b11001000, 0b00011110, 0b10000000 };
|
||||
uint8_t code[L];
|
||||
for (int i = 0; i < L; ++i)
|
||||
code[i] = target[i];
|
||||
std::uniform_int_distribution<int> distribution(0, BCH::N-1);
|
||||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
CODE::xor_be_bit(code, noise(), 1);
|
||||
decode(code);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int n = noise();
|
||||
if (n < BCH::K)
|
||||
CODE::xor_be_bit(code, n, 1);
|
||||
else
|
||||
CODE::xor_be_bit(code+D, n-BCH::K, 1);
|
||||
}
|
||||
decode(code, code + D);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
|
|
@ -38,7 +45,9 @@ int main()
|
|||
// DVB-S2 FULL BCH(65535, 65343) T=12
|
||||
typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 65343, GF> BCH;
|
||||
const int L = (BCH::N + 7) / 8;
|
||||
const int D = (BCH::K + 7) / 8;
|
||||
const int P = (BCH::NP + 7) / 8;
|
||||
const int L = D + P;
|
||||
GF *instance = new GF();
|
||||
BCH *decode = new BCH();
|
||||
uint8_t *target = new uint8_t[L];
|
||||
|
|
@ -48,15 +57,20 @@ int main()
|
|||
CODE::set_be_bit(target, i, (s^=s>>7)&1);
|
||||
bool parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 };
|
||||
for (int i = 0; i < BCH::NP; ++i)
|
||||
CODE::set_be_bit(target, BCH::K+i, parity[i]);
|
||||
CODE::set_be_bit(target + D, i, parity[i]);
|
||||
uint8_t *code = new uint8_t[L];
|
||||
for (int i = 0; i < L; ++i)
|
||||
code[i] = target[i];
|
||||
std::uniform_int_distribution<int> distribution(0, BCH::N-1);
|
||||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
CODE::xor_be_bit(code, noise(), 1);
|
||||
(*decode)(code);
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
int n = noise();
|
||||
if (n < BCH::K)
|
||||
CODE::xor_be_bit(code, n, 1);
|
||||
else
|
||||
CODE::xor_be_bit(code+D, n-BCH::K, 1);
|
||||
}
|
||||
(*decode)(code, code + D);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
|
|
@ -64,7 +78,7 @@ int main()
|
|||
delete decode;
|
||||
delete instance;
|
||||
}
|
||||
if (0) {
|
||||
if (1) {
|
||||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::GaloisField<4, 0b10011, uint8_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemDecoderReference<6, 1, 5, GF> BCH;
|
||||
|
|
@ -78,11 +92,11 @@ int main()
|
|||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
code[noise()] ^= 1;
|
||||
decode(reinterpret_cast<GF::ValueType *>(code));
|
||||
decode(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
if (0) {
|
||||
if (1) {
|
||||
// DVB-S2 FULL BCH(65535, 65343) T=12
|
||||
typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemDecoderReference<24, 1, 65343, GF> BCH;
|
||||
|
|
@ -101,7 +115,7 @@ int main()
|
|||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
code[noise()] ^= 1;
|
||||
(*decode)(reinterpret_cast<GF::ValueType *>(code));
|
||||
(*decode)(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
|
|
|
|||
|
|
@ -15,18 +15,22 @@ int main()
|
|||
if (1) {
|
||||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::BoseChaudhuriHocquenghemEncoder<15, 5> BCH;
|
||||
const int L = (BCH::N + 7) / 8;
|
||||
const int D = (BCH::K + 7) / 8;
|
||||
const int P = (BCH::NP + 7) / 8;
|
||||
const int L = D + P;
|
||||
BCH encode({0b10011, 0b11111, 0b00111});
|
||||
uint8_t code[L] = { 0b11001000 };
|
||||
uint8_t target[L] = { 0b11001000, 0b11110100 };
|
||||
encode(code);
|
||||
uint8_t target[L] = { 0b11001000, 0b00011110, 0b10000000 };
|
||||
encode(code, code + D);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
if (1) {
|
||||
// DVB-S2 FULL BCH(65535, 65343) T=12
|
||||
typedef CODE::BoseChaudhuriHocquenghemEncoder<65535, 65343> BCH;
|
||||
const int L = (BCH::N + 7) / 8;
|
||||
const int D = (BCH::K + 7) / 8;
|
||||
const int P = (BCH::NP + 7) / 8;
|
||||
const int L = D + P;
|
||||
BCH *encode = new BCH({0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, 0b10111010110100111, 0b10011101000101101, 0b10001101011100011});
|
||||
uint8_t *target = new uint8_t[L];
|
||||
for (int i = 0; i < L; ++i)
|
||||
|
|
@ -38,15 +42,15 @@ int main()
|
|||
code[i] = target[i];
|
||||
bool parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 };
|
||||
for (int i = 0; i < BCH::NP; ++i)
|
||||
CODE::set_be_bit(target, BCH::K+i, parity[i]);
|
||||
(*encode)(code);
|
||||
CODE::set_be_bit(target + D, i, parity[i]);
|
||||
(*encode)(code, code + D);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
delete[] code;
|
||||
delete encode;
|
||||
}
|
||||
if (0) {
|
||||
if (1) {
|
||||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::GaloisField<4, 0b10011, uint8_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemEncoderReference<6, 1, 5, GF> BCH;
|
||||
|
|
@ -54,11 +58,11 @@ int main()
|
|||
BCH encode({0b10011, 0b11111, 0b00111});
|
||||
BCH::value_type code[BCH::N] = { 1, 1, 0, 0, 1 };
|
||||
BCH::value_type target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 };
|
||||
encode(reinterpret_cast<GF::ValueType *>(code));
|
||||
encode(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
if (0) {
|
||||
if (1) {
|
||||
// DVB-S2 FULL BCH(65535, 65343) T=12
|
||||
typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF;
|
||||
typedef CODE::BoseChaudhuriHocquenghemEncoderReference<24, 1, 65343, GF> BCH;
|
||||
|
|
@ -71,7 +75,7 @@ int main()
|
|||
BCH::value_type parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 };
|
||||
for (int i = 0; i < BCH::NP; ++i)
|
||||
target[BCH::K+i] = parity[i];
|
||||
(*encode)(reinterpret_cast<GF::ValueType *>(code));
|
||||
(*encode)(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ int main()
|
|||
auto val = std::bind(std::uniform_int_distribution<RS::value_type>(0, RS::N), generator);
|
||||
for (int i = 0; i < 2; ++i)
|
||||
code[pos()] = val();
|
||||
decode(code);
|
||||
decode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ int main()
|
|||
auto val = std::bind(std::uniform_int_distribution<RS::value_type>(0, RS::N), generator);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
code[pos()] = val();
|
||||
decode(code);
|
||||
decode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ int main()
|
|||
auto val = std::bind(std::uniform_int_distribution<RS::value_type>(0, RS::N), generator);
|
||||
for (int i = 0; i < 32; ++i)
|
||||
code[pos()] = val();
|
||||
(*decode)(code);
|
||||
(*decode)(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ int main()
|
|||
RS encode;
|
||||
RS::value_type code[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
||||
RS::value_type target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 };
|
||||
encode(code);
|
||||
encode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ int main()
|
|||
RS::value_type parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 };
|
||||
for (int i = 0; i < RS::NP; ++i)
|
||||
target[RS::K+i] = parity[i];
|
||||
encode(code);
|
||||
encode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ int main()
|
|||
RS::value_type parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 };
|
||||
for (int i = 0; i < RS::NP; ++i)
|
||||
target[RS::K+i] = parity[i];
|
||||
(*encode)(code);
|
||||
(*encode)(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
delete[] target;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue