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