00001 00030 #include <itpp/comm/sequence.h> 00031 #include <itpp/base/converters.h> 00032 #include <itpp/base/math/log_exp.h> 00033 00034 00035 namespace itpp 00036 { 00037 00038 LFSR::LFSR(const bvec &connections) 00039 { 00040 set_connections(connections); 00041 } 00042 00043 LFSR::LFSR(const ivec &connections) 00044 { 00045 set_connections(connections); 00046 } 00047 00048 void LFSR::set_connections(const bvec &connections) 00049 { 00050 short N = connections.size() - 1; 00051 memory.set_size(N, true); // Should this be true??? 00052 Connections = connections.right(N); 00053 } 00054 00055 void LFSR::set_connections(const ivec &connections) 00056 { 00057 bvec temp = oct2bin(connections); 00058 short N = temp.size() - 1; 00059 memory.set_size(N, true); // Should this be true??? 00060 Connections = temp.right(N); 00061 } 00062 00063 void LFSR::set_state(const bvec &state) 00064 { 00065 it_assert(state.length() == memory.size(), "LFSR::set_state(): dimension mismatch"); 00066 memory = state; 00067 } 00068 00069 void LFSR::set_state(const ivec &state) 00070 { 00071 bvec temp = oct2bin(state, 1); 00072 it_assert(temp.length() >= memory.size(), "LFSR::set_state(): dimension mismatch"); 00073 memory = temp.right(memory.size()); 00074 } 00075 00076 bvec LFSR::shift(int no_shifts) 00077 { 00078 it_assert(no_shifts > 0, "LFSR::shift(): shift must be positive"); 00079 bvec temp(no_shifts); 00080 for (int i = 0;i < no_shifts;i++) { 00081 temp(i) = shift(); 00082 } 00083 return temp; 00084 } 00085 00086 //--------------------------- class Gold ------------------------- 00087 Gold::Gold(int degree) 00088 { 00089 bvec mseq1_connections, mseq2_connections; 00090 switch (degree) { 00091 case 5: 00092 mseq1_connections = bvec("1 0 1 0 0 1"); 00093 mseq2_connections = bvec("1 0 1 1 1 1"); 00094 break; 00095 case 7: 00096 mseq1_connections = bvec("1 0 0 1 0 0 0 1"); 00097 mseq2_connections = bvec("1 1 1 1 0 0 0 1"); 00098 break; 00099 case 8: 00100 mseq1_connections = bvec("1 1 1 0 0 1 1 1 1"); 00101 mseq2_connections = bvec("1 1 0 0 0 0 1 1 1"); 00102 break; 00103 case 9: 00104 mseq1_connections = bvec("1 0 0 0 1 0 0 0 0 1"); 00105 mseq2_connections = bvec("1 0 0 1 1 0 1 0 0 1"); 00106 break; 00107 default: 00108 it_error("This degree of Gold sequence is not available"); 00109 } 00110 mseq1.set_connections(mseq1_connections); 00111 mseq2.set_connections(mseq2_connections); 00112 N = pow2i(mseq1.get_length()) - 1; 00113 } 00114 00115 Gold::Gold(const bvec &mseq1_connections, const bvec &mseq2_connections) 00116 { 00117 it_assert(mseq1_connections.size() == mseq2_connections.size(), "Gold::Gold(): dimension mismatch"); 00118 mseq1.set_connections(mseq1_connections); 00119 mseq2.set_connections(mseq2_connections); 00120 N = pow2i(mseq1.get_length()) - 1; 00121 } 00122 00123 Gold::Gold(const ivec &mseq1_connections, const ivec &mseq2_connections) 00124 { 00125 mseq1.set_connections(mseq1_connections); 00126 mseq2.set_connections(mseq2_connections); 00127 it_assert(mseq1.get_length() == mseq1.get_length(), "Gold::Gold(): dimension mismatch"); 00128 N = pow2i(mseq1.get_length()) - 1; 00129 } 00130 00131 void Gold::set_state(const bvec &state1, const bvec &state2) 00132 { 00133 mseq1.set_state(state1); 00134 mseq2.set_state(state2); 00135 } 00136 00137 void Gold::set_state(const ivec &state1, const ivec &state2) 00138 { 00139 mseq1.set_state(state1); 00140 mseq2.set_state(state2); 00141 } 00142 00143 bvec Gold::shift(int no_shifts) 00144 { 00145 it_assert(no_shifts > 0, "Gold::shift(): shift must be positive"); 00146 bvec temp(no_shifts); 00147 for (int i = 0;i < no_shifts;i++) { 00148 temp(i) = shift(); 00149 } 00150 return temp; 00151 } 00152 00153 bmat Gold::get_family(void) 00154 { 00155 bmat codes(N + 2, N); 00156 bvec temp = dec2bin(mseq1.get_length(), 1); 00157 set_state(temp, temp); 00158 00159 // The two m-seq. 00160 codes.set_row(0, mseq1.shift(N)); 00161 codes.set_row(1, mseq2.shift(N)); 00162 // The sum of mseq1 and all time shifts of mseq2 00163 for (int i = 0;i < N;i++) { 00164 codes.set_row(i + 2, codes.get_row(0) + concat((codes.get_row(1)).right(i), (codes.get_row(1)).left(N - i))); 00165 } 00166 return codes; 00167 } 00168 00169 smat wcdma_spreading_codes(int SF) 00170 { 00171 it_assert((SF == 1) || (SF == 2) || (SF == 4) || (SF == 8) || (SF == 16) || (SF == 32) || (SF == 64) || (SF == 128) || (SF == 256) || (SF == 512), 00172 "wcdma_spreading_codes: SF must equal 1, 2, 4, 8, 16, 32, 64, 128, 256, or 512"); 00173 smat codes(SF, SF); 00174 if (SF == 1) { 00175 codes(0, 0) = short(1); 00176 } 00177 else { 00178 int i; 00179 smat prev_codes(SF / 2, SF / 2); 00180 prev_codes = wcdma_spreading_codes(SF / 2); 00181 for (i = 0; i < SF / 2; i++) { 00182 codes.set_row(2*i, concat(prev_codes.get_row(i), prev_codes.get_row(i))); 00183 codes.set_row(2*i + 1, concat(prev_codes.get_row(i), (-prev_codes.get_row(i)))); 00184 } 00185 } 00186 return codes; 00187 } 00188 00189 } // namespace itpp
Generated on Thu Apr 23 20:07:46 2009 for IT++ by Doxygen 1.5.8