IT++ Logo
spread.cpp
Go to the documentation of this file.
1
29#include <itpp/comm/spread.h>
31#include <itpp/stat/misc_stat.h>
32
33
34namespace itpp
35{
36
37//------------- Spread1d -------------------
38
40{
42}
43
45{
46 N = incode.size();
47 code = incode;
48 code /= norm(code);
49}
50
52{
53 return code;
54}
55
56void Spread_1d::spread(const vec &symbols, vec &out)
57{
58 out.set_size(symbols.length()*N, false);
59
60 for (int i = 0;i < symbols.length();i++)
61 out.replace_mid(i*N, symbols(i)*code);
62}
63
64void Spread_1d::despread(const vec &rec_signal, vec &out, int timing)
65{
66 int nosymbols = (int)std::floor(double((rec_signal.length() - timing)) / N);
68
69 for (int i = 0;i < nosymbols;i++)
70 out(i) = rec_signal.mid(i * N + timing, N) * code;
71}
72
73
74//---------------- Spread2d ----------------------
75
77{
78 return spreadI.get_code();
79}
80
82{
83 return spreadQ.get_code();
84}
85
86Spread_2d::Spread_2d(const vec &incodeI, const vec &incodeQ)
87{
89}
90
91void Spread_2d::set_code(const vec &incodeI, const vec &incodeQ)
92{
93 it_assert(incodeI.length() == incodeQ.length(), "Size of I and Q codes doesn't match");
96}
97
98void Spread_2d::spread(const cvec &symbols, cvec &out)
99{
100 out = to_cvec(spreadI.spread(real(symbols)), spreadQ.spread(imag(symbols)));
101}
102
107
108
109
110//------------- Multicode_Spread_1d ----------------
111
112
117
119{
120 codes = incodes;
121 N = incodes.cols();
122 L = incodes.rows();
123 for (int i = 0; i < L; i++)
124 codes.set_row(i, codes.get_row(i) / norm(codes.get_row(i)));
125}
126
128{
129 return codes;
130}
131
132vec Multicode_Spread_1d::spread(const vec &symbols)
133{
134 int i;
135 int nomcsymbols = (int)std::floor(double(symbols.length() / L));
136 vec temp(nomcsymbols*N);
137
138 for (i = 0;i < nomcsymbols;i++) {
139 temp.replace_mid(i*N, codes.T() * symbols.mid(i*L, L)); // TODO: this is now very slow
140 }
141
142 return temp;
143}
144
146{
147 int i;
148 int nosymbols = (int)std::floor(double((receivedsignal.length() - timing)) / N);
149 vec temp(nosymbols*L);
150
151 for (i = 0;i < nosymbols;i++) {
152 temp.replace_mid(i*L, codes*receivedsignal.mid(i*N + timing, N));
153 }
154 return temp;
155}
156
157
158//----------------- Multicode_Spread_2d -------------------
159
160
165
170
175
177{
178 it_assert(incodesI.rows() == incodesQ.rows() && incodesI.cols() == incodesQ.cols(),
179 "Multicode_Spread_2d::set_codes(): dimension mismatch");
182}
183
184cvec Multicode_Spread_2d::spread(const cvec &symbols)
185{
186 return to_cvec(mcspreadI.spread(real(symbols)), mcspreadQ.spread(imag(symbols)));
187}
188
193
194} // namespace itpp
General array class.
Definition array.h:105
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
Definition array.h:377
int size() const
Returns the number of data elements in the array object.
Definition array.h:155
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Definition array.h:257
int length() const
Returns the number of data elements in the array object.
Definition array.h:157
int L
The number of multi-codes.
Definition spread.h:222
int N
The spreading factor.
Definition spread.h:224
vec spread(const vec &symbols)
Spreading function.
Definition spread.cpp:132
mat get_codes()
Returns the matrix containing the spreading codes used as rows in the matrix.
Definition spread.cpp:127
Multicode_Spread_1d()
Constructor.
Definition spread.h:203
vec despread(const vec &receivedsignal, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:145
void set_codes(const mat &incodes)
Set the spreading codes. Each row represent one spreading code. The spreading factor equals the numbe...
Definition spread.cpp:118
mat codes
The spreading codes used size ( )
Definition spread.h:220
cvec spread(const cvec &symbols)
Spreading of signal.
Definition spread.cpp:184
Multicode_Spread_1d mcspreadI
Definition spread.h:274
mat get_codesQ()
Return the matrix containing the quadrature-phase codes (as rows)
Definition spread.cpp:171
Multicode_Spread_2d()
Constructor.
Definition spread.h:251
mat get_codesI()
Return the matrix containing the in-phase codes (as rows)
Definition spread.cpp:166
Multicode_Spread_1d mcspreadQ
Definition spread.h:274
void set_codes(const mat &incodesI, const mat &incodesQ)
Set the spreading codes.
Definition spread.cpp:176
cvec despread(const cvec &receivedsignal, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:189
int N
The spreading factor.
Definition spread.h:129
void despread(const vec &rec_signal, vec &out, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:64
vec code
The spreading code.
Definition spread.h:127
void set_code(const vec &incode)
Set the spreading code used for spreading.
Definition spread.cpp:44
vec get_code()
Returns the spreading code used.
Definition spread.cpp:51
Spread_1d()
Constructor.
Definition spread.h:103
void spread(const vec &symbols, vec &out)
Spreading of signal return i out.
Definition spread.cpp:56
Spread_1d spreadI
Definition spread.h:183
void spread(const cvec &symbols, cvec &out)
Spreading of signal.
Definition spread.cpp:98
void despread(const cvec &rec_signal, cvec &out, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:103
vec get_codeI()
Returns the in-phase spreading code.
Definition spread.cpp:76
Spread_2d()
Constructor.
Definition spread.h:156
Spread_1d spreadQ
Definition spread.h:183
vec get_codeQ()
Returns the quadrature-phase spreading code.
Definition spread.cpp:81
void set_code(const vec &incodeI, const vec &incodeQ)
Set the in-phase and the quadrature-phase spreading codes.
Definition spread.cpp:91
Definitions of converters between different vector and matrix types.
#define it_assert(t, s)
Abort if t is not true.
Definition itassert.h:94
vec imag(const cvec &data)
Imaginary part of complex values.
vec real(const cvec &data)
Real part of complex values.
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
Definition misc_stat.cpp:77
Miscellaneous statistics functions and classes - header file.
itpp namespace
Definition itmex.h:37
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
Definition converters.h:107
Definition of spread spectrum classes and functions.
SourceForge Logo

Generated on Mon Jun 10 2024 11:49:22 for IT++ by Doxygen 1.9.8