00001 00033 #include <itpp/comm/egolay.h> 00034 #include <itpp/comm/commfunc.h> 00035 00036 00037 namespace itpp { 00038 00039 Extended_Golay::Extended_Golay(void) 00040 { 00041 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"; 00042 00043 G = concat_horizontal(eye_b(12), B); 00044 } 00045 00046 void Extended_Golay::encode(const bvec &uncoded_bits, bvec &coded_bits) 00047 { 00048 int no_bits = uncoded_bits.length(); 00049 int no_blocks = (int)floor((double)no_bits/12); 00050 00051 coded_bits.set_size(24*no_blocks, false); 00052 bmat Gt = G.T(); 00053 int i; 00054 00055 for (i=0; i<no_blocks; i++) 00056 coded_bits.replace_mid(24*i, Gt * uncoded_bits.mid(i*12,12)); 00057 } 00058 00059 bvec Extended_Golay::encode(const bvec &uncoded_bits) 00060 { 00061 bvec coded_bits; 00062 encode(uncoded_bits, coded_bits); 00063 return coded_bits; 00064 } 00065 00066 void Extended_Golay::decode(const bvec &coded_bits, bvec &decoded_bits) 00067 { 00068 int no_bits = coded_bits.length(); 00069 int no_blocks = (int)floor((double)no_bits/24); 00070 00071 decoded_bits.set_size(12*no_blocks, false); 00072 int i, j; 00073 bvec S(12),BS(12),r(12),temp(12),e(24),c(24); 00074 bmat eyetemp = eye_b(12); 00075 00076 for (i=0; i<no_blocks; i++) { 00077 r = coded_bits.mid(i*24,24); 00078 // Step 1. Compute S=G*r. 00079 S = G*r; 00080 // Step 2. w(S)<=3. e=(S,0). Goto 8. 00081 if( weight(S) <= 3 ) { 00082 e = concat(S, zeros_b(12)); 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)); 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); goto Step8; 00100 } 00101 00102 // Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8. 00103 for (j=0; j<12; j++) { 00104 temp = BS + B.get_row(j); 00105 if ( weight(temp) <=2 ) { 00106 e = concat(eyetemp.get_row(j), temp); goto Step8; 00107 } 00108 } 00109 00110 // Step 7. Uncorrectable erreor pattern. Choose the first 12 bits. 00111 e = zeros_b(24); goto Step8; 00112 00113 Step8: // Step 8. c=r+e. STOP 00114 c = r + e; 00115 decoded_bits.replace_mid(i*12, c.left(12)); 00116 } 00117 } 00118 00119 bvec Extended_Golay::decode(const bvec &coded_bits) 00120 { 00121 bvec decoded_bits; 00122 decode(coded_bits, decoded_bits); 00123 return decoded_bits; 00124 } 00125 00126 00127 // -------------- Soft-decision decoding is not implemented ------------------ 00128 void Extended_Golay::decode(const vec &received_signal, bvec &output) 00129 { 00130 it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"); 00131 } 00132 00133 bvec Extended_Golay::decode(const vec &received_signal) 00134 { 00135 it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"); 00136 return bvec(); 00137 } 00138 00139 00140 } // namespace itpp
Generated on Thu Apr 19 14:19:54 2007 for IT++ by Doxygen 1.4.6