47 void Hamming_Code::generate_H(
void)
55 for (i = 1; i <= n - k; i++) { indexes(i - 1) =
pow2i(n - k - i); }
57 for (i = 1; i <= n; i++) {
59 for (j = 0; j < n; j++)
60 if (i == indexes(j)) { NotUsed = 0; }
61 if (NotUsed) { indexes(NextPos) = i; NextPos = NextPos + 1; }
64 for (i = 0; i < n; i++) {
65 temp =
dec2bin(n - k, indexes(i));
66 for (j = 0; j < (n - k); j++) {
72 void Hamming_Code::generate_G(
void)
75 for (i = 0; i < k; i++) {
76 for (j = 0; j < n - k; j++)
77 G(i, j) = H(j, i + n - k);
80 for (i = 0; i < k; i++) {
81 for (j = n - k; j < n; j++)
85 for (i = 0; i < k; i++)
91 int length = uncoded_bits.length();
92 int Itterations =
floor_i(static_cast<double>(length) / k);
96 coded_bits.set_size(Itterations * n,
false);
98 for (i = 0; i < Itterations; i++)
99 coded_bits.replace_mid(n*i, Gt * uncoded_bits.mid(i*k, k));
105 encode(uncoded_bits, coded_bits);
111 int length = coded_bits.length();
112 int Itterations =
floor_i(static_cast<double>(length) / n);
115 bvec coded(n), syndrome(n - k);
116 int isynd, errorpos = 0;
119 decoded_bits.set_size(Itterations*k,
false);
121 for (i = 0; i < n; i++) {
122 for (j = 0; j < n - k; j++)
128 for (i = 0; i < Itterations; i++) {
129 coded = coded_bits.mid(i * n, n);
130 syndrome = H * coded;
133 for (j = 0; j < n; j++)
134 if (Hindexes(j) == isynd) { errorpos = j; };
135 coded(errorpos) += 1;
137 decoded_bits.replace_mid(k*i, coded.right(k));
144 decode(coded_bits, decoded_bits);
152 it_error(
"Hamming_Code::decode(vec, bvec); soft-decision decoding is not implemented");
157 it_error(
"Hamming_Code::decode(vec, bvec); soft-decision decoding is not implemented");