IT++ Logo

egolay.cpp

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

Generated on Sun Jul 26 08:54:28 2009 for IT++ by Doxygen 1.5.9