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

Generated on Sat Jul 9 2011 15:21:31 for IT++ by Doxygen 1.7.4