IT++ Logo
egolay.cpp
Go to the documentation of this file.
1 
29 #include <itpp/comm/egolay.h>
30 #include <itpp/comm/commfunc.h>
31 #include <itpp/base/specmat.h>
32 #include <itpp/base/converters.h>
33 
34 namespace itpp
35 {
36 
38 {
39  B = "0 1 1 1 1 1 1 1 1 1 1 1;1 1 1 0 1 1 1 0 0 0 1 0;1 1 0 1 1 1 0 0 0 1 0 1;1 0 1 1 1 0 0 0 1 0 1 1;1 1 1 1 0 0 0 1 0 1 1 0;1 1 1 0 0 0 1 0 1 1 0 1;1 1 0 0 0 1 0 1 1 0 1 1;1 0 0 0 1 0 1 1 0 1 1 1;1 0 0 1 0 1 1 0 1 1 1 0;1 0 1 0 1 1 0 1 1 1 0 0;1 1 0 1 1 0 1 1 1 0 0 0;1 0 1 1 0 1 1 1 0 0 0 1";
40 
41  G = concat_horizontal(eye_b(12), B);
42 }
43 
44 void Extended_Golay::encode(const bvec &uncoded_bits, bvec &coded_bits)
45 {
46  int no_bits = uncoded_bits.length();
47  int no_blocks = floor_i(no_bits / 12.0);
48 
49  coded_bits.set_size(24*no_blocks, false);
50  bmat Gt = G.T();
51  int i;
52 
53  for (i = 0; i < no_blocks; i++)
54  coded_bits.replace_mid(24*i, Gt * uncoded_bits.mid(i*12, 12));
55 }
56 
57 bvec Extended_Golay::encode(const bvec &uncoded_bits)
58 {
59  bvec coded_bits;
60  encode(uncoded_bits, coded_bits);
61  return coded_bits;
62 }
63 
64 void Extended_Golay::decode(const bvec &coded_bits, bvec &decoded_bits)
65 {
66  int no_bits = coded_bits.length();
67  int no_blocks = floor_i(no_bits / 24.0);
68 
69  decoded_bits.set_size(12*no_blocks, false);
70  int i, j;
71  bvec S(12), BS(12), r(12), temp(12), e(24), c(24);
72  bmat eyetemp = eye_b(12);
73 
74  for (i = 0; i < no_blocks; i++) {
75  r = coded_bits.mid(i * 24, 24);
76  // Step 1. Compute S=G*r.
77  S = G * r;
78  // Step 2. w(S)<=3. e=(S,0). Goto 8.
79  if (weight(S) <= 3) {
80  e = concat(S, zeros_b(12));
81  goto Step8;
82  }
83 
84  // Step 3. w(S+Ii)<=2. e=(S+Ii,yi). Goto 8.
85  for (j = 0; j < 12; j++) {
86 
87  temp = S + B.get_col(j);
88  if (weight(temp) <= 2) {
89  e = concat(temp, eyetemp.get_row(j));
90  goto Step8;
91  }
92  }
93 
94  // STEP 4. Compute B*S
95  BS = B * S;
96 
97  // Step 5. w(B*S)<=3. e=(0,BS). Goto8.
98  if (weight(BS) <= 3) {
99  e = concat(zeros_b(12), BS);
100  goto Step8;
101  }
102 
103  // Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8.
104  for (j = 0; j < 12; j++) {
105  temp = BS + B.get_row(j);
106  if (weight(temp) <= 2) {
107  e = concat(eyetemp.get_row(j), temp);
108  goto Step8;
109  }
110  }
111 
112  // Step 7. Uncorrectable erreor pattern. Choose the first 12 bits.
113  e = zeros_b(24);
114  goto Step8;
115 
116  Step8: // Step 8. c=r+e. STOP
117  c = r + e;
118  decoded_bits.replace_mid(i*12, c.left(12));
119  }
120 }
121 
122 bvec Extended_Golay::decode(const bvec &coded_bits)
123 {
124  bvec decoded_bits;
125  decode(coded_bits, decoded_bits);
126  return decoded_bits;
127 }
128 
129 
130 // -------------- Soft-decision decoding is not implemented ------------------
131 void Extended_Golay::decode(const vec &, bvec &)
132 {
133  it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
134 }
135 
136 bvec Extended_Golay::decode(const vec &)
137 {
138  it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
139  return bvec();
140 }
141 
142 
143 } // namespace itpp
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:22 for IT++ by Doxygen 1.8.2