IT++ Logo
sequence.cpp
Go to the documentation of this file.
1 
29 #include <itpp/comm/sequence.h>
30 #include <itpp/base/converters.h>
31 #include <itpp/base/math/log_exp.h>
32 
33 
34 namespace itpp
35 {
36 
37 LFSR::LFSR(const bvec &connections)
38 {
39  set_connections(connections);
40 }
41 
42 LFSR::LFSR(const ivec &connections)
43 {
44  set_connections(connections);
45 }
46 
47 void LFSR::set_connections(const bvec &connections)
48 {
49  int N = connections.size() - 1;
50  memory.set_size(N, true); // Should this be true???
51  Connections = connections.right(N);
52 }
53 
54 void LFSR::set_connections(const ivec &connections)
55 {
56  bvec temp = oct2bin(connections);
57  int N = temp.size() - 1;
58  memory.set_size(N, true); // Should this be true???
59  Connections = temp.right(N);
60 }
61 
62 void LFSR::set_state(const bvec &state)
63 {
64  it_assert(state.length() == memory.size(), "LFSR::set_state(): dimension mismatch");
65  memory = state;
66 }
67 
68 void LFSR::set_state(const ivec &state)
69 {
70  bvec temp = oct2bin(state, 1);
71  it_assert(temp.length() >= memory.size(), "LFSR::set_state(): dimension mismatch");
72  memory = temp.right(memory.size());
73 }
74 
75 bvec LFSR::shift(int no_shifts)
76 {
77  it_assert(no_shifts > 0, "LFSR::shift(): shift must be positive");
78  bvec temp(no_shifts);
79  for (int i = 0;i < no_shifts;i++) {
80  temp(i) = shift();
81  }
82  return temp;
83 }
84 
85 //--------------------------- class Gold -------------------------
86 Gold::Gold(int degree)
87 {
88  bvec mseq1_connections, mseq2_connections;
89  switch (degree) {
90  case 5:
91  mseq1_connections = bvec("1 0 1 0 0 1");
92  mseq2_connections = bvec("1 0 1 1 1 1");
93  break;
94  case 7:
95  mseq1_connections = bvec("1 0 0 1 0 0 0 1");
96  mseq2_connections = bvec("1 1 1 1 0 0 0 1");
97  break;
98  case 8:
99  mseq1_connections = bvec("1 1 1 0 0 1 1 1 1");
100  mseq2_connections = bvec("1 1 0 0 0 0 1 1 1");
101  break;
102  case 9:
103  mseq1_connections = bvec("1 0 0 0 1 0 0 0 0 1");
104  mseq2_connections = bvec("1 0 0 1 1 0 1 0 0 1");
105  break;
106  default:
107  it_error("This degree of Gold sequence is not available");
108  }
109  mseq1.set_connections(mseq1_connections);
110  mseq2.set_connections(mseq2_connections);
111  N = pow2i(mseq1.get_length()) - 1;
112 }
113 
114 Gold::Gold(const bvec &mseq1_connections, const bvec &mseq2_connections)
115 {
116  it_assert(mseq1_connections.size() == mseq2_connections.size(), "Gold::Gold(): dimension mismatch");
117  mseq1.set_connections(mseq1_connections);
118  mseq2.set_connections(mseq2_connections);
119  N = pow2i(mseq1.get_length()) - 1;
120 }
121 
122 Gold::Gold(const ivec &mseq1_connections, const ivec &mseq2_connections)
123 {
124  mseq1.set_connections(mseq1_connections);
125  mseq2.set_connections(mseq2_connections);
126  it_assert(mseq1.get_length() == mseq1.get_length(), "Gold::Gold(): dimension mismatch");
127  N = pow2i(mseq1.get_length()) - 1;
128 }
129 
130 void Gold::set_state(const bvec &state1, const bvec &state2)
131 {
132  mseq1.set_state(state1);
133  mseq2.set_state(state2);
134 }
135 
136 void Gold::set_state(const ivec &state1, const ivec &state2)
137 {
138  mseq1.set_state(state1);
139  mseq2.set_state(state2);
140 }
141 
142 bvec Gold::shift(int no_shifts)
143 {
144  it_assert(no_shifts > 0, "Gold::shift(): shift must be positive");
145  bvec temp(no_shifts);
146  for (int i = 0;i < no_shifts;i++) {
147  temp(i) = shift();
148  }
149  return temp;
150 }
151 
153 {
154  bmat codes(N + 2, N);
155  bvec temp = dec2bin(mseq1.get_length(), 1);
156  set_state(temp, temp);
157 
158  // The two m-seq.
159  codes.set_row(0, mseq1.shift(N));
160  codes.set_row(1, mseq2.shift(N));
161  // The sum of mseq1 and all time shifts of mseq2
162  for (int i = 0;i < N;i++) {
163  codes.set_row(i + 2, codes.get_row(0) + concat((codes.get_row(1)).right(i), (codes.get_row(1)).left(N - i)));
164  }
165  return codes;
166 }
167 
169 {
170  it_assert((SF == 1) || (SF == 2) || (SF == 4) || (SF == 8) || (SF == 16) || (SF == 32) || (SF == 64) || (SF == 128) || (SF == 256) || (SF == 512),
171  "wcdma_spreading_codes: SF must equal 1, 2, 4, 8, 16, 32, 64, 128, 256, or 512");
172  smat codes(SF, SF);
173  if (SF == 1) {
174  codes(0, 0) = short(1);
175  }
176  else {
177  int i;
178  smat prev_codes(SF / 2, SF / 2);
179  prev_codes = wcdma_spreading_codes(SF / 2);
180  for (i = 0; i < SF / 2; i++) {
181  codes.set_row(2*i, concat(prev_codes.get_row(i), prev_codes.get_row(i)));
182  codes.set_row(2*i + 1, concat(prev_codes.get_row(i), (-prev_codes.get_row(i))));
183  }
184  }
185  return codes;
186 }
187 
188 } // namespace itpp
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:23 for IT++ by Doxygen 1.8.2