IT++ Logo
egolay.cpp
Go to the documentation of this file.
00001 
00029 #include <itpp/comm/egolay.h>
00030 #include <itpp/comm/commfunc.h>
00031 #include <itpp/base/specmat.h>
00032 #include <itpp/base/converters.h>
00033 
00034 namespace itpp
00035 {
00036 
00037 Extended_Golay::Extended_Golay(void)
00038 {
00039   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";
00040 
00041   G = concat_horizontal(eye_b(12), B);
00042 }
00043 
00044 void Extended_Golay::encode(const bvec &uncoded_bits, bvec &coded_bits)
00045 {
00046   int no_bits = uncoded_bits.length();
00047   int no_blocks = floor_i(no_bits / 12.0);
00048 
00049   coded_bits.set_size(24*no_blocks, false);
00050   bmat Gt = G.T();
00051   int i;
00052 
00053   for (i = 0; i < no_blocks; i++)
00054     coded_bits.replace_mid(24*i, Gt * uncoded_bits.mid(i*12, 12));
00055 }
00056 
00057 bvec Extended_Golay::encode(const bvec &uncoded_bits)
00058 {
00059   bvec coded_bits;
00060   encode(uncoded_bits, coded_bits);
00061   return coded_bits;
00062 }
00063 
00064 void Extended_Golay::decode(const bvec &coded_bits, bvec &decoded_bits)
00065 {
00066   int no_bits = coded_bits.length();
00067   int no_blocks = floor_i(no_bits / 24.0);
00068 
00069   decoded_bits.set_size(12*no_blocks, false);
00070   int i, j;
00071   bvec S(12), BS(12), r(12), temp(12), e(24), c(24);
00072   bmat eyetemp = eye_b(12);
00073 
00074   for (i = 0; i < no_blocks; i++) {
00075     r = coded_bits.mid(i * 24, 24);
00076     // Step 1. Compute S=G*r.
00077     S = G * r;
00078     // Step 2. w(S)<=3. e=(S,0). Goto 8.
00079     if (weight(S) <= 3) {
00080       e = concat(S, zeros_b(12));
00081       goto Step8;
00082     }
00083 
00084     // Step 3. w(S+Ii)<=2. e=(S+Ii,yi). Goto 8.
00085     for (j = 0; j < 12; j++) {
00086 
00087       temp = S + B.get_col(j);
00088       if (weight(temp) <= 2) {
00089         e = concat(temp, eyetemp.get_row(j));
00090         goto Step8;
00091       }
00092     }
00093 
00094     // STEP 4. Compute B*S
00095     BS = B * S;
00096 
00097     // Step 5. w(B*S)<=3. e=(0,BS). Goto8.
00098     if (weight(BS) <= 3) {
00099       e = concat(zeros_b(12), BS);
00100       goto Step8;
00101     }
00102 
00103     // Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8.
00104     for (j = 0; j < 12; j++) {
00105       temp = BS + B.get_row(j);
00106       if (weight(temp) <= 2) {
00107         e = concat(eyetemp.get_row(j), temp);
00108         goto Step8;
00109       }
00110     }
00111 
00112     // Step 7. Uncorrectable erreor pattern. Choose the first 12 bits.
00113     e = zeros_b(24);
00114     goto Step8;
00115 
00116   Step8: // Step 8. c=r+e. STOP
00117     c = r + e;
00118     decoded_bits.replace_mid(i*12, c.left(12));
00119   }
00120 }
00121 
00122 bvec Extended_Golay::decode(const bvec &coded_bits)
00123 {
00124   bvec decoded_bits;
00125   decode(coded_bits, decoded_bits);
00126   return decoded_bits;
00127 }
00128 
00129 
00130 // -------------- Soft-decision decoding is not implemented ------------------
00131 void Extended_Golay::decode(const vec &, bvec &)
00132 {
00133   it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
00134 }
00135 
00136 bvec Extended_Golay::decode(const vec &)
00137 {
00138   it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
00139   return bvec();
00140 }
00141 
00142 
00143 } // namespace itpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Jul 27 2011 16:27:04 for IT++ by Doxygen 1.7.4