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 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)); goto Step8; 00081 } 00082 00083 // Step 3. w(S+Ii)<=2. e=(S+Ii,yi). Goto 8. 00084 for (j=0; j<12; j++) { 00085 00086 temp = S + B.get_col(j); 00087 if ( weight(temp) <=2 ) { 00088 e = concat(temp, eyetemp.get_row(j)); goto Step8; 00089 } 00090 } 00091 00092 // STEP 4. Compute B*S 00093 BS = B*S; 00094 00095 // Step 5. w(B*S)<=3. e=(0,BS). Goto8. 00096 if ( weight(BS) <=3 ) { 00097 e = concat(zeros_b(12), BS); goto Step8; 00098 } 00099 00100 // Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8. 00101 for (j=0; j<12; j++) { 00102 temp = BS + B.get_row(j); 00103 if ( weight(temp) <=2 ) { 00104 e = concat(eyetemp.get_row(j), temp); goto Step8; 00105 } 00106 } 00107 00108 // Step 7. Uncorrectable erreor pattern. Choose the first 12 bits. 00109 e = zeros_b(24); goto Step8; 00110 00111 Step8: // Step 8. c=r+e. STOP 00112 c = r + e; 00113 decoded_bits.replace_mid(i*12, c.left(12)); 00114 } 00115 } 00116 00117 bvec Extended_Golay::decode(const bvec &coded_bits) 00118 { 00119 bvec decoded_bits; 00120 decode(coded_bits, decoded_bits); 00121 return decoded_bits; 00122 } 00123 00124 00125 // -------------- Soft-decision decoding is not implemented ------------------ 00126 void Extended_Golay::decode(const vec &received_signal, bvec &output) 00127 { 00128 it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"); 00129 } 00130 00131 bvec Extended_Golay::decode(const vec &received_signal) 00132 { 00133 it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"); 00134 return bvec(); 00135 } 00136 00137 00138 } // namespace itpp
Generated on Sun Sep 14 18:54:53 2008 for IT++ by Doxygen 1.5.6